From: David Majnemer Date: Mon, 5 May 2014 18:54:23 +0000 (+0000) Subject: CodeGen: Assign linkage to thread-wrappers correctly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9cf72f94dab05055ac4b83c347a006ead632b82;p=clang CodeGen: Assign linkage to thread-wrappers correctly We would sometimes incorrectly give a thread-wrapper external linkage instead of internal linkage if we had only CodeGen'd it's declaration, not it's definition. This fixes PR19655. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207988 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index 4b1c1c255a..d11d1728af 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -1582,8 +1582,9 @@ ItaniumCXXABI::getOrCreateThreadLocalWrapper(const VarDecl *VD, llvm::FunctionType *FnTy = llvm::FunctionType::get(RetTy, false); llvm::Function *Wrapper = llvm::Function::Create( - FnTy, getThreadLocalWrapperLinkage(Var->getLinkage()), WrapperName.str(), - &CGM.getModule()); + FnTy, getThreadLocalWrapperLinkage( + CGM.getLLVMLinkageVarDefinition(VD, /*isConstant=*/false)), + WrapperName.str(), &CGM.getModule()); // Always resolve references to the wrapper at link time. Wrapper->setVisibility(llvm::GlobalValue::HiddenVisibility); return Wrapper; diff --git a/test/CodeGenCXX/cxx11-thread-local.cpp b/test/CodeGenCXX/cxx11-thread-local.cpp index b91f46d5d4..5843a343b8 100644 --- a/test/CodeGenCXX/cxx11-thread-local.cpp +++ b/test/CodeGenCXX/cxx11-thread-local.cpp @@ -145,6 +145,14 @@ int PR19254::f() { return this->n; } +namespace { +thread_local int anon_i{1}; +} +void set_anon_i() { + anon_i = 2; +} +// CHECK-LABEL: define internal hidden i32* @_ZTWN12_GLOBAL__N_16anon_iE() + // CHECK: define {{.*}} @[[V_M_INIT:.*]]() // CHECK: load i8* bitcast (i64* @_ZGVN1VIiE1mE to i8*) // CHECK: %[[V_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0