Skip to content

Commit b3b6a81

Browse files
authored
[Wasm Exceptions] Fix cfg-traversal on linking the basic block after a call (#3594)
This was an unfortunate case of the order of execution of call arguments. link(self->currBasicBlock, self->startBasicBlock()) would run the call first, which sets currBasicBlock, so we'd end up with the same value for both parameters. Without this fix, the testcase would drop the result of the call, as it thought it had no uses. Also improve debug logging here a tiny bit. Found by emscripten-core/emscripten#13485
1 parent 84eb631 commit b3b6a81

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/cfg/cfg-traversal.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> {
267267
doEndThrowingInst(self, currp);
268268
if (!self->unwindCatchStack.empty()) {
269269
// exception not thrown. link to the continuation BB
270-
self->link(self->currBasicBlock, self->startBasicBlock());
270+
auto* last = self->currBasicBlock;
271+
self->link(last, self->startBasicBlock());
271272
}
272273
}
273274

@@ -477,7 +478,8 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> {
477478
generateDebugIds();
478479
for (auto& block : basicBlocks) {
479480
assert(debugIds.count(block.get()) > 0);
480-
std::cout << " block " << debugIds[block.get()] << ":\n";
481+
std::cout << " block " << debugIds[block.get()] << " (" << block.get()
482+
<< "):\n";
481483
block->contents.dump(static_cast<SubType*>(this)->getFunction());
482484
for (auto& in : block->in) {
483485
assert(debugIds.count(in) > 0);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(module
2+
(type $none_=>_i32 (func (result i32)))
3+
(type $i32_=>_i32 (func (param i32) (result i32)))
4+
(export "foo" (func $1))
5+
(func $bar (result i32)
6+
(i32.const 1984)
7+
)
8+
(func $1 (param $0 i32) (result i32)
9+
(try $try
10+
(do
11+
(local.set $0
12+
(call $bar)
13+
)
14+
)
15+
(catch_all
16+
(unreachable)
17+
)
18+
)
19+
(local.get $0)
20+
)
21+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(module
2+
(func $bar (result i32)
3+
(i32.const 1984)
4+
)
5+
(func "foo" (param $0 i32) (result i32)
6+
(local $1 i32)
7+
(try
8+
(do
9+
(local.set $1
10+
(call $bar) ;; the call may or may not throw, so we may reach the get of $1
11+
)
12+
)
13+
(catch_all
14+
(unreachable)
15+
)
16+
)
17+
(local.get $1)
18+
)
19+
)

0 commit comments

Comments
 (0)