This patch fixes http://llvm.org/bugs/show_bug.cgi?id=5966 by making the same changes to clang made to fix http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31775

Sean Hunt
Index: test/CodeGenCXX/mangle.cpp
===================================================================
--- test/CodeGenCXX/mangle.cpp	(revision 92903)
+++ test/CodeGenCXX/mangle.cpp	(working copy)
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks | FileCheck %s
-
 struct X { };
 struct Y { };
 
@@ -308,4 +307,4 @@
 }
 
 // CHECK: define void @_Z1fU13block_pointerFiiiE
-void f(int (^)(int, int)) { }
\ No newline at end of file
+void f(int (^)(int, int)) { }
Index: test/CodeGenCXX/global-llvm-constant.cpp
===================================================================
--- test/CodeGenCXX/global-llvm-constant.cpp	(revision 92903)
+++ test/CodeGenCXX/global-llvm-constant.cpp	(working copy)
@@ -7,4 +7,4 @@
 
 const A x;
 
-// CHECK: @x = internal global
+// CHECK: @_ZL1x = internal global
Index: test/CodeGenCXX/const-global-linkage.cpp
===================================================================
--- test/CodeGenCXX/const-global-linkage.cpp	(revision 92903)
+++ test/CodeGenCXX/const-global-linkage.cpp	(working copy)
@@ -3,11 +3,11 @@
 const int x = 10;
 const int y = 20;
 // CHECK-NOT: @x
-// CHECK: @y = internal constant i32 20
+// CHECK: @_ZL1y = internal constant i32 20
 const int& b() { return y; }
 
 const char z1[] = "asdf";
 const char z2[] = "zxcv";
 // CHECK-NOT: @z1
-// CHECK: @z2 = internal constant
+// CHECK: @_ZL2z2 = internal constant
 const char* b2() { return z2; }
Index: test/CodeGenCXX/PR5966-static-mangle.cpp
===================================================================
--- test/CodeGenCXX/PR5966-static-mangle.cpp	(revision 0)
+++ test/CodeGenCXX/PR5966-static-mangle.cpp	(revision 0)
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+//CHECK: @i = external global
+//CHECK: @_ZL1i = internal global
+
+void foo() {
+  extern int i;
+  i = 0;
+}
+
+static int i;
+
+void bar() {
+  i = 0;
+}
\ No newline at end of file
Index: lib/CodeGen/Mangle.cpp
===================================================================
--- lib/CodeGen/Mangle.cpp	(revision 92903)
+++ lib/CodeGen/Mangle.cpp	(working copy)
@@ -171,14 +171,15 @@
       isInExternCSystemHeader(D->getLocation()))
     return false;
 
-  // Variables at global scope are not mangled.
+  // Variables at global scope with non-internal linkage are not mangled
   if (!FD) {
     const DeclContext *DC = D->getDeclContext();
     // Check for extern variable declared locally.
     if (isa<FunctionDecl>(DC) && D->hasLinkage())
       while (!DC->isNamespace() && !DC->isTranslationUnit())
         DC = DC->getParent();
-    if (DC->isTranslationUnit())
+    if (DC->isTranslationUnit() &&
+        D->getLinkage() != NamedDecl::InternalLinkage)
       return false;
   }
 
@@ -416,6 +417,13 @@
     }
 
     if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) {
+      // We must avoid conflicts between internally- and externally-
+      // linked names in the same TU. This naming convention is the
+      // same as that followed by GCC, though it shouldn't actually matter.
+      if (ND->getLinkage() == NamedDecl::InternalLinkage &&
+          ND->getDeclContext()->isFileContext())
+        Out << "L";
+
       mangleSourceName(II);
       break;
     }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to