From c243e2889faa939b655940da7b0b0e7b21cfd08b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 10 Jul 2020 17:45:20 -0700 Subject: NoExitRuntime pass: Don't assume arguments have no side effects (#2953) This bug was present from the very first version of this pass from 2018, but it went unnoticed until now when a large project broke on it, for some reason after emscripten-core/emscripten#11403 Nothing wrong in that PR, probably just luck that it started to happen there... --- src/passes/NoExitRuntime.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/passes/NoExitRuntime.cpp b/src/passes/NoExitRuntime.cpp index 82a296cfc..deffccd36 100644 --- a/src/passes/NoExitRuntime.cpp +++ b/src/passes/NoExitRuntime.cpp @@ -46,7 +46,17 @@ struct NoExitRuntime : public WalkerPass> { } for (auto name : ATEXIT_NAMES) { if (name == import->base) { - replaceCurrent(Builder(*getModule()).replaceWithIdenticalType(curr)); + // Remove the call, and drop the arguments (which may have side + // effects); let other passes clean that up more. + Builder builder(*getModule()); + std::vector args; + for (auto* operand : curr->operands) { + args.push_back(builder.makeDrop(operand)); + } + // Ensure the block has the right type using the last arg. + args.push_back(builder.replaceWithIdenticalType(curr)); + replaceCurrent(builder.makeBlock(args)); + break; } } } -- cgit v1.2.3