summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-04-17 10:18:36 -0700
committerGitHub <noreply@github.com>2023-04-17 10:18:36 -0700
commit5679e3b1ea0d4155a6b5c3b93fa6aef34023365f (patch)
treed7da64adf799b2f7fe3c876d106c3de85cdbee90 /src
parentaddbc66ff7a42ed3b94c05e188db936b36968c9f (diff)
downloadbinaryen-5679e3b1ea0d4155a6b5c3b93fa6aef34023365f.tar.gz
binaryen-5679e3b1ea0d4155a6b5c3b93fa6aef34023365f.tar.bz2
binaryen-5679e3b1ea0d4155a6b5c3b93fa6aef34023365f.zip
[Wasm GC] OptimizeInstructions: Don't turn ref.test into unreachable immediately (#5673)
Emit an unreachable, but guarded by a block as we do in other cases in this pass, to avoid having unreachable code that is not fully propagated during the pass (as we only do a full refinalize at the end). See existing comments starting with "Make sure to emit a block with the same type as us" in the pass. This is mostly not a problem with other casts, but ref.test returns an i32 which we have lots of code that tries to optimize.
Diffstat (limited to 'src')
-rw-r--r--src/passes/OptimizeInstructions.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 70df652b8..6251348af 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -2169,8 +2169,12 @@ struct OptimizeInstructions
{builder.makeDrop(curr->ref), builder.makeConst(int32_t(1))}));
break;
case GCTypeUtils::Unreachable:
- replaceCurrent(builder.makeSequence(builder.makeDrop(curr->ref),
- builder.makeUnreachable()));
+ // Make sure to emit a block with the same type as us, to avoid other
+ // code in this pass needing to handle unexpected unreachable code
+ // (which is only properly propagated at the end of this pass when we
+ // refinalize).
+ replaceCurrent(builder.makeBlock(
+ {builder.makeDrop(curr->ref), builder.makeUnreachable()}, Type::i32));
break;
case GCTypeUtils::Failure:
replaceCurrent(builder.makeSequence(builder.makeDrop(curr->ref),