Skip to content

Commit 8242d19

Browse files
authored
[Stack Switching] Fix ctor-eval handling of unhandled resumes (#8556)
The logic for this was in the wrong place. It should be where we handle a non-constant operation, as it is something that stops us and prevents precomputing. (Before, it was down by a branch, but a branch is a very special case in which we can ignore the branch, because we know it goes to the toplevel block, skipping what is after it.) Fixes #8553
1 parent a070616 commit 8242d19

File tree

2 files changed

+63
-11
lines changed

2 files changed

+63
-11
lines changed

src/tools/wasm-ctor-eval.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,14 @@ EvalCtorOutcome evalCtor(EvallingModuleRunner& instance,
11731173
std::cout << " ...stopping due to non-constant flow\n";
11741174
}
11751175
break;
1176+
} else if (flow.suspendTag) {
1177+
// A suspend reached the exit of the function, so it is unhandled in
1178+
// it. TODO: We could support the case of the calling function
1179+
// handling it.
1180+
if (!quiet) {
1181+
std::cout << " ...stopping due to unhandled suspend\n";
1182+
}
1183+
break;
11761184
}
11771185

11781186
if (flow.breakTo == RETURN_CALL_FLOW) {
@@ -1235,18 +1243,8 @@ EvalCtorOutcome evalCtor(EvallingModuleRunner& instance,
12351243
results = flow.values;
12361244

12371245
if (flow.breaking()) {
1238-
if (flow.suspendTag) {
1239-
// A suspend reached the exit of the function, so it is unhandled in
1240-
// it. TODO: We could support the case of the calling function
1241-
// handling it.
1242-
if (!quiet) {
1243-
std::cout << " ...stopping due to unhandled suspend\n";
1244-
}
1245-
return EvalCtorOutcome();
1246-
}
1247-
12481246
// We are returning out of the function (either via a return, or via a
1249-
// break to |block|, which has the same outcome. That means we don't
1247+
// break to |block|, which has the same outcome). That means we don't
12501248
// need to execute any more lines, and can consider them to be
12511249
// executed.
12521250
if (!quiet) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
;; 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=ctor --kept-exports=ctor,main --quiet -all -S -o - | filecheck %s
3+
4+
;; Test that we properly stop precomputing at an unhandled suspend. $ctor will
5+
;; decrement $global, and we apply that to the global. We should remove that
6+
;; decrement from the export, which will only contain the suspend that we
7+
;; stopped at. (After that, $main will print the same value, 99, as if we didn't
8+
;; precompute.)
9+
10+
(module
11+
;; CHECK: (type $none-none (func))
12+
13+
;; CHECK: (type $i32-none (func (param i32)))
14+
(type $i32-none (func (param i32)))
15+
(type $none-none (func))
16+
17+
;; CHECK: (import "fuzzing-support" "log-i32" (func $log (type $i32-none) (param i32)))
18+
(import "fuzzing-support" "log-i32" (func $log (type $i32-none)))
19+
20+
;; CHECK: (global $global (mut i32) (i32.const 99))
21+
(global $global (mut i32) (i32.const 100))
22+
23+
;; CHECK: (tag $tag (type $none-none))
24+
(tag $tag (type $none-none))
25+
26+
(export "ctor" (func $ctor))
27+
;; CHECK: (export "ctor" (func $ctor_3))
28+
29+
;; CHECK: (export "main" (func $main))
30+
(export "main" (func $main))
31+
32+
(func $ctor (type $none-none)
33+
(global.set $global
34+
(i32.sub
35+
(global.get $global)
36+
(i32.const 1)
37+
)
38+
)
39+
(suspend $tag)
40+
)
41+
42+
;; CHECK: (func $main (type $none-none)
43+
;; CHECK-NEXT: (call $log
44+
;; CHECK-NEXT: (global.get $global)
45+
;; CHECK-NEXT: )
46+
;; CHECK-NEXT: )
47+
(func $main (type $none-none)
48+
(global.get $global)
49+
(call $log)
50+
)
51+
)
52+
;; CHECK: (func $ctor_3 (type $none-none)
53+
;; CHECK-NEXT: (suspend $tag)
54+
;; CHECK-NEXT: )

0 commit comments

Comments
 (0)