From 0a17d86043c539a2db28d8a48911f967b43d8853 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 26 May 2026 14:44:19 -0700 Subject: [PATCH 1/4] go --- src/tools/wasm-ctor-eval.cpp | 7 +++++- test/lit/ctor-eval/start-nonconstant.wast | 27 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/lit/ctor-eval/start-nonconstant.wast diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index c8fe1d5e385..27d4ca78b6f 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -1482,11 +1482,16 @@ void evalCtors(Module& wasm, } } } catch (FailToEvalException& fail) { - // that's it, we failed to even create the instance + // That's it, we failed to even create the instance. if (!quiet) { std::cout << " ...stopping since could not create module instance: " << fail.why << "\n"; } + } catch (NonconstantException& fail) { + // We can also fail during start due to a non-constant operation. + if (!quiet) { + std::cout << " ...stopping since could non-constant in start\n"; + } } catch (TopologicalSort::CycleException e) { // We use a topological sort for GC globals. If there is a non-breakable // cycle there, we will hit an error (we can break cycles in nullable and diff --git a/test/lit/ctor-eval/start-nonconstant.wast b/test/lit/ctor-eval/start-nonconstant.wast new file mode 100644 index 00000000000..45d5e55ff01 --- /dev/null +++ b/test/lit/ctor-eval/start-nonconstant.wast @@ -0,0 +1,27 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: foreach %s %t wasm-ctor-eval --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s + +;; A non-constant (relaxed SIMD) operation in the start function. We should not +;; error and just not eval anything. +(module + ;; CHECK: (type $0 (func)) + (type $0 (func)) + + ;; CHECK: (export "test" (func $0)) + (export "test" (func $0)) + + (start $0) + + ;; CHECK: (func $0 (type $0) + ;; CHECK-NEXT: (nop) + ;; CHECK-NEXT: ) + (func $0 + (drop + (f32x4.relaxed_min + (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) + (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) + ) + ) + ) +) + From 2337815c75a9ec76ad568f6bd4629bb0a762c4fb Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 26 May 2026 14:45:01 -0700 Subject: [PATCH 2/4] go --- src/tools/wasm-ctor-eval.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 27d4ca78b6f..0a37e219ffc 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -1490,7 +1490,7 @@ void evalCtors(Module& wasm, } catch (NonconstantException& fail) { // We can also fail during start due to a non-constant operation. if (!quiet) { - std::cout << " ...stopping since could non-constant in start\n"; + std::cout << " ...stopping since non-constant in start\n"; } } catch (TopologicalSort::CycleException e) { // We use a topological sort for GC globals. If there is a non-breakable From bf3b22181b0f25500e8081e784e019fc39add54d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 26 May 2026 14:49:02 -0700 Subject: [PATCH 3/4] fix --- test/lit/ctor-eval/start-nonconstant.wast | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/lit/ctor-eval/start-nonconstant.wast b/test/lit/ctor-eval/start-nonconstant.wast index 45d5e55ff01..29ef4805145 100644 --- a/test/lit/ctor-eval/start-nonconstant.wast +++ b/test/lit/ctor-eval/start-nonconstant.wast @@ -2,7 +2,7 @@ ;; RUN: foreach %s %t wasm-ctor-eval --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s ;; A non-constant (relaxed SIMD) operation in the start function. We should not -;; error and just not eval anything. +;; error. (module ;; CHECK: (type $0 (func)) (type $0 (func)) @@ -16,6 +16,8 @@ ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) (func $0 + ;; While this is non-constant and evalling it fails, vacuum does remove it, + ;; so it vanishes. (drop (f32x4.relaxed_min (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) From cdef694dd441e837d8bfd2f902f6a3d678b3140f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 26 May 2026 16:08:40 -0700 Subject: [PATCH 4/4] add import to avoid vacuum --- test/lit/ctor-eval/start-nonconstant.wast | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/test/lit/ctor-eval/start-nonconstant.wast b/test/lit/ctor-eval/start-nonconstant.wast index 29ef4805145..4d6baa668ab 100644 --- a/test/lit/ctor-eval/start-nonconstant.wast +++ b/test/lit/ctor-eval/start-nonconstant.wast @@ -4,21 +4,30 @@ ;; A non-constant (relaxed SIMD) operation in the start function. We should not ;; error. (module - ;; CHECK: (type $0 (func)) - (type $0 (func)) + ;; CHECK: (type $0 (func (param v128))) + + ;; CHECK: (type $1 (func)) + + ;; CHECK: (import "a" "b" (func $import (type $0) (param v128))) + (import "a" "b" (func $import (param v128))) ;; CHECK: (export "test" (func $0)) (export "test" (func $0)) + ;; CHECK: (start $0) (start $0) - ;; CHECK: (func $0 (type $0) - ;; CHECK-NEXT: (nop) + ;; CHECK: (func $0 (type $1) + ;; CHECK-NEXT: (call $import + ;; CHECK-NEXT: (f32x4.relaxed_min + ;; CHECK-NEXT: (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) + ;; CHECK-NEXT: (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $0 - ;; While this is non-constant and evalling it fails, vacuum does remove it, - ;; so it vanishes. - (drop + ;; The import avoids vacuum from removing the entire body. + (call $import (f32x4.relaxed_min (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000)