summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-02-18 22:32:34 +0000
committerGitHub <noreply@github.com>2021-02-18 14:32:34 -0800
commitad0c8b4fd3808755fc071d43ebaa582a46d74922 (patch)
treee0b7934fdd754e8de1572b7eb4f68b361133b9ea /src
parentec2aa7e870ef4d9926e35c5f4bfc7cdbabe2441a (diff)
downloadbinaryen-ad0c8b4fd3808755fc071d43ebaa582a46d74922.tar.gz
binaryen-ad0c8b4fd3808755fc071d43ebaa582a46d74922.tar.bz2
binaryen-ad0c8b4fd3808755fc071d43ebaa582a46d74922.zip
[Wasm Exceptions] Fix RemoveUnusedNames on Try (#3583)
The delegate field of Try was not being scanned, so we could remove a name that was used only by a delegate. The bug was because visitTry overrides the generic visitor visitExpression. So we need to call it manually. Sadly the code here was pretty old (I probably wrote it back in 2015 or so) and it was misleading, as it had unnecessary calls from the generic visitor to visitBlock, visitLoop, which are not needed. This PR removes them which is shorter and cleaner. Also, we must handle the case of the delegate field being unset, so check name.is().
Diffstat (limited to 'src')
-rw-r--r--src/passes/RemoveUnusedNames.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/passes/RemoveUnusedNames.cpp b/src/passes/RemoveUnusedNames.cpp
index 53da00733..addd4367b 100644
--- a/src/passes/RemoveUnusedNames.cpp
+++ b/src/passes/RemoveUnusedNames.cpp
@@ -37,16 +37,11 @@ struct RemoveUnusedNames
std::map<Name, std::set<Expression*>> branchesSeen;
void visitExpression(Expression* curr) {
- if (auto* block = curr->dynCast<Block>()) {
- visitBlock(block);
- return;
- }
- if (auto* loop = curr->dynCast<Loop>()) {
- visitLoop(loop);
- return;
- }
- BranchUtils::operateOnScopeNameUses(
- curr, [&](Name& name) { branchesSeen[name].insert(curr); });
+ BranchUtils::operateOnScopeNameUses(curr, [&](Name& name) {
+ if (name.is()) {
+ branchesSeen[name].insert(curr);
+ }
+ });
}
void handleBreakTarget(Name& name) {
@@ -83,7 +78,12 @@ struct RemoveUnusedNames
}
}
- void visitTry(Try* curr) { handleBreakTarget(curr->name); }
+ void visitTry(Try* curr) {
+ handleBreakTarget(curr->name);
+ // Try has not just a break target but also an optional delegate with a
+ // target name, so call the generic visitor as well to handle that.
+ visitExpression(curr);
+ }
void visitFunction(Function* curr) { assert(branchesSeen.empty()); }
};