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
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
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to