diff options
author | Alon Zakai <azakai@google.com> | 2023-05-09 09:07:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-09 09:07:35 -0700 |
commit | 91b067031219c2b6112a9020e794fefb05afb56b (patch) | |
tree | 79da70b02c018a220d5f46c24560ba7093a556e0 /src | |
parent | 6086df072d07bc7cc63f65eafd9eca92ef8e3e89 (diff) | |
download | binaryen-91b067031219c2b6112a9020e794fefb05afb56b.tar.gz binaryen-91b067031219c2b6112a9020e794fefb05afb56b.tar.bz2 binaryen-91b067031219c2b6112a9020e794fefb05afb56b.zip |
Fix optimizeAddedConstants on GC-introduced unreachability (#5706)
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index acb2c8d66..af7369994 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -2924,6 +2924,11 @@ private: } } }; + // Noting the type here not only simplifies the code below, but is also + // necessary to avoid an error: if we look at walked->type then it may + // actually differ from the original type, say if the walk ended up turning + // |binary| into a simpler unreachable expression. + auto type = binary->type; Expression* walked = binary; ZeroRemover remover(getPassOptions()); remover.setModule(getModule()); @@ -2936,14 +2941,14 @@ private: // Accumulated 64-bit constant value in 32-bit context will be wrapped // during downcasting. So it's valid unification for 32-bit and 64-bit // values. - c->value = Literal::makeFromInt64(constant, c->type); + c->value = Literal::makeFromInt64(constant, type); return c; } Builder builder(*getModule()); return builder.makeBinary( - Abstract::getBinary(walked->type, Abstract::Add), + Abstract::getBinary(type, Abstract::Add), walked, - builder.makeConst(Literal::makeFromInt64(constant, walked->type))); + builder.makeConst(Literal::makeFromInt64(constant, type))); } // Given an i64.wrap operation, see if we can remove it. If all the things |