[cfe-commits] r68319 - /cfe/trunk/lib/CodeGen/Mangle.cpp

Anders Carlsson andersca at mac.com
Thu Apr 2 08:51:57 PDT 2009


Author: andersca
Date: Thu Apr  2 10:51:53 2009
New Revision: 68319

URL: http://llvm.org/viewvc/llvm-project?rev=68319&view=rev
Log:
Move the function decl mangling code out into its own function. No functionality change.

Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=68319&r1=68318&r2=68319&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Thu Apr  2 10:51:53 2009
@@ -34,6 +34,10 @@
       : 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 @@
   };
 }
 
-
-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 @@
              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 @@
   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);





More information about the cfe-commits mailing list