[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:33:02 PDT 2022


sbc100 created this revision.
Herald added subscribers: pmatos, wingo, ecnelises, sunfish, jgravelle-google, dschuff.
Herald added a project: All.
sbc100 requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127888

Files:
  clang/lib/AST/Mangle.cpp


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.437267.patch
Type: text/x-patch
Size: 530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220615/dde926e3/attachment.bin>


More information about the cfe-commits mailing list