2828#include < memory>
2929
3030#include " ir/branch-utils.h"
31+ #include " ir/eh-utils.h"
3132#include " ir/iteration.h"
3233#include " ir/localize.h"
3334#include " ir/properties.h"
@@ -1089,9 +1090,13 @@ struct Reducer
10891090 struct FunctionReplacer
10901091 : public WalkerPass<PostWalker<FunctionReplacer>> {
10911092 bool isFunctionParallel () override { return true ; }
1093+
10921094 std::unique_ptr<Pass> create () override {
10931095 return std::make_unique<FunctionReplacer>();
10941096 };
1097+
1098+ bool needEHFixups = false ;
1099+
10951100 void visitCall (Call* curr) {
10961101 // Replace calls to functions we have removed.
10971102 if (getModule ()->getFunctionOrNull (curr->target )) {
@@ -1112,6 +1117,9 @@ struct Reducer
11121117 block->list .push_back (replacement);
11131118 block->type = originalType;
11141119 replaceCurrent (block);
1120+ // We added a block around content here, possibly causing us to need
1121+ // EH fixups later.
1122+ needEHFixups = true ;
11151123 }
11161124 void visitRefFunc (RefFunc* curr) {
11171125 // Replace references to functions we have removed.
@@ -1122,6 +1130,11 @@ struct Reducer
11221130 replaceCurrent (
11231131 builder.makeBlock ({builder.makeUnreachable ()}, curr->type ));
11241132 }
1133+ void visitFunction (Function* curr) {
1134+ if (needEHFixups) {
1135+ EHUtils::handleBlockNestedPops (curr, *getModule ());
1136+ }
1137+ }
11251138 };
11261139 PassRunner runner (module .get ());
11271140 runner.add (std::make_unique<FunctionReplacer>());
0 commit comments