From 07d90673f1765c3ddff03f7748caefe9a7d14ffa Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 31 May 2022 08:33:56 -0700 Subject: 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 --- src/wasm/wasm-emscripten.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') 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()) { - 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()) { + if (call->operands.empty()) { + mainReadsParams = false; + } } } } -- cgit v1.2.3