diff options
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/Mangle.cpp | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index cd97b5d916..1c84f28d5b 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -34,6 +34,10 @@ namespace { : Context(C), Out(os) { } bool mangle(const NamedDecl *D); + + private: + bool mangleFunctionDecl(const FunctionDecl *FD); + void mangleFunctionEncoding(const FunctionDecl *FD); void mangleName(const NamedDecl *ND); void mangleUnqualifiedName(const NamedDecl *ND); @@ -55,26 +59,17 @@ namespace { }; } - -bool CXXNameMangler::mangle(const NamedDecl *D) { - // Any decl can be declared with __asm("foo") on it, and this takes - // precedence over all other naming in the .o file. - if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) { - // If we have an asm name, then we use it as the mangling. - Out << '\01'; // LLVM IR Marker for __asm("foo") - Out << ALA->getLabel(); - return true; +static bool isInCLinkageSpecification(const Decl *D) { + 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; } - // <mangled-name> ::= _Z <encoding> - // ::= <data name> - // ::= <special-name> + return false; +} - // FIXME: Actually use a visitor to decode these? - const FunctionDecl *FD = dyn_cast<FunctionDecl>(D); - if (!FD) // Can only mangle functions so far. - return false; - +bool CXXNameMangler::mangleFunctionDecl(const FunctionDecl *FD) { // Clang's "overloadable" attribute extension to C/C++ implies // name mangling (always). if (FD->getAttr<OverloadableAttr>()) { @@ -85,22 +80,10 @@ bool CXXNameMangler::mangle(const NamedDecl *D) { FD->isMain() || // No mangling in an "implicit extern C" header. Context.getSourceManager().getFileCharacteristic(FD->getLocation()) - == SrcMgr::C_ExternCSystem) + == SrcMgr::C_ExternCSystem || + // No name mangling in a C linkage specification. + isInCLinkageSpecification(FD)) return false; - else { - // No name mangling in a C linkage specification. - - for (const DeclContext *DC = FD->getDeclContext(); - !DC->isTranslationUnit(); DC = DC->getParent()) { - if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { - // extern "C" functions don't use name mangling. - if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) - return false; - // Others do. - break; - } - } - } // If we get here, mangle the decl name! Out << "_Z"; @@ -108,6 +91,27 @@ bool CXXNameMangler::mangle(const NamedDecl *D) { return true; } +bool CXXNameMangler::mangle(const NamedDecl *D) { + // Any decl can be declared with __asm("foo") on it, and this takes + // precedence over all other naming in the .o file. + if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) { + // If we have an asm name, then we use it as the mangling. + Out << '\01'; // LLVM IR Marker for __asm("foo") + Out << ALA->getLabel(); + return true; + } + + // <mangled-name> ::= _Z <encoding> + // ::= <data name> + // ::= <special-name> + + // FIXME: Actually use a visitor to decode these? + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) + return mangleFunctionDecl(FD); + + return false; +} + void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { // <encoding> ::= <function name> <bare-function-type> mangleName(FD); |