Author: majnemer Date: Fri Sep 13 04:40:55 2013 New Revision: 190675 URL: http://llvm.org/viewvc/llvm-project?rev=190675&view=rev Log: [-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 Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp cfe/trunk/test/CodeGenCXX/mangle-ms.cpp Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=190675&r1=190674&r2=190675&view=diff ============================================================================== --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original) +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Sep 13 04:40:55 2013 @@ -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(c 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::shouldMangl 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 Modified: cfe/trunk/test/CodeGenCXX/mangle-ms.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms.cpp?rev=190675&r1=190674&r2=190675&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/mangle-ms.cpp (original) +++ cfe/trunk/test/CodeGenCXX/mangle-ms.cpp Fri Sep 13 04:40:55 2013 @@ -255,3 +255,23 @@ extern "C" inline void extern_c_func() { void call_extern_c_func() { extern_c_func(); } + +int main() { return 0; } +// CHECK-DAG: @main +// X64-DAG: @main + +int wmain() { return 0; } +// CHECK-DAG: @wmain +// X64-DAG: @wmain + +int WinMain() { return 0; } +// CHECK-DAG: @WinMain +// X64-DAG: @WinMain + +int wWinMain() { return 0; } +// CHECK-DAG: @wWinMain +// X64-DAG: @wWinMain + +int DllMain() { return 0; } +// CHECK-DAG: @DllMain +// X64-DAG: @DllMain _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
