[PATCH] D127888: [clang][WebAssembly] Loosen restriction on `main` symbol mangling

Sam Clegg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 15 11:42:59 PDT 2022


sbc100 updated this revision to Diff 437272.
sbc100 edited the summary of this revision.
sbc100 added a comment.
Herald added a subscriber: asb.

add tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127888/new/

https://reviews.llvm.org/D127888

Files:
  clang/lib/AST/Mangle.cpp
  clang/test/CodeGen/mangle-wasm-main-noproto.c
  clang/test/CodeGen/mangle-wasm-main-void.c
  clang/test/CodeGen/mangle-wasm-main.c


Index: clang/test/CodeGen/mangle-wasm-main.c
===================================================================
--- /dev/null
+++ 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 { 
Index: clang/test/CodeGen/mangle-wasm-main-void.c
===================================================================
--- /dev/null
+++ 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 {
Index: clang/test/CodeGen/mangle-wasm-main-noproto.c
===================================================================
--- /dev/null
+++ 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 { 
Index: clang/lib/AST/Mangle.cpp
===================================================================
--- clang/lib/AST/Mangle.cpp
+++ 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<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())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127888.437272.patch
Type: text/x-patch
Size: 1874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220615/05dfd304/attachment-0001.bin>


More information about the cfe-commits mailing list