]> granicus.if.org Git - clang/commitdiff
fix several problems with asm renaming, by pulling it into the mangling code:
authorChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 08:24:40 +0000 (08:24 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 08:24:40 +0000 (08:24 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67442 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/Mangle.cpp
lib/CodeGen/Mangle.h
test/CodeGen/mangle.c

index c46db96bad64a8fba89f50bac3eb54d67184bfc5..97f989dbe381767e123a80e962815a9001b5e20b 100644 (file)
@@ -305,11 +305,6 @@ void CodeGenModule::SetGlobalValueAttributes(const Decl *D,
     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 @@ void CodeGenModule::EmitGlobalDefinition(const ValueDecl *D) {
   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 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
     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);
index e760b83fe6b91bdc3c469ec2af955038d2aa6b67..7a7a480bdb079b40287b74ffe86f5d5d3f248a90 100644 (file)
@@ -57,6 +57,15 @@ 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;
+  }
+  
   // <mangled-name> ::= _Z <encoding>
   //            ::= <data name>
   //            ::= <special-name>
@@ -68,15 +77,15 @@ bool CXXNameMangler::mangle(const NamedDecl *D) {
   
   // 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.
index 60a5113ccc9290249ea21f6417fdd2741fb13490..627c16a08ef1167a3e5926a873c5855137d09e7e 100644 (file)
@@ -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
 
index fbee4122d12173867f2c6378fa77881ceb8efb08..cdcce751cbdc8da40ec8762511069f91dd6849e0 100644 (file)
@@ -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;
+}