From 17f131f228b34292c344f295c78580715c673fe5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 22 Feb 2021 16:13:23 -0800 Subject: [PATCH] fix --- src/cfg/cfg-traversal.h | 6 ++++-- test/passes/coalesce-locals_all-features.txt | 21 +++++++++++++++++++ test/passes/coalesce-locals_all-features.wast | 19 +++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/passes/coalesce-locals_all-features.txt create mode 100644 test/passes/coalesce-locals_all-features.wast diff --git a/src/cfg/cfg-traversal.h b/src/cfg/cfg-traversal.h index fe85f0b9f48..02a1970df14 100644 --- a/src/cfg/cfg-traversal.h +++ b/src/cfg/cfg-traversal.h @@ -267,7 +267,8 @@ struct CFGWalker : public ControlFlowWalker { doEndThrowingInst(self, currp); if (!self->unwindCatchStack.empty()) { // exception not thrown. link to the continuation BB - self->link(self->currBasicBlock, self->startBasicBlock()); + auto* last = self->currBasicBlock; + self->link(last, self->startBasicBlock()); } } @@ -477,7 +478,8 @@ struct CFGWalker : public ControlFlowWalker { generateDebugIds(); for (auto& block : basicBlocks) { assert(debugIds.count(block.get()) > 0); - std::cout << " block " << debugIds[block.get()] << ":\n"; + std::cout << " block " << debugIds[block.get()] << " (" << block.get() + << "):\n"; block->contents.dump(static_cast(this)->getFunction()); for (auto& in : block->in) { assert(debugIds.count(in) > 0); diff --git a/test/passes/coalesce-locals_all-features.txt b/test/passes/coalesce-locals_all-features.txt new file mode 100644 index 00000000000..f532f5d0e61 --- /dev/null +++ b/test/passes/coalesce-locals_all-features.txt @@ -0,0 +1,21 @@ +(module + (type $none_=>_i32 (func (result i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (export "foo" (func $1)) + (func $bar (result i32) + (i32.const 1984) + ) + (func $1 (param $0 i32) (result i32) + (try $try + (do + (local.set $0 + (call $bar) + ) + ) + (catch_all + (unreachable) + ) + ) + (local.get $0) + ) +) diff --git a/test/passes/coalesce-locals_all-features.wast b/test/passes/coalesce-locals_all-features.wast new file mode 100644 index 00000000000..ff7f04f0ce0 --- /dev/null +++ b/test/passes/coalesce-locals_all-features.wast @@ -0,0 +1,19 @@ +(module + (func $bar (result i32) + (i32.const 1984) + ) + (func "foo" (param $0 i32) (result i32) + (local $1 i32) + (try + (do + (local.set $1 + (call $bar) ;; the call may or may not throw, so we may reach the get of $1 + ) + ) + (catch_all + (unreachable) + ) + ) + (local.get $1) + ) +)