[cfe-commits] r67442 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/CodeGen/Mangle.cpp lib/CodeGen/Mangle.h test/CodeGen/mangle.c

Chris Lattner sabre at nondot.org
Sat Mar 21 01:24:55 PDT 2009


Author: lattner
Date: Sat Mar 21 03:24:40 2009
New Revision: 67442

URL: http://llvm.org/viewvc/llvm-project?rev=67442&view=rev
Log:
fix several problems with asm renaming, by pulling it into the mangling code:

1. it wasn't applying to definitions, only declarations, e.g. int x __asm("foo")
2. multiple definitions were conflicting, they weren't getting merged.
3. the code was duplicated in several places.


Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/Mangle.cpp
    cfe/trunk/lib/CodeGen/Mangle.h
    cfe/trunk/test/CodeGen/mangle.c

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Sat Mar 21 03:24:40 2009
@@ -305,11 +305,6 @@
     setGlobalVisibility(GV, attr->getVisibility());
   // FIXME: else handle -fvisibility
 
-  // Prefaced with special LLVM marker to indicate that the name
-  // should not be munged.
-  if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>())
-    GV->setName("\01" + ALA->getLabel());
-
   if (const SectionAttr *SA = D->getAttr<SectionAttr>())
     GV->setSection(SA->getName());
 
@@ -629,12 +624,6 @@
   if (D->getAttr<WeakAttr>() || D->getAttr<WeakImportAttr>())
     GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
 
-  // FIXME: This should be handled by the mangler!
-  if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
-    // Prefaced with special LLVM marker to indicate that the name
-    // should not be munged.
-    GV->setName("\01" + ALA->getLabel());
-  }
   return Entry = GV;
 }
 
@@ -746,13 +735,6 @@
     setGlobalVisibility(GV, attr->getVisibility());
   // FIXME: else handle -fvisibility
 
-  // FIXME: This should be a mangling issue.
-  if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
-    // Prefaced with special LLVM marker to indicate that the name
-    // should not be munged.
-    GV->setName("\01" + ALA->getLabel());
-  }
-  
   // Set the llvm linkage type as appropriate.
   if (D->getStorageClass() == VarDecl::Static)
     GV->setLinkage(llvm::Function::InternalLinkage);

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

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sat Mar 21 03:24:40 2009
@@ -57,6 +57,15 @@
 
 
 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>
@@ -68,15 +77,15 @@
   
   // Clang's "overloadable" attribute extension to C/C++ implies
   // name mangling (always).
-  if (FD->getAttr<OverloadableAttr>())
+  if (FD->getAttr<OverloadableAttr>()) {
     ; // fall into mangling code unconditionally.
-  else if (// C functions are not mangled
-           !Context.getLangOptions().CPlusPlus ||
-           // "main" is not mangled in C++
-           FD->isMain() ||
-           // No mangling in an "implicit extern C" header.
-           Context.getSourceManager().getFileCharacteristic(FD->getLocation())
-                == SrcMgr::C_ExternCSystem)
+  } else if (// C functions are not mangled
+             !Context.getLangOptions().CPlusPlus ||
+             // "main" is not mangled in C++
+             FD->isMain() ||
+             // No mangling in an "implicit extern C" header.
+             Context.getSourceManager().getFileCharacteristic(FD->getLocation())
+               == SrcMgr::C_ExternCSystem)
     return false;
   else {
     // No name mangling in a C linkage specification.

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

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.h (original)
+++ cfe/trunk/lib/CodeGen/Mangle.h Sat Mar 21 03:24:40 2009
@@ -14,6 +14,7 @@
 //   http://www.codesourcery.com/public/cxx-abi/abi.html
 //
 //===----------------------------------------------------------------------===//
+
 #ifndef LLVM_CLANG_CODEGEN_MANGLE_H
 #define LLVM_CLANG_CODEGEN_MANGLE_H
 

Modified: cfe/trunk/test/CodeGen/mangle.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mangle.c?rev=67442&r1=67441&r2=67442&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/mangle.c (original)
+++ cfe/trunk/test/CodeGen/mangle.c Sat Mar 21 03:24:40 2009
@@ -1,9 +1,28 @@
 // RUN: clang -arch i386 -emit-llvm -o %t %s &&
 // RUN: grep '@_Z2f0i' %t &&
-// RUN: grep '@_Z2f0l' %t
+// RUN: grep '@_Z2f0l' %t &&
 
 // Make sure we mangle overloadable, even in C system headers.
 
 # 1 "somesystemheader.h" 1 3 4
 void __attribute__((__overloadable__)) f0(int a) {}
 void __attribute__((__overloadable__)) f0(long b) {}
+
+
+
+// These should get merged.
+void foo() __asm__("bar");
+void foo2() __asm__("bar");
+
+// RUN: grep '@"\\01foo"' %t &&
+// RUN: grep '@"\\01bar"' %t
+
+int nux __asm__("foo");
+extern float nux2 __asm__("foo");
+
+int test() { 
+  foo();
+  foo2();
+  
+  return nux + nux2;
+}





More information about the cfe-commits mailing list