xref: /llvm-project/clang/test/CodeGenCXX/cxx11-thread-local-instantiated.cpp (revision b6965f7246bba1b399755f56d8ae34893e815198)
1cd4d6d71SRichard Smith // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
2cd4d6d71SRichard Smith 
3cd4d6d71SRichard Smith // PR48030
4cd4d6d71SRichard Smith 
5cd4d6d71SRichard Smith template<typename T> struct TLS { static thread_local T *mData; };
non_constant_initializer()6cd4d6d71SRichard Smith inline decltype(nullptr) non_constant_initializer() { return nullptr; }
7cd4d6d71SRichard Smith template<typename T> thread_local T *TLS<T>::mData = non_constant_initializer();
8cd4d6d71SRichard Smith struct S {};
current()9cd4d6d71SRichard Smith S *current() { return TLS<S>::mData; };
10cd4d6d71SRichard Smith 
11cd4d6d71SRichard Smith // CHECK-DAG: @_ZN3TLSI1SE5mDataE = linkonce_odr thread_local global {{.*}}, comdat,
12cd4d6d71SRichard Smith // CHECK-DAG: @_ZGVN3TLSI1SE5mDataE = linkonce_odr thread_local global {{.*}}, comdat($_ZN3TLSI1SE5mDataE),
13cd4d6d71SRichard Smith // CHECK-DAG: @_ZTHN3TLSI1SE5mDataE = linkonce_odr alias {{.*}} @__cxx_global_var_init
14cd4d6d71SRichard Smith 
15cd4d6d71SRichard Smith // CHECK-LABEL: define {{.*}} @_Z7currentv()
16cd4d6d71SRichard Smith // CHECK: call {{.*}} @_ZTWN3TLSI1SE5mDataE()
17cd4d6d71SRichard Smith 
18cd4d6d71SRichard Smith // CHECK-LABEL: define weak_odr hidden {{.*}} @_ZTWN3TLSI1SE5mDataE() {{.*}} comdat {
19cd4d6d71SRichard Smith // CHECK: call void @_ZTHN3TLSI1SE5mDataE()
20*b6965f72SAlexander Shaposhnikov // CHECK: [[TLSmData_ADDR:%[^ ]+]] = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_ZN3TLSI1SE5mDataE)
21bacdf80fSChuanqi Xu // CHECK: ret {{.*}} [[TLSmData_ADDR]]
22cd4d6d71SRichard Smith 
23cd4d6d71SRichard Smith // Unlike for a global, the global initialization function must not be in a
24cd4d6d71SRichard Smith // COMDAT with the variable, because it is referenced from the _ZTH function
25cd4d6d71SRichard Smith // which is outside that COMDAT.
26cd4d6d71SRichard Smith //
27cd4d6d71SRichard Smith // CHECK-NOT: define {{.*}} @__cxx_global_var_init{{.*}}comdat
28