summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-11-05 12:01:55 -0700
committerGitHub <noreply@github.com>2021-11-05 12:01:55 -0700
commit993ebb35dbd499bf36cd37bb79d695cd63767765 (patch)
tree0428690828c1c949786d38145d8da0edbe965150 /src
parent938e1ee240b802968cb9f458314eb92391d75f73 (diff)
downloadbinaryen-993ebb35dbd499bf36cd37bb79d695cd63767765.tar.gz
binaryen-993ebb35dbd499bf36cd37bb79d695cd63767765.tar.bz2
binaryen-993ebb35dbd499bf36cd37bb79d695cd63767765.zip
Fix fuzz bug in RemoveUnusedBrs with incremental type updating (#4309)
The BrOn logic there is incremental in optimizing and updating types, and so we cannot assume that at every point in the middle the types are fully updated.
Diffstat (limited to 'src')
-rw-r--r--src/passes/RemoveUnusedBrs.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 01c465f18..f383f669a 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -694,8 +694,13 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
bool worked = false;
void visitBrOn(BrOn* curr) {
- // Ignore unreachable BrOns which we cannot improve anyhow.
- if (curr->type == Type::unreachable) {
+ // Ignore unreachable BrOns which we cannot improve anyhow. Note that
+ // we must check the ref field manually, as we may be changing types as
+ // we go here. (Another option would be to use a TypeUpdater here
+ // instead of calling ReFinalize at the very end, but that would be more
+ // complex and slower.)
+ if (curr->type == Type::unreachable ||
+ curr->ref->type == Type::unreachable) {
return;
}