diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -72,7 +72,7 @@ // can call it with the correct function signature. if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) - if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) + if (FD->isMain() && FD->getNumParams() == 2) return CCM_WasmMainArgcArgv; if (!Triple.isOSWindows() || !Triple.isX86()) diff --git a/clang/test/CodeGen/mangle-wasm-main-noproto.c b/clang/test/CodeGen/mangle-wasm-main-noproto.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/mangle-wasm-main-noproto.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=wasm32-unknown-unknown -Wno-deprecated-non-prototype | FileCheck %s + +int main(argc, argv) + int argc; + char* argv[]; +{ + return 0; +} +// CHECK-NOT: __main_void +// CHECK: define i32 @__main_argc_argv(i32 noundef %argc, ptr noundef %argv) #0 { diff --git a/clang/test/CodeGen/mangle-wasm-main-void.c b/clang/test/CodeGen/mangle-wasm-main-void.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/mangle-wasm-main-void.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=wasm32-unknown-unknown | FileCheck %s + +int main(void) { + return 0; +} +// CHECK: @__main_void = hidden alias i32 (), ptr @main +// CHECK: define i32 @main() #0 { diff --git a/clang/test/CodeGen/mangle-wasm-main.c b/clang/test/CodeGen/mangle-wasm-main.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/mangle-wasm-main.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=wasm32-unknown-unknown | FileCheck %s + +int main(int argc, char* argv[]) { + return 0; +} +// CHECK-NOT: __main_void +// CHECK: define i32 @__main_argc_argv(i32 noundef %argc, ptr noundef %argv) #0 {