[cfe-commits] r129342 - in /cfe/trunk: lib/CodeGen/CGDeclCXX.cpp lib/CodeGen/CodeGenModule.cpp test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp test/CodeGenCXX/explicit-instantiation.cpp test/CodeGenCXX/global-init.cpp test/CodeGenCXX/specialized-static-data-mem-init.cpp test/CodeGenCXX/static-data-member.cpp test/CodeGenCXX/static-init-3.cpp test/CodeGenCXX/template-inner-struct-visibility-hidden.cpp

John McCall rjmccall at apple.com
Mon Apr 11 18:46:55 PDT 2011


Author: rjmccall
Date: Mon Apr 11 20:46:54 2011
New Revision: 129342

URL: http://llvm.org/viewvc/llvm-project?rev=129342&view=rev
Log:
Template static data members can have weak_odr linkage, not just
weak linkage.  Also, fix a problem where global weak variables
with non-trivial initializers were getting guard variables, or at
least were checking for them and then crashing.


Modified:
    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp
    cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp
    cfe/trunk/test/CodeGenCXX/global-init.cpp
    cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp
    cfe/trunk/test/CodeGenCXX/static-data-member.cpp
    cfe/trunk/test/CodeGenCXX/static-init-3.cpp
    cfe/trunk/test/CodeGenCXX/template-inner-struct-visibility-hidden.cpp

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=129342&r1=129341&r2=129342&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Apr 11 20:46:54 2011
@@ -275,8 +275,11 @@
                 FunctionArgList(), SourceLocation());
 
   // Use guarded initialization if the global variable is weak due to
-  // being a class template's static data member.
-  if (Addr->hasWeakLinkage() && D->getInstantiatedFromStaticDataMember()) {
+  // being a class template's static data member.  These will always
+  // have weak_odr linkage.
+  if (Addr->getLinkage() == llvm::GlobalValue::WeakODRLinkage &&
+      D->isStaticDataMember() &&
+      D->getInstantiatedFromStaticDataMember()) {
     EmitCXXGuardedInit(*D, Addr);
   } else {
     EmitCXXGlobalVarDeclInit(*D, Addr);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=129342&r1=129341&r2=129342&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Apr 11 20:46:54 2011
@@ -1316,9 +1316,7 @@
       return llvm::GlobalVariable::WeakAnyLinkage;
   } else if (Linkage == GVA_TemplateInstantiation ||
              Linkage == GVA_ExplicitTemplateInstantiation)
-    // FIXME: It seems like we can provide more specific linkage here
-    // (LinkOnceODR, WeakODR).
-    return llvm::GlobalVariable::WeakAnyLinkage;
+    return llvm::GlobalVariable::WeakODRLinkage;
   else if (!getLangOptions().CPlusPlus && 
            ((!CodeGenOpts.NoCommon && !D->getAttr<NoCommonAttr>()) ||
              D->getAttr<CommonAttr>()) &&

Modified: cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp?rev=129342&r1=129341&r2=129342&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp Mon Apr 11 20:46:54 2011
@@ -12,16 +12,16 @@
 template<typename T>
 T X<T>::member2 = 17;
 
-// CHECK: @_ZN1XIiE7member1E = weak global i32 0
+// CHECK: @_ZN1XIiE7member1E = weak_odr global i32 0
 template int X<int>::member1;
 
-// CHECK: @_ZN1XIiE7member2E = weak global i32 17
+// CHECK: @_ZN1XIiE7member2E = weak_odr global i32 17
 template int X<int>::member2;
 
 // For implicit instantiation of 
 long& get(bool Cond1, bool Cond2) {
-  // CHECK: @_ZN1XIlE7member1E = weak global i64 0
-  // CHECK: @_ZN1XIlE7member2E = weak global i64 17
+  // CHECK: @_ZN1XIlE7member1E = weak_odr global i64 0
+  // CHECK: @_ZN1XIlE7member2E = weak_odr global i64 17
   // CHECK: @_ZN1XIlE7member3E = external global i64
   return Cond1? X<long>::member1 
        : Cond2? X<long>::member2

Modified: cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp?rev=129342&r1=129341&r2=129342&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/explicit-instantiation.cpp Mon Apr 11 20:46:54 2011
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -emit-llvm -triple i686-pc-linux-gnu -o - %s | FileCheck %s
 
 // This check logically is attached to 'template int S<int>::i;' below.
-// CHECK: @_ZN1SIiE1iE = weak global i32
+// CHECK: @_ZN1SIiE1iE = weak_odr global i32
 
 template<typename T, typename U, typename Result>
 struct plus {

Modified: cfe/trunk/test/CodeGenCXX/global-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/global-init.cpp?rev=129342&r1=129341&r2=129342&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/global-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/global-init.cpp Mon Apr 11 20:46:54 2011
@@ -97,6 +97,16 @@
   };
 }
 
+namespace test6 {
+  struct A {
+    A();
+  };
+  extern int foo();
+
+  // This needs an initialization function but not guard variables.
+  __attribute__((weak)) int x = foo();
+}
+
 // At the end of the file, we check that y is initialized before z.
 
 // CHECK: define internal void @_GLOBAL__I_a() section "__TEXT,__StaticInit,regular,pure_instructions" {

Modified: cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp?rev=129342&r1=129341&r2=129342&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/specialized-static-data-mem-init.cpp Mon Apr 11 20:46:54 2011
@@ -2,8 +2,8 @@
 // rdar: // 8562966
 // pr8409
 
-// CHECK: @_ZN1CIiE11needs_guardE = weak global
-// CHECK: @_ZGVN1CIiE11needs_guardE = weak global
+// CHECK: @_ZN1CIiE11needs_guardE = weak_odr global
+// CHECK: @_ZGVN1CIiE11needs_guardE = weak_odr global
 
 struct K
 {

Modified: cfe/trunk/test/CodeGenCXX/static-data-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/static-data-member.cpp?rev=129342&r1=129341&r2=129342&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/static-data-member.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/static-data-member.cpp Mon Apr 11 20:46:54 2011
@@ -2,8 +2,8 @@
 
 // CHECK: @_ZN5test11A1aE = constant i32 10, align 4
 // CHECK: @_ZN5test212_GLOBAL__N_11AIiE1xE = internal global i32 0, align 4
-// CHECK: @_ZN5test31AIiE1xE = weak global i32 0, align 4
-// CHECK: @_ZGVN5test31AIiE1xE = weak global i64 0
+// CHECK: @_ZN5test31AIiE1xE = weak_odr global i32 0, align 4
+// CHECK: @_ZGVN5test31AIiE1xE = weak_odr global i64 0
 
 // PR5564.
 namespace test1 {

Modified: cfe/trunk/test/CodeGenCXX/static-init-3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/static-init-3.cpp?rev=129342&r1=129341&r2=129342&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/static-init-3.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/static-init-3.cpp Mon Apr 11 20:46:54 2011
@@ -16,8 +16,8 @@
     }
 };
 
-// CHECK: @_ZN2X1I2X2I1BEE8instanceE = weak global %struct.X0* null, align 8
-// CHECJ: @_ZN2X1I2X2I1AEE8instanceE = weak global %struct.X0* null, align 8
+// CHECK: @_ZN2X1I2X2I1BEE8instanceE = weak_odr global %struct.X0* null, align 8
+// CHECJ: @_ZN2X1I2X2I1AEE8instanceE = weak_odr global %struct.X0* null, align 8
 template<class T> T & X1<T>::instance = X1<T>::get();
 
 class A { };

Modified: cfe/trunk/test/CodeGenCXX/template-inner-struct-visibility-hidden.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/template-inner-struct-visibility-hidden.cpp?rev=129342&r1=129341&r2=129342&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/template-inner-struct-visibility-hidden.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/template-inner-struct-visibility-hidden.cpp Mon Apr 11 20:46:54 2011
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fvisibility hidden -emit-llvm -o - %s | FileCheck %s
 
 // Verify that symbols are hidden.
-// CHECK: @_ZN1CIiE5Inner6Inner26StaticE = weak hidden global
+// CHECK: @_ZN1CIiE5Inner6Inner26StaticE = weak_odr hidden global
 // CHECK: define weak_odr hidden void @_ZN1CIiE5Inner1fEv
 // CHECK: define weak_odr hidden void @_ZN1CIiE5Inner6Inner21gEv
 





More information about the cfe-commits mailing list