summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2013-09-13 09:40:55 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2013-09-13 09:40:55 +0000
commit9d0bb9d2ba0b5b0a66cb3188b1880e23049d95c6 (patch)
treecac6edeaef9239507acfe47b024710c686f58ce5 /clang/lib/AST
parent015ed028cf6922059f3da337a7fbfeb874a51051 (diff)
downloadbcm5719-llvm-9d0bb9d2ba0b5b0a66cb3188b1880e23049d95c6.tar.gz
bcm5719-llvm-9d0bb9d2ba0b5b0a66cb3188b1880e23049d95c6.zip
[-cxx-abi microsoft] Mangle user defined entry points properly
Summary: Functions named "main", "wmain", "WinMain", "wWinMain", and "DllMain" are never mangled regardless of linkage, even when compiling for kernel mode. Depends on D1655 Reviewers: timurrrr, pcc, rnk, whunt CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1670 llvm-svn: 190675
Diffstat (limited to 'clang/lib/AST')
-rw-r--r--clang/lib/AST/MicrosoftMangle.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index e082759cb92..9cea06187e2 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/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,29 @@ static const FunctionDecl *getStructor(const FunctionDecl *fn) {
return fn;
}
+// The 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.
+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 +254,7 @@ bool MicrosoftMangleContext::shouldMangleDeclName(const NamedDecl *D) {
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
OpenPOWER on IntegriCloud