From 8cc9855cfe18acdd24319ccf0fcbc3df8fa8c29b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 21 Aug 2025 17:17:35 -0700 Subject: [PATCH 1/2] fix --- src/tools/wasm-ctor-eval.cpp | 10 ++++++++++ test/lit/ctor-eval/cont.wast | 22 +++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index cc63e1c779a..8efae47670c 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -1162,6 +1162,16 @@ EvalCtorOutcome evalCtor(EvallingModuleRunner& instance, results = flow.values; if (flow.breaking()) { + if (flow.suspendTag) { + // A suspend reached the exit of the function, so it is unhandled in + // it. TODO: We could support the case of the calling function + // handling it. + if (!quiet) { + std::cout << " ...stopping in block due to unhandled suspend\n"; + } + return EvalCtorOutcome(); + } + // We are returning out of the function (either via a return, or via a // break to |block|, which has the same outcome. That means we don't // need to execute any more lines, and can consider them to be diff --git a/test/lit/ctor-eval/cont.wast b/test/lit/ctor-eval/cont.wast index c8bb0dccc84..e7e199d1c26 100644 --- a/test/lit/ctor-eval/cont.wast +++ b/test/lit/ctor-eval/cont.wast @@ -1,12 +1,16 @@ ;; 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 +;; RUN: foreach %s %t wasm-ctor-eval --ctors=test,test2 --kept-exports=test,test2 --quiet -all -S -o - | filecheck %s ;; Test that we can precompute continuations. (module + ;; CHECK: (type $f (func)) (type $f (func)) (type $k (cont $f)) + ;; CHECK: (type $1 (func (result i32))) + + ;; CHECK: (tag $more (type $f)) (tag $more) (global $g (mut i32) (i32.const 0)) @@ -45,11 +49,19 @@ ) (global.get $g) ) -) -;; CHECK: (type $0 (func (result i32))) -;; CHECK: (export "test" (func $test_3)) + ;; CHECK: (export "test" (func $test_4)) + + ;; CHECK: (export "test2" (func $test2)) -;; CHECK: (func $test_3 (type $0) (result i32) + ;; CHECK: (func $test2 (type $f) + ;; CHECK-NEXT: (suspend $more) + ;; CHECK-NEXT: ) + (func $test2 (export "test2") + ;; This unhandled suspend will trap, and should not be precomputed. + (suspend $more) + ) +) +;; CHECK: (func $test_4 (type $1) (result i32) ;; CHECK-NEXT: (i32.const 3) ;; CHECK-NEXT: ) From f404726f8b2e3d9f2dcdf2018b37b2f8580817a5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 21 Aug 2025 17:18:06 -0700 Subject: [PATCH 2/2] fix --- 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 8efae47670c..2ac4ceeddde 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -1167,7 +1167,7 @@ EvalCtorOutcome evalCtor(EvallingModuleRunner& instance, // it. TODO: We could support the case of the calling function // handling it. if (!quiet) { - std::cout << " ...stopping in block due to unhandled suspend\n"; + std::cout << " ...stopping due to unhandled suspend\n"; } return EvalCtorOutcome(); }