[PATCH] AST: 'wmain' is also an entry point for win32

David Majnemer david.majnemer at gmail.com
Thu Sep 12 19:53:37 PDT 2013


Hi rsmith, rjmccall,

'wmain' and 'main' are both considered main functions in win32

http://llvm-reviews.chandlerc.com/D1667

Files:
  lib/AST/Decl.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CodeGenCXX/mangle-ms.cpp

Index: lib/AST/Decl.cpp
===================================================================
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -2197,11 +2197,20 @@
 }
 
 bool FunctionDecl::isMain() const {
-  const TranslationUnitDecl *tunit =
-    dyn_cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext());
-  return tunit &&
-         !tunit->getASTContext().getLangOpts().Freestanding &&
-         isNamed(this, "main");
+  if (const TranslationUnitDecl *TUnit =
+          dyn_cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext())) {
+    if (TUnit->getASTContext().getLangOpts().Freestanding)
+      return false;
+
+    if (isNamed(this, "main"))
+      return true;
+
+    if (TUnit->getASTContext().getTargetInfo().getTriple().getOS() ==
+        llvm::Triple::Win32)
+      if (isNamed(this, "wmain"))
+        return true;
+  }
+  return false;
 }
 
 bool FunctionDecl::isReservedGlobalPlacementOperator() const {
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -101,8 +101,7 @@
     if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
       // Precondition: the first argument of 'main' is an integer guaranteed
       //  to be > 0.
-      const IdentifierInfo *II = FD->getIdentifier();
-      if (!II || !(II->getName() == "main" && FD->getNumParams() > 0))
+      if (!FD->isMain() || FD->getNumParams() == 0)
         break;
 
       const ParmVarDecl *PD = FD->getParamDecl(0);
Index: test/CodeGenCXX/mangle-ms.cpp
===================================================================
--- test/CodeGenCXX/mangle-ms.cpp
+++ test/CodeGenCXX/mangle-ms.cpp
@@ -245,3 +245,7 @@
     return s0[0] + s1[0] + s2[0] + s3[0] + s4[0] + s5[0] + s6[0][0];
   }
 }
+
+int wmain() {
+}
+// CHECK: @wmain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1667.1.patch
Type: text/x-patch
Size: 1880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130912/41cf0d8a/attachment.bin>


More information about the cfe-commits mailing list