summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-02-15 13:05:25 -0800
committerGitHub <noreply@github.com>2023-02-15 13:05:25 -0800
commitc4d15efc62fb6e6b55dd128e62896c93ca52c98a (patch)
tree9d24b32068ece1bc76d55067f4464b0df4e308b8 /src
parent8f98375c051f2b8e1be87e7eb97e88d73cfb2c26 (diff)
downloadbinaryen-c4d15efc62fb6e6b55dd128e62896c93ca52c98a.tar.gz
binaryen-c4d15efc62fb6e6b55dd128e62896c93ca52c98a.tar.bz2
binaryen-c4d15efc62fb6e6b55dd128e62896c93ca52c98a.zip
Unreachability fixes for inlining (#5492)
We must refinalize as inlining unreachable code can lead to more things becoming unreachable. We also must uniquify label names before refinalizing, as the IR must be valid at that time, so that code is moved. This causes some minor changes to existing test code (some label changes, and refinalization makes more things unreachable), but only the two new tests show actual problems that needed to be fixed.
Diffstat (limited to 'src')
-rw-r--r--src/passes/Inlining.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp
index 4475db7b0..7df5c8f29 100644
--- a/src/passes/Inlining.cpp
+++ b/src/passes/Inlining.cpp
@@ -413,6 +413,16 @@ static Expression* doInlining(Module* module,
// Make the block reachable by adding a break to it
block->list.push_back(builder.makeBreak(block->name));
}
+ // Anything we inlined into may now have non-unique label names, fix it up.
+ // Note that we must do this before refinalization, as otherwise duplicate
+ // block labels can lead to errors (the IR must be valid before we
+ // refinalize).
+ wasm::UniqueNameMapper::uniquify(into->body);
+ // Inlining unreachable contents can make things in the function we inlined
+ // into unreachable.
+ ReFinalize().walkFunctionInModule(into, module);
+ // New locals we added may require fixups for nondefaultability.
+ // FIXME Is this not done automatically?
TypeUpdating::handleNonDefaultableLocals(into, *module);
return block;
}
@@ -1039,11 +1049,6 @@ struct Inlining : public Pass {
assert(inlinedUses[inlinedName] <= infos[inlinedName].refs);
}
}
- for (auto func : inlinedInto) {
- // Anything we inlined into may now have non-unique label names, fix it
- // up.
- wasm::UniqueNameMapper::uniquify(func->body);
- }
if (optimize && inlinedInto.size() > 0) {
OptUtils::optimizeAfterInlining(inlinedInto, module, getPassRunner());
}