From 43f1740b7eeef0f39479474f199ec7cfa290b57e Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Thu, 2 Apr 2009 15:51:53 +0000 Subject: [PATCH] Move the function decl mangling code out into its own function. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68319 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/Mangle.cpp | 68 ++++++++++++++++++++++-------------------- 1 file 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()) { - // 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(DC)) + return Linkage->getLanguage() == LinkageSpecDecl::lang_c; } - // ::= _Z - // ::= - // ::= + return false; +} - // FIXME: Actually use a visitor to decode these? - const FunctionDecl *FD = dyn_cast(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()) { @@ -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(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()) { + // 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; + } + + // ::= _Z + // ::= + // ::= + + // FIXME: Actually use a visitor to decode these? + if (const FunctionDecl *FD = dyn_cast(D)) + return mangleFunctionDecl(FD); + + return false; +} + void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { // ::= mangleName(FD); -- 2.40.0