diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index cc63e1c779a..2ac4ceeddde 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 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: )