Remove the `hasPrototype()` restriction so that old style K&R
declarations of main work too.
For example the following has 2 params but no prototype.
```
int main(argc, argv)
int argc;
char *argv[];
{
return 0;
}
```
Also, use `getNumParams()` over `param_size()` which seems to be a more
direct way to get at the same information.
Also, add missing tests for this mangling.
Differential Revision: https://reviews.llvm.org/
D127888
// can call it with the correct function signature.
if (Triple.isWasm())
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND))
- if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2)
+ if (FD->isMain() && FD->getNumParams() == 2)
return CCM_WasmMainArgcArgv;
if (!Triple.isOSWindows() || !Triple.isX86())
--- /dev/null
+// 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 {
--- /dev/null
+// 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 {
--- /dev/null
+// 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 {