diff options
author | Sam Clegg <sbc@chromium.org> | 2022-05-31 08:33:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 15:33:56 +0000 |
commit | 07d90673f1765c3ddff03f7748caefe9a7d14ffa (patch) | |
tree | 12b4c64b7b0c3b5024fdb81ef5cb9b04acc33751 /src | |
parent | 46282a482ec81e8d379b4e9b3ee50f66dd0ac5e5 (diff) | |
download | binaryen-07d90673f1765c3ddff03f7748caefe9a7d14ffa.tar.gz binaryen-07d90673f1765c3ddff03f7748caefe9a7d14ffa.tar.bz2 binaryen-07d90673f1765c3ddff03f7748caefe9a7d14ffa.zip |
wasm-emscripten-finalize: Improve detection of mainReadsParams (#4701)
The first way to should detect this is if the main function actually
doesn't take any params. They we fallback to looking deeper.
In preparation for https://reviews.llvm.org/D75277
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index bba638cf2..fea5048f6 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -477,12 +477,16 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata() { if (exp) { if (exp->kind == ExternalKind::Function) { auto* main = wasm.getFunction(exp->value); - mainReadsParams = true; - // If main does not read its parameters, it will just be a stub that - // calls __original_main (which has no parameters). - if (auto* call = main->body->dynCast<Call>()) { - if (call->operands.empty()) { - mainReadsParams = false; + mainReadsParams = main->getNumParams() > 0; + if (mainReadsParams) { + // Main could also be stub that just calls __original_main with + // no parameters. + // TODO(sbc): Remove this once https://reviews.llvm.org/D75277 + // lands. + if (auto* call = main->body->dynCast<Call>()) { + if (call->operands.empty()) { + mainReadsParams = false; + } } } } |