summaryrefslogtreecommitdiff
path: root/src/passes/RemoveUnusedBrs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/RemoveUnusedBrs.cpp')
-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;
}