From ad723a19b018a786bcbec8d9e16160f30959e60e Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 28 Dec 2021 17:05:09 -0800 Subject: [EH][GC] Fix nested pop after removing ref.cast (#4407) `ref.cast` can be statically removed when the ref's type is a subtype of the intended RTT type and either of `--ignore-implicit-traps` or `--traps-never-happen` is given: https://github.com/WebAssembly/binaryen/blob/083ab9842ec3d4ca278c95e1a33112ae7cd4d9e5/src/passes/OptimizeInstructions.cpp#L1603-L1624 Some more context: https://github.com/WebAssembly/binaryen/pull/4097#discussion_r694456784 But this can create a block in which a `pop` is nested, which makes the `catch` invalid. The test in this PR is the same as the example given by @kripken in #4237. This calls the fixup function `EHUtils::handleBlockNestedPops` at the end of the pass to fix this. Also, because this pass creates a lot of blocks in other patterns, I think it is possible there can be other patterns to cause this kind of `pop` nesting. --- src/passes/OptimizeInstructions.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 80ca7162c..347ebbbe4 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -229,6 +230,9 @@ struct OptimizeInstructions // Some patterns create locals (like when we use getResultOfFirst), which we // may need to fix up. TypeUpdating::handleNonDefaultableLocals(func, *getModule()); + // Some patterns create blocks that can interfere 'catch' and 'pop', nesting + // the 'pop' into a block making it invalid. + EHUtils::handleBlockNestedPops(func, *getModule()); } // Set to true when one of the visitors makes a change (either replacing the -- cgit v1.2.3