diff options
author | Charles Davis <cdavis@mines.edu> | 2010-06-11 04:25:47 +0000 |
---|---|---|
committer | Charles Davis <cdavis@mines.edu> | 2010-06-11 04:25:47 +0000 |
commit | 971154db24429b103280d15423b8c200cfb2380c (patch) | |
tree | 609f1c6e420b25b6aed74f798c58ce48dce70090 /lib/CodeGen | |
parent | 876e994957472eda4b40136d4e1d6e08e2be338f (diff) |
When mangling for the Microsoft C++ ABI, mangle variables in the global
namespace, too.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105809 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/Mangle.h | 2 | ||||
-rw-r--r-- | lib/CodeGen/MicrosoftCXXABI.cpp | 41 |
2 files changed, 42 insertions, 1 deletions
diff --git a/lib/CodeGen/Mangle.h b/lib/CodeGen/Mangle.h index a12a140f72..d10334dcbb 100644 --- a/lib/CodeGen/Mangle.h +++ b/lib/CodeGen/Mangle.h @@ -110,7 +110,7 @@ public: /// @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, diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp index 948a66f665..012ef23c1c 100644 --- a/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/lib/CodeGen/MicrosoftCXXABI.cpp @@ -64,6 +64,7 @@ class MicrosoftMangleContext : public MangleContext { 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 @@ public: } +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. |