From ff5d94339ae995223526863d0f2cd21e1828d2f3 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 29 Apr 2014 06:18:53 +0000 Subject: [PATCH] CodeGen: Reference temporaries inherit visibility 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 | 3 +++ test/CodeGenCXX/const-init-cxx11.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index bed949db22..6103933300 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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()) diff --git a/test/CodeGenCXX/const-init-cxx11.cpp b/test/CodeGenCXX/const-init-cxx11.cpp index 26ad9cb767..891a732de0 100644 --- a/test/CodeGenCXX/const-init-cxx11.cpp +++ b/test/CodeGenCXX/const-init-cxx11.cpp @@ -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::a = 5; const int &use = S::a; } + +namespace ClassTemplateWithHiddenStaticDataMember { + template + struct S { + __attribute__((visibility("hidden"))) static const int &a; + }; + template + const int &S::a = 5; + const int &use = S::a; +} -- 2.40.0