r207496 - CodeGen: Reference temporaries inherit visibility

David Majnemer david.majnemer at gmail.com
Mon Apr 28 23:18:53 PDT 2014


Author: majnemer
Date: Tue Apr 29 01:18:53 2014
New Revision: 207496

URL: http://llvm.org/viewvc/llvm-project?rev=207496&view=rev
Log:
CodeGen: Reference temporaries inherit visibility

Reference temporaries inherited many properties from the variable that
they correspond to but visibility wasn't one of them.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=207496&r1=207495&r2=207496&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr 29 01:18:53 2014
@@ -2865,6 +2865,8 @@ llvm::Constant *CodeGenModule::GetAddrOf
   // Create a global variable for this lifetime-extended temporary.
   llvm::GlobalValue::LinkageTypes Linkage =
       getLLVMLinkageVarDefinition(VD, Constant);
+  // There is no need for this temporary to have global linkage if the global
+  // variable has external linkage.
   if (Linkage == llvm::GlobalVariable::ExternalLinkage)
     Linkage = llvm::GlobalVariable::PrivateLinkage;
   unsigned AddrSpace = GetGlobalVarAddressSpace(
@@ -2873,6 +2875,7 @@ llvm::Constant *CodeGenModule::GetAddrOf
       getModule(), Type, Constant, Linkage, InitialValue, Name.c_str(),
       /*InsertBefore=*/nullptr, llvm::GlobalVariable::NotThreadLocal,
       AddrSpace);
+  setGlobalVisibility(GV, VD);
   GV->setAlignment(
       getContext().getTypeAlignInChars(MaterializedType).getQuantity());
   if (VD->getTLSKind())

Modified: cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp?rev=207496&r1=207495&r2=207496&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/const-init-cxx11.cpp Tue Apr 29 01:18:53 2014
@@ -395,6 +395,8 @@ namespace UnemittedTemporaryDecl {
 // CHECK: @_ZZN12LocalVarInit8mutable_EvE1a = private unnamed_addr constant {{.*}} i32 103
 // CHECK: @_ZGRN33ClassTemplateWithStaticDataMember1SIvE1aE = linkonce_odr constant i32 5
 // CHECK: @_ZN33ClassTemplateWithStaticDataMember3useE = constant i32* @_ZGRN33ClassTemplateWithStaticDataMember1SIvE1aE
+// CHECK: @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE = linkonce_odr hidden constant i32 5
+// CHECK: @_ZN39ClassTemplateWithHiddenStaticDataMember3useE = constant i32* @_ZGRN39ClassTemplateWithHiddenStaticDataMember1SIvE1aE
 // CHECK: @_ZGRZN20InlineStaticConstRef3funEvE1i = linkonce_odr constant i32 10
 
 // Constant initialization tests go before this point,
@@ -572,5 +574,15 @@ namespace ClassTemplateWithStaticDataMem
   };
   template <typename T>
   const int &S<T>::a = 5;
+  const int &use = S<void>::a;
+}
+
+namespace ClassTemplateWithHiddenStaticDataMember {
+  template <typename T>
+  struct S {
+    __attribute__((visibility("hidden"))) static const int &a;
+  };
+  template <typename T>
+  const int &S<T>::a = 5;
   const int &use = S<void>::a;
 }





More information about the cfe-commits mailing list