summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm/wasm.cpp4
-rw-r--r--test/passes/remove-unused-brs.txt13
-rw-r--r--test/passes/remove-unused-brs.wast13
3 files changed, 29 insertions, 1 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 4f5f46f0a..635d14354 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -109,18 +109,20 @@ struct TypeSeeker : public PostWalker<TypeSeeker> {
Name targetName;
std::vector<WasmType> types;
+
TypeSeeker(Expression* target, Name targetName) : target(target), targetName(targetName) {
Expression* temp = target;
walk(temp);
}
void visitBreak(Break* curr) {
- if (curr->name == targetName) {
+ if (curr->name == targetName && BranchUtils::isBranchTaken(curr)) {
types.push_back(curr->value ? curr->value->type : none);
}
}
void visitSwitch(Switch* curr) {
+ if (!BranchUtils::isBranchTaken(curr)) return;
for (auto name : curr->targets) {
if (name == targetName) types.push_back(curr->value ? curr->value->type : none);
}
diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt
index 417bd3728..355f8a531 100644
--- a/test/passes/remove-unused-brs.txt
+++ b/test/passes/remove-unused-brs.txt
@@ -1035,4 +1035,17 @@
)
)
)
+ (func $untaken-br-with-concrete-last-element (type $2) (result i32)
+ (block $label$8 (result i32)
+ (block $label$11 (result i32)
+ (block $label$14
+ (br_if $label$8
+ (br $label$11
+ (i32.const 103)
+ )
+ )
+ )
+ )
+ )
+ )
)
diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast
index d694bd4d0..e7c221fa4 100644
--- a/test/passes/remove-unused-brs.wast
+++ b/test/passes/remove-unused-brs.wast
@@ -919,5 +919,18 @@
)
)
)
+ (func $untaken-br-with-concrete-last-element (result i32)
+ (block $label$8 (result i32)
+ (block $label$11 (result i32)
+ (block $label$14
+ (br_if $label$14
+ (br $label$11
+ (i32.const 103)
+ )
+ )
+ )
+ )
+ )
+ )
)