Skip to content

Commit de5ff1a

Browse files
authored
[Stack Switching] wasm-ctor-eval: Properly ignore unhandled suspends (#7855)
We treated them as breaks, which meant we thought they could be precomputed into nops in some cases.
1 parent 2339a96 commit de5ff1a

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/tools/wasm-ctor-eval.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,16 @@ EvalCtorOutcome evalCtor(EvallingModuleRunner& instance,
11621162
results = flow.values;
11631163

11641164
if (flow.breaking()) {
1165+
if (flow.suspendTag) {
1166+
// A suspend reached the exit of the function, so it is unhandled in
1167+
// it. TODO: We could support the case of the calling function
1168+
// handling it.
1169+
if (!quiet) {
1170+
std::cout << " ...stopping due to unhandled suspend\n";
1171+
}
1172+
return EvalCtorOutcome();
1173+
}
1174+
11651175
// We are returning out of the function (either via a return, or via a
11661176
// break to |block|, which has the same outcome. That means we don't
11671177
// need to execute any more lines, and can consider them to be

test/lit/ctor-eval/cont.wast

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2-
;; RUN: foreach %s %t wasm-ctor-eval --ctors=test --kept-exports=test --quiet -all -S -o - | filecheck %s
2+
;; RUN: foreach %s %t wasm-ctor-eval --ctors=test,test2 --kept-exports=test,test2 --quiet -all -S -o - | filecheck %s
33

44
;; Test that we can precompute continuations.
55

66
(module
7+
;; CHECK: (type $f (func))
78
(type $f (func))
89
(type $k (cont $f))
910

11+
;; CHECK: (type $1 (func (result i32)))
12+
13+
;; CHECK: (tag $more (type $f))
1014
(tag $more)
1115

1216
(global $g (mut i32) (i32.const 0))
@@ -45,11 +49,19 @@
4549
)
4650
(global.get $g)
4751
)
48-
)
49-
;; CHECK: (type $0 (func (result i32)))
5052

51-
;; CHECK: (export "test" (func $test_3))
53+
;; CHECK: (export "test" (func $test_4))
54+
55+
;; CHECK: (export "test2" (func $test2))
5256

53-
;; CHECK: (func $test_3 (type $0) (result i32)
57+
;; CHECK: (func $test2 (type $f)
58+
;; CHECK-NEXT: (suspend $more)
59+
;; CHECK-NEXT: )
60+
(func $test2 (export "test2")
61+
;; This unhandled suspend will trap, and should not be precomputed.
62+
(suspend $more)
63+
)
64+
)
65+
;; CHECK: (func $test_4 (type $1) (result i32)
5466
;; CHECK-NEXT: (i32.const 3)
5567
;; CHECK-NEXT: )

0 commit comments

Comments
 (0)