[cfe-commits] r94352 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenCXX/const-global-linkage.cpp test/CodeGenCXX/deferred-global-init.cpp test/CodeGenCXX/global-llvm-constant.cpp test/CodeGenCXX/mangle.cpp

Sean Hunt rideau3 at gmail.com
Sat Jan 23 19:04:27 PST 2010


Author: coppro
Date: Sat Jan 23 21:04:27 2010
New Revision: 94352

URL: http://llvm.org/viewvc/llvm-project?rev=94352&view=rev
Log:
Mangle static variables with an extra name to distinguish them from non-static variables in the same TU.
Fixes PR5966 for real this time; also reverts r92911, which had a incorrect fix.

Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp
    cfe/trunk/test/CodeGenCXX/const-global-linkage.cpp
    cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp
    cfe/trunk/test/CodeGenCXX/global-llvm-constant.cpp
    cfe/trunk/test/CodeGenCXX/mangle.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sat Jan 23 21:04:27 2010
@@ -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;
   }
 
@@ -199,13 +200,10 @@
     return;
   }
 
-  // <mangled-name> ::= _Z [L] <encoding>
+  // <mangled-name> ::= _Z <encoding>
   //            ::= <data name>
   //            ::= <special-name>
   Out << Prefix;
-  if (D->getLinkage() == NamedDecl::InternalLinkage) // match gcc behavior
-    Out << 'L';
-
   if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
     mangleFunctionEncoding(FD);
   else
@@ -419,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;
     }

Modified: cfe/trunk/test/CodeGenCXX/const-global-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-global-linkage.cpp?rev=94352&r1=94351&r2=94352&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/const-global-linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/const-global-linkage.cpp Sat Jan 23 21:04:27 2010
@@ -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; }

Modified: cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp?rev=94352&r1=94351&r2=94352&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/deferred-global-init.cpp Sat Jan 23 21:04:27 2010
@@ -5,7 +5,7 @@
 static void* const a = foo;
 void* bar() { return a; }
 
-// CHECK: @a = internal global i8* null
+// CHECK: @_ZL1a = internal global i8* null
 
 // CHECK: define internal void @__cxx_global_var_init
 // CHECK: load i8** @foo

Modified: cfe/trunk/test/CodeGenCXX/global-llvm-constant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/global-llvm-constant.cpp?rev=94352&r1=94351&r2=94352&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/global-llvm-constant.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/global-llvm-constant.cpp Sat Jan 23 21:04:27 2010
@@ -7,4 +7,4 @@
 
 const A x;
 
-// CHECK: @x = internal global
+// CHECK: @_ZL1x = internal global

Modified: cfe/trunk/test/CodeGenCXX/mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle.cpp?rev=94352&r1=94351&r2=94352&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Sat Jan 23 21:04:27 2010
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks | FileCheck %s
-
 struct X { };
 struct Y { };
 
@@ -9,6 +8,9 @@
 // CHECK: @_ZZN1N1gEvE1a = internal global
 // CHECK: @_ZGVZN1N1gEvE1a = internal global
 
+//CHECK: @pr5966_i = external global
+//CHECK: @_ZL8pr5966_i = internal global
+
 // CHECK: define zeroext i1 @_ZplRK1YRA100_P1X
 bool operator+(const Y&, X* (&xs)[100]) { return false; }
 
@@ -310,7 +312,13 @@
 // CHECK: define void @_Z1fU13block_pointerFiiiE
 void f(int (^)(int, int)) { }
 
-// PR5869
-// CHECK: define internal void @_ZL2f2v
-static void f2() {}
-void f3() { f2(); }
+void pr5966_foo() {
+  extern int pr5966_i;
+  pr5966_i = 0;
+}
+
+static int pr5966_i;
+
+void pr5966_bar() {
+  pr5966_i = 0;
+}





More information about the cfe-commits mailing list