[cfe-commits] r105809 - in /cfe/trunk: lib/CodeGen/Mangle.h lib/CodeGen/MicrosoftCXXABI.cpp test/CodeGenCXX/mangle-ms.cpp
Charles Davis
cdavis at mines.edu
Thu Jun 10 21:25:47 PDT 2010
Author: cdavis
Date: Thu Jun 10 23:25:47 2010
New Revision: 105809
URL: http://llvm.org/viewvc/llvm-project?rev=105809&view=rev
Log:
When mangling for the Microsoft C++ ABI, mangle variables in the global
namespace, too.
Modified:
cfe/trunk/lib/CodeGen/Mangle.h
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
Modified: cfe/trunk/lib/CodeGen/Mangle.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.h?rev=105809&r1=105808&r2=105809&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.h (original)
+++ cfe/trunk/lib/CodeGen/Mangle.h Thu Jun 10 23:25:47 2010
@@ -110,7 +110,7 @@
/// @name Mangler Entry Points
/// @{
- bool shouldMangleDeclName(const NamedDecl *D);
+ virtual bool shouldMangleDeclName(const NamedDecl *D);
virtual void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &);
virtual void mangleThunk(const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=105809&r1=105808&r2=105809&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Thu Jun 10 23:25:47 2010
@@ -64,6 +64,7 @@
public:
MicrosoftMangleContext(ASTContext &Context,
Diagnostic &Diags) : MangleContext(Context, Diags) { }
+ virtual bool shouldMangleDeclName(const NamedDecl *D);
virtual void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &);
virtual void mangleThunk(const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
@@ -101,6 +102,46 @@
}
+static bool isInCLinkageSpecification(const Decl *D) {
+ D = D->getCanonicalDecl();
+ for (const DeclContext *DC = D->getDeclContext();
+ !DC->isTranslationUnit(); DC = DC->getParent()) {
+ if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC))
+ return Linkage->getLanguage() == LinkageSpecDecl::lang_c;
+ }
+
+ return false;
+}
+
+bool MicrosoftMangleContext::shouldMangleDeclName(const NamedDecl *D) {
+ // In C, functions with no attributes never need to be mangled. Fastpath them.
+ if (!getASTContext().getLangOptions().CPlusPlus && !D->hasAttrs())
+ return false;
+
+ // Any decl can be declared with __asm("foo") on it, and this takes precedence
+ // over all other naming in the .o file.
+ if (D->hasAttr<AsmLabelAttr>())
+ return true;
+
+ // Clang's "overloadable" attribute extension to C/C++ implies name mangling
+ // (always) as does passing a C++ member function and a function
+ // whose name is not a simple identifier.
+ const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
+ if (FD && (FD->hasAttr<OverloadableAttr>() || isa<CXXMethodDecl>(FD) ||
+ !FD->getDeclName().isIdentifier()))
+ return true;
+
+ // Otherwise, no mangling is done outside C++ mode.
+ if (!getASTContext().getLangOptions().CPlusPlus)
+ return false;
+
+ // C functions and "main" are not mangled.
+ if ((FD && FD->isMain()) || isInCLinkageSpecification(D))
+ return false;
+
+ return true;
+}
+
void MicrosoftCXXNameMangler::mangle(const NamedDecl *D,
llvm::StringRef Prefix) {
// MSVC doesn't mangle C++ names the same way it mangles extern "C" names.
Modified: cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms.cpp?rev=105809&r1=105808&r2=105809&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms.cpp Thu Jun 10 23:25:47 2010
@@ -1,6 +1,7 @@
// RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-apple-darwin10 | FileCheck %s
-//int a; // FIXME: All names not in an extern "C" block are mangled
+int a;
+// CHECK: @"\01?a@@"
namespace N { int b; }
// CHECK: @"\01?b at N@@"
More information about the cfe-commits
mailing list