]> granicus.if.org Git - clang/commitdiff
CodeGen: Reference temporaries inherit visibility
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 29 Apr 2014 06:18:53 +0000 (06:18 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 29 Apr 2014 06:18:53 +0000 (06:18 +0000)
Reference temporaries inherited many properties from the variable that
they correspond to but visibility wasn't one of them.

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

lib/CodeGen/CodeGenModule.cpp
test/CodeGenCXX/const-init-cxx11.cpp

index bed949db22038bd974f9f1241948b0c383111525..610393330085430c5e80063359a014ef11f8c2c4 100644 (file)
@@ -2865,6 +2865,8 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalTemporary(
   // 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::GetAddrOfGlobalTemporary(
       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())
index 26ad9cb767687766eddcfec2c6c9873a61ba0340..891a732de0329bc2ac69a7ee6a9753d27591e258 100644 (file)
@@ -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,
@@ -574,3 +576,13 @@ namespace ClassTemplateWithStaticDataMember {
   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;
+}