diff options
-rw-r--r-- | src/ir/branch-utils.h | 2 | ||||
-rw-r--r-- | test/passes/code-folding.txt | 22 | ||||
-rw-r--r-- | test/passes/code-folding.wast | 21 |
3 files changed, 44 insertions, 1 deletions
diff --git a/src/ir/branch-utils.h b/src/ir/branch-utils.h index e8fd25119..b9448e590 100644 --- a/src/ir/branch-utils.h +++ b/src/ir/branch-utils.h @@ -95,7 +95,7 @@ inline std::set<Name> getExitingBranches(Expression* ast) { targets.insert(curr->name); } void visitSwitch(Switch* curr) { - for (auto target : targets) { + for (auto target : curr->targets) { targets.insert(target); } targets.insert(curr->default_); diff --git a/test/passes/code-folding.txt b/test/passes/code-folding.txt index 4b512940c..0fe3aa144 100644 --- a/test/passes/code-folding.txt +++ b/test/passes/code-folding.txt @@ -142,6 +142,7 @@ ) (module (type $0 (func)) + (type $1 (func (param i32))) (global $global$0 (mut i32) (i32.const 10)) (func $determinism (; 0 ;) (type $0) (block $folding-inner0 @@ -181,4 +182,25 @@ ) (unreachable) ) + (func $careful-of-the-switch (; 1 ;) (type $1) (param $0 i32) + (block $label$1 + (block $label$3 + (block $label$5 + (block $label$7 + (br_table $label$3 $label$7 + (i32.const 0) + ) + ) + (br $label$1) + ) + (block $label$8 + (br_table $label$3 $label$8 + (i32.const 0) + ) + ) + (br $label$1) + ) + (unreachable) + ) + ) ) diff --git a/test/passes/code-folding.wast b/test/passes/code-folding.wast index a813f44a6..d9c1cc950 100644 --- a/test/passes/code-folding.wast +++ b/test/passes/code-folding.wast @@ -198,5 +198,26 @@ ) (unreachable) ) + (func $careful-of-the-switch (param $0 i32) + (block $label$1 + (block $label$3 + (block $label$5 + (block $label$7 ;; this is block is equal to $label$8 when accounting for the internal 7/8 difference + (br_table $label$3 $label$7 ;; the reference to $label$3 must remain valid, cannot hoist out of it! + (i32.const 0) + ) + ) + (br $label$1) + ) + (block $label$8 + (br_table $label$3 $label$8 + (i32.const 0) + ) + ) + (br $label$1) + ) + (unreachable) + ) + ) ) |