diff options
-rw-r--r-- | src/passes/RemoveUnusedNames.cpp | 2 | ||||
-rw-r--r-- | test/passes/remove-unused-names.txt | 17 | ||||
-rw-r--r-- | test/passes/remove-unused-names.wast | 16 |
3 files changed, 34 insertions, 1 deletions
diff --git a/src/passes/RemoveUnusedNames.cpp b/src/passes/RemoveUnusedNames.cpp index 39bf068df..e5aaf5509 100644 --- a/src/passes/RemoveUnusedNames.cpp +++ b/src/passes/RemoveUnusedNames.cpp @@ -57,7 +57,7 @@ struct RemoveUnusedNames : public WalkerPass<PostWalker<RemoveUnusedNames>> { void visitBlock(Block *curr) { if (curr->name.is() && curr->list.size() == 1) { auto* child = curr->list[0]->dynCast<Block>(); - if (child && child->name.is()) { + if (child && child->name.is() && child->type == curr->type) { // we have just one child, this block, so breaking out of it goes to the same place as breaking out of us, we just need one name (and block) auto& branches = branchesSeen[curr->name]; for (auto* branch : branches) { diff --git a/test/passes/remove-unused-names.txt b/test/passes/remove-unused-names.txt index 91b8b8981..894e07165 100644 --- a/test/passes/remove-unused-names.txt +++ b/test/passes/remove-unused-names.txt @@ -1,6 +1,7 @@ (module (type $0 (func (param i32) (result i32))) (type $1 (func)) + (type $2 (func (result i32))) (memory $0 256 256) (func $b0 (type $0) (param $i1 i32) (result i32) (i32.const 0) @@ -63,4 +64,20 @@ ) ) ) + (func $merge-typed-with-unreachable-child (type $2) (result i32) + (local $0 f32) + (block $label$0 (result i32) + (block $label$1 + (br_if $label$1 + (i32.const 0) + (br_if $label$0 + (i32.const 0) + (br $label$0 + (i32.const 0) + ) + ) + ) + ) + ) + ) ) diff --git a/test/passes/remove-unused-names.wast b/test/passes/remove-unused-names.wast index 0f8fe4dcc..dc882cf4c 100644 --- a/test/passes/remove-unused-names.wast +++ b/test/passes/remove-unused-names.wast @@ -77,4 +77,20 @@ ) ) ) + (func $merge-typed-with-unreachable-child (result i32) + (local $0 f32) + (block $label$0 (result i32) + (block $label$1 + (br_if $label$1 + (i32.const 0) + (br_if $label$0 + (i32.const 0) + (br $label$0 + (i32.const 0) + ) + ) + ) + ) + ) + ) ) |