Hi timurrrr, pcc, rnk, whunt,
Functions named "main", "wmain", "WinMain", "wWinMain", and "DllMain"
are never mangled regardless of linkage, even when compiling for kernel
mode.
Depends on D1655
http://llvm-reviews.chandlerc.com/D1670
Files:
lib/AST/MicrosoftMangle.cpp
test/CodeGenCXX/mangle-ms.cpp
Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -24,6 +24,7 @@
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringSwitch.h"
using namespace clang;
@@ -70,6 +71,22 @@
return fn;
}
+// Microsoft Visual C++ will never mangle some "standard" entry points
+// regardless of visibility or freestanding-ness.
+static bool isUserDefinedEntryPoint(const FunctionDecl *FD) {
+ if (!FD->getIdentifier())
+ return false;
+
+ return llvm::StringSwitch<bool>(FD->getName())
+ .Cases("main", // An ANSI console app
+ "wmain", // A Unicode console App
+ "WinMain", // An ANSI GUI app
+ "wWinMain", // A Unicode GUI app
+ "DllMain", // A DLL
+ true)
+ .Default(false);
+}
+
/// MicrosoftCXXNameMangler - Manage the mangling of a single name for the
/// Microsoft Visual C++ ABI.
class MicrosoftCXXNameMangler {
@@ -230,8 +247,7 @@
if (FD->hasAttr<OverloadableAttr>())
return true;
- // "main" is not mangled.
- if (FD->isMain())
+ if (isUserDefinedEntryPoint(FD))
return false;
// C++ functions and those whose names are not a simple identifier need
Index: test/CodeGenCXX/mangle-ms.cpp
===================================================================
--- test/CodeGenCXX/mangle-ms.cpp
+++ test/CodeGenCXX/mangle-ms.cpp
@@ -255,3 +255,28 @@
void call_extern_c_func() {
extern_c_func();
}
+
+int main() {
+}
+// CHECK-DAG: @main
+// X64-DAG: @main
+
+int wmain() {
+}
+// CHECK-DAG: @wmain
+// X64-DAG: @wmain
+
+int WinMain() {
+}
+// CHECK-DAG: @WinMain
+// X64-DAG: @WinMain
+
+int wWinMain() {
+}
+// CHECK-DAG: @wWinMain
+// X64-DAG: @wWinMain
+
+int DllMain() {
+}
+// CHECK-DAG: @DllMain
+// X64-DAG: @DllMain
Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -24,6 +24,7 @@
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringSwitch.h"
using namespace clang;
@@ -70,6 +71,22 @@
return fn;
}
+// Microsoft Visual C++ will never mangle some "standard" entry points
+// regardless of visibility or freestanding-ness.
+static bool isUserDefinedEntryPoint(const FunctionDecl *FD) {
+ if (!FD->getIdentifier())
+ return false;
+
+ return llvm::StringSwitch<bool>(FD->getName())
+ .Cases("main", // An ANSI console app
+ "wmain", // A Unicode console App
+ "WinMain", // An ANSI GUI app
+ "wWinMain", // A Unicode GUI app
+ "DllMain", // A DLL
+ true)
+ .Default(false);
+}
+
/// MicrosoftCXXNameMangler - Manage the mangling of a single name for the
/// Microsoft Visual C++ ABI.
class MicrosoftCXXNameMangler {
@@ -230,8 +247,7 @@
if (FD->hasAttr<OverloadableAttr>())
return true;
- // "main" is not mangled.
- if (FD->isMain())
+ if (isUserDefinedEntryPoint(FD))
return false;
// C++ functions and those whose names are not a simple identifier need
Index: test/CodeGenCXX/mangle-ms.cpp
===================================================================
--- test/CodeGenCXX/mangle-ms.cpp
+++ test/CodeGenCXX/mangle-ms.cpp
@@ -255,3 +255,28 @@
void call_extern_c_func() {
extern_c_func();
}
+
+int main() {
+}
+// CHECK-DAG: @main
+// X64-DAG: @main
+
+int wmain() {
+}
+// CHECK-DAG: @wmain
+// X64-DAG: @wmain
+
+int WinMain() {
+}
+// CHECK-DAG: @WinMain
+// X64-DAG: @WinMain
+
+int wWinMain() {
+}
+// CHECK-DAG: @wWinMain
+// X64-DAG: @wWinMain
+
+int DllMain() {
+}
+// CHECK-DAG: @DllMain
+// X64-DAG: @DllMain
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits