diff options
author | Alon Zakai <azakai@google.com> | 2020-07-10 17:45:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-10 17:45:20 -0700 |
commit | c243e2889faa939b655940da7b0b0e7b21cfd08b (patch) | |
tree | aefa68646323f7a81e3720237132a8168baca45a /src | |
parent | bc4bb83d94a8a6240bead6ad9c18702bd9c331e7 (diff) | |
download | binaryen-c243e2889faa939b655940da7b0b0e7b21cfd08b.tar.gz binaryen-c243e2889faa939b655940da7b0b0e7b21cfd08b.tar.bz2 binaryen-c243e2889faa939b655940da7b0b0e7b21cfd08b.zip |
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...
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/NoExitRuntime.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
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<PostWalker<NoExitRuntime>> { } 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<Expression*> 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; } } } |