summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-12-06 14:18:44 -0800
committerGitHub <noreply@github.com>2022-12-06 14:18:44 -0800
commit7769139efbe818c7ba36d1a382db5114ebee9df8 (patch)
treead14587c6213cfcdcb4dc0b7cb5d5a65499170a7 /src
parent080a2e151b9d740f62bd91708cccb1c9be322cb8 (diff)
downloadbinaryen-7769139efbe818c7ba36d1a382db5114ebee9df8.tar.gz
binaryen-7769139efbe818c7ba36d1a382db5114ebee9df8.tar.bz2
binaryen-7769139efbe818c7ba36d1a382db5114ebee9df8.zip
Fix an Inlining bug with a name collision in a br nested in a call param (#5323)
Diffstat (limited to 'src')
-rw-r--r--src/ir/branch-utils.h6
-rw-r--r--src/passes/Inlining.cpp24
2 files changed, 25 insertions, 5 deletions
diff --git a/src/ir/branch-utils.h b/src/ir/branch-utils.h
index d433a421e..3527f1b36 100644
--- a/src/ir/branch-utils.h
+++ b/src/ir/branch-utils.h
@@ -327,6 +327,12 @@ struct BranchAccumulator
auto selfBranches = getUniqueTargets(curr);
branches.insert(selfBranches.begin(), selfBranches.end());
}
+
+ static NameSet get(Expression* tree) {
+ BranchAccumulator accumulator;
+ accumulator.walk(tree);
+ return accumulator.branches;
+ }
};
// A helper structure for the common case of post-walking some IR while querying
diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp
index c542d1018..41083567c 100644
--- a/src/passes/Inlining.cpp
+++ b/src/passes/Inlining.cpp
@@ -338,11 +338,25 @@ static Expression* doInlining(Module* module,
//
// Here the br wants to go to the very outermost block, to represent a
// return from the inlined function's code, but it ends up captured by an
- // internal block.
- if (BranchUtils::hasBranchTarget(from->body, block->name)) {
- auto existingNames = BranchUtils::getBranchTargets(from->body);
- block->name = Names::getValidName(
- block->name, [&](Name test) { return !existingNames.count(test); });
+ // internal block. We also need to be careful of the call's children:
+ //
+ // (block $X ;; a new block we add as the target of returns
+ // (local.set $param
+ // (call's first parameter
+ // (br $X) ;; nested br in call's first parameter
+ // )
+ // )
+ //
+ // (In this case we could use a second block and define the named block $X
+ // after the call's parameters, but that adds work for an extremely rare
+ // situation.)
+ if (BranchUtils::hasBranchTarget(from->body, block->name) ||
+ BranchUtils::BranchSeeker::has(call, block->name)) {
+ auto fromNames = BranchUtils::getBranchTargets(from->body);
+ auto callNames = BranchUtils::BranchAccumulator::get(call);
+ block->name = Names::getValidName(block->name, [&](Name test) {
+ return !fromNames.count(test) && !callNames.count(test);
+ });
}
if (call->isReturn) {
if (retType.isConcrete()) {