]> granicus.if.org Git - clang/commitdiff
CodeGen: Assign linkage to thread-wrappers correctly
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 5 May 2014 18:54:23 +0000 (18:54 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 5 May 2014 18:54:23 +0000 (18:54 +0000)
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

lib/CodeGen/ItaniumCXXABI.cpp
test/CodeGenCXX/cxx11-thread-local.cpp

index 4b1c1c255af0e51bab46284cb4fb8b1f7bacee99..d11d1728afec8424feb71b157b4482104d24c517 100644 (file)
@@ -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;
index b91f46d5d49e7c3fce79c6cfcdcbfd9936de8e2d..5843a343b8644d3034c41a61cc475182512d1db8 100644 (file)
@@ -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