summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-04-24 14:22:21 -0700
committerGitHub <noreply@github.com>2020-04-24 14:22:21 -0700
commit99708992211d82dd7f157b2dda6dd81e59671378 (patch)
tree61371dccaa07cf06271dccb54fffb8947411f2eb
parent8e7a5c2bd2e8f296d840cc1ab76b1712609e71d8 (diff)
downloadbinaryen-99708992211d82dd7f157b2dda6dd81e59671378.tar.gz
binaryen-99708992211d82dd7f157b2dda6dd81e59671378.tar.bz2
binaryen-99708992211d82dd7f157b2dda6dd81e59671378.zip
Fix RemoveUnusedNames on a loop with no name and a child with a different type. fixes #2807 (#2808)
-rw-r--r--src/passes/RemoveUnusedNames.cpp2
-rw-r--r--test/passes/remove-unused-names.txt7
-rw-r--r--test/passes/remove-unused-names.wast9
3 files changed, 17 insertions, 1 deletions
diff --git a/src/passes/RemoveUnusedNames.cpp b/src/passes/RemoveUnusedNames.cpp
index 1cd974704..d2fc51379 100644
--- a/src/passes/RemoveUnusedNames.cpp
+++ b/src/passes/RemoveUnusedNames.cpp
@@ -92,7 +92,7 @@ struct RemoveUnusedNames : public WalkerPass<PostWalker<RemoveUnusedNames>> {
void visitLoop(Loop* curr) {
handleBreakTarget(curr->name);
- if (!curr->name.is()) {
+ if (!curr->name.is() && curr->body->type == curr->type) {
replaceCurrent(curr->body);
}
}
diff --git a/test/passes/remove-unused-names.txt b/test/passes/remove-unused-names.txt
index 27b9cc76c..43950ca26 100644
--- a/test/passes/remove-unused-names.txt
+++ b/test/passes/remove-unused-names.txt
@@ -78,4 +78,11 @@
)
)
)
+ (func $loop-with-child-of-other-type
+ (drop
+ (loop (result i32)
+ (unreachable)
+ )
+ )
+ )
)
diff --git a/test/passes/remove-unused-names.wast b/test/passes/remove-unused-names.wast
index a4c240f02..766a56bec 100644
--- a/test/passes/remove-unused-names.wast
+++ b/test/passes/remove-unused-names.wast
@@ -93,4 +93,13 @@
)
)
)
+ (func $loop-with-child-of-other-type
+ (drop
+ (loop (result i32) ;; the loop has no name, but can't be replaced by the child
+ (block $l ;; as the type differs
+ (unreachable)
+ )
+ )
+ )
+ )
)