summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2022-05-31 08:33:56 -0700
committerGitHub <noreply@github.com>2022-05-31 15:33:56 +0000
commit07d90673f1765c3ddff03f7748caefe9a7d14ffa (patch)
tree12b4c64b7b0c3b5024fdb81ef5cb9b04acc33751
parent46282a482ec81e8d379b4e9b3ee50f66dd0ac5e5 (diff)
downloadbinaryen-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
-rw-r--r--src/wasm/wasm-emscripten.cpp16
-rw-r--r--test/lld/basic_safe_stack.wat.out2
-rw-r--r--test/lld/duplicate_imports.wat.out2
3 files changed, 12 insertions, 8 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;
+ }
}
}
}
diff --git a/test/lld/basic_safe_stack.wat.out b/test/lld/basic_safe_stack.wat.out
index 6e1b83712..9ed9eb221 100644
--- a/test/lld/basic_safe_stack.wat.out
+++ b/test/lld/basic_safe_stack.wat.out
@@ -107,7 +107,7 @@
},
"invokeFuncs": [
],
- "mainReadsParams": 1,
+ "mainReadsParams": 0,
"features": [
]
}
diff --git a/test/lld/duplicate_imports.wat.out b/test/lld/duplicate_imports.wat.out
index 38a08e50f..68f4d96a6 100644
--- a/test/lld/duplicate_imports.wat.out
+++ b/test/lld/duplicate_imports.wat.out
@@ -85,7 +85,7 @@
"invokeFuncs": [
"invoke_ffd"
],
- "mainReadsParams": 1,
+ "mainReadsParams": 0,
"features": [
]
}