From 2d1e1501f5da1436f61c8ff5440aca33e25a29e9 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 16 Oct 2023 15:51:05 -0700 Subject: Heap2Local: Refinalize when removing a cast (#6012) --- src/passes/Heap2Local.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/passes/Heap2Local.cpp b/src/passes/Heap2Local.cpp index e027f5a46..f0f691299 100644 --- a/src/passes/Heap2Local.cpp +++ b/src/passes/Heap2Local.cpp @@ -440,6 +440,20 @@ struct Heap2LocalOptimizer { // the allocation is a subtype of the type of the cast, and so // cannot trap. replaceCurrent(curr->ref); + + // We need to refinalize after this, as while we know the cast is not + // logically needed - the value flowing through will not be used - we do + // need validation to succeed even before other optimizations remove the + // code. For example: + // + // (block (result $B) + // (ref.cast $B + // (block (result $A) + // + // Without the cast this does not validate, so we need to refinalize + // (which will fix this, as we replace the unused value with a null, so + // that type will propagate out). + refinalize = true; } void visitStructSet(StructSet* curr) { -- cgit v1.2.3