summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/RemoveUnusedNames.cpp7
-rw-r--r--test/passes/remove-unused-names_all-features.txt8
-rw-r--r--test/passes/remove-unused-names_all-features.wast8
3 files changed, 22 insertions, 1 deletions
diff --git a/src/passes/RemoveUnusedNames.cpp b/src/passes/RemoveUnusedNames.cpp
index addd4367b..a08cb5eda 100644
--- a/src/passes/RemoveUnusedNames.cpp
+++ b/src/passes/RemoveUnusedNames.cpp
@@ -21,6 +21,7 @@
#include <ir/branch-utils.h>
#include <pass.h>
+#include <shared-constants.h>
#include <wasm.h>
namespace wasm {
@@ -85,7 +86,11 @@ struct RemoveUnusedNames
visitExpression(curr);
}
- void visitFunction(Function* curr) { assert(branchesSeen.empty()); }
+ void visitFunction(Function* curr) {
+ // When we reach the function body we can erase delegations to the caller.
+ branchesSeen.erase(DELEGATE_CALLER_TARGET);
+ assert(branchesSeen.empty());
+ }
};
Pass* createRemoveUnusedNamesPass() { return new RemoveUnusedNames(); }
diff --git a/test/passes/remove-unused-names_all-features.txt b/test/passes/remove-unused-names_all-features.txt
index 6e3bba584..d3a9146c8 100644
--- a/test/passes/remove-unused-names_all-features.txt
+++ b/test/passes/remove-unused-names_all-features.txt
@@ -26,4 +26,12 @@
)
)
)
+ (func $1
+ (try
+ (do
+ (nop)
+ )
+ (delegate 0)
+ )
+ )
)
diff --git a/test/passes/remove-unused-names_all-features.wast b/test/passes/remove-unused-names_all-features.wast
index 1c1bd43e2..c55268a7a 100644
--- a/test/passes/remove-unused-names_all-features.wast
+++ b/test/passes/remove-unused-names_all-features.wast
@@ -23,4 +23,12 @@
)
)
)
+ (func $1
+ (try $label$3
+ (do
+ (nop)
+ )
+ (delegate 0) ;; delegates to the caller
+ )
+ )
)