r337146 - [MinGW] Automatically mangle Windows-specific entry points as C

Martin Storsjo via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 15 22:42:25 PDT 2018


Author: mstorsjo
Date: Sun Jul 15 22:42:25 2018
New Revision: 337146

URL: http://llvm.org/viewvc/llvm-project?rev=337146&view=rev
Log:
[MinGW] Automatically mangle Windows-specific entry points as C

This mangles entry points wmain, WinMain, wWinMain or DllMain as C
functions, to match the ABI for these functions.

We already did the same for these functions in MSVC mode, but we also
should do the same in the Itanium ABI.

This fixes PR38124.

Differential Revision: https://reviews.llvm.org/D49354

Added:
    cfe/trunk/test/CodeGenCXX/mangle-mingw.cpp
Modified:
    cfe/trunk/lib/AST/ItaniumMangle.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=337146&r1=337145&r2=337146&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Sun Jul 15 22:42:25 2018
@@ -592,6 +592,18 @@ bool ItaniumMangleContextImpl::shouldMan
     if (FD->isMain())
       return false;
 
+    // The Windows ABI expects that we would never mangle "typical"
+    // user-defined entry points regardless of visibility or freestanding-ness.
+    //
+    // N.B. This is distinct from asking about "main".  "main" has a lot of
+    // special rules associated with it in the standard while these
+    // user-defined entry points are outside of the purview of the standard.
+    // For example, there can be only one definition for "main" in a standards
+    // compliant program; however nothing forbids the existence of wmain and
+    // WinMain in the same translation unit.
+    if (FD->isMSVCRTEntryPoint())
+      return false;
+
     // C++ functions and those whose names are not a simple identifier need
     // mangling.
     if (!FD->getDeclName().isIdentifier() || L == CXXLanguageLinkage)

Added: cfe/trunk/test/CodeGenCXX/mangle-mingw.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-mingw.cpp?rev=337146&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-mingw.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/mangle-mingw.cpp Sun Jul 15 22:42:25 2018
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-w64-mingw32 | FileCheck %s
+
+int func() { return 0; }
+// CHECK-DAG: @_Z4funcv
+
+int main() { return 0; }
+// CHECK-DAG: @main
+
+int wmain() { return 0; }
+// CHECK-DAG: @wmain
+
+int WinMain() { return 0; }
+// CHECK-DAG: @WinMain
+
+int wWinMain() { return 0; }
+// CHECK-DAG: @wWinMain
+
+int DllMain() { return 0; }
+// CHECK-DAG: @DllMain




More information about the cfe-commits mailing list