2020-02-04 02:09:39 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
|
|
|
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
|
|
|
|
// RUN: %clang_cc1 -std=c++11 -femulated-tls -emit-llvm %s -o - \
|
2015-11-12 06:42:31 +08:00
|
|
|
// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
|
|
|
|
// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
|
2013-04-15 07:01:42 +08:00
|
|
|
|
2020-02-04 02:09:39 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
|
|
|
|
// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
|
|
|
|
// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s -o - \
|
2019-06-14 02:20:19 +08:00
|
|
|
// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
|
|
|
|
// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
|
|
|
|
|
2013-04-20 00:42:07 +08:00
|
|
|
int f();
|
2013-04-15 07:01:42 +08:00
|
|
|
int g();
|
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX-DAG: @a = thread_local global i32 0
|
|
|
|
// DARWIN-DAG: @a = internal thread_local global i32 0
|
2013-04-20 00:42:07 +08:00
|
|
|
thread_local int a = f();
|
|
|
|
extern thread_local int b;
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-DAG: @c = global i32 0
|
2013-04-20 00:42:07 +08:00
|
|
|
int c = b;
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-DAG: @_ZL1d = internal thread_local global i32 0
|
2013-04-20 00:42:07 +08:00
|
|
|
static thread_local int d = g();
|
|
|
|
|
|
|
|
struct U { static thread_local int m; };
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX-DAG: @_ZN1U1mE = thread_local global i32 0
|
|
|
|
// DARWIN-DAG: @_ZN1U1mE = internal thread_local global i32 0
|
2013-04-20 00:42:07 +08:00
|
|
|
thread_local int U::m = f();
|
|
|
|
|
2015-12-01 09:10:48 +08:00
|
|
|
namespace MismatchedInitType {
|
|
|
|
// Check that we don't crash here when we're forced to create a new global
|
|
|
|
// variable (with a different type) when we add the initializer.
|
|
|
|
union U {
|
|
|
|
int a;
|
|
|
|
float f;
|
|
|
|
constexpr U() : f(0.0) {}
|
|
|
|
};
|
|
|
|
static thread_local U u;
|
|
|
|
void *p = &u;
|
|
|
|
}
|
|
|
|
|
2013-04-20 00:42:07 +08:00
|
|
|
template<typename T> struct V { static thread_local int m; };
|
|
|
|
template<typename T> thread_local int V<T>::m = g();
|
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
template<typename T> struct W { static thread_local int m; };
|
|
|
|
template<typename T> thread_local int W<T>::m = 123;
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
struct Dtor { ~Dtor(); };
|
|
|
|
template<typename T> struct X { static thread_local Dtor m; };
|
|
|
|
template<typename T> thread_local Dtor X<T>::m;
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-DAG: @e = global
|
|
|
|
void *e = V<int>::m + W<int>::m + &X<int>::m;
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
template thread_local int V<float>::m;
|
|
|
|
template thread_local int W<float>::m;
|
|
|
|
template thread_local Dtor X<float>::m;
|
2013-04-15 07:01:42 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
extern template thread_local int V<char>::m;
|
|
|
|
extern template thread_local int W<char>::m;
|
|
|
|
extern template thread_local Dtor X<char>::m;
|
2013-04-15 07:01:42 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
void *e2 = V<char>::m + W<char>::m + &X<char>::m;
|
2013-04-15 07:01:42 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-DAG: @_ZN1VIiE1mE = linkonce_odr thread_local global i32 0
|
|
|
|
// CHECK-DAG: @_ZN1WIiE1mE = linkonce_odr thread_local global i32 123
|
|
|
|
// CHECK-DAG: @_ZN1XIiE1mE = linkonce_odr thread_local global {{.*}}
|
|
|
|
// CHECK-DAG: @_ZN1VIfE1mE = weak_odr thread_local global i32 0
|
|
|
|
// CHECK-DAG: @_ZN1WIfE1mE = weak_odr thread_local global i32 123
|
|
|
|
// CHECK-DAG: @_ZN1XIfE1mE = weak_odr thread_local global {{.*}}
|
2013-04-15 07:01:42 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-DAG: @_ZZ1fvE1n = internal thread_local global i32 0
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-DAG: @_ZGVZ1fvE1n = internal thread_local global i8 0
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-DAG: @_ZZ8tls_dtorvE1s = internal thread_local global
|
|
|
|
// CHECK-DAG: @_ZGVZ8tls_dtorvE1s = internal thread_local global i8 0
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-DAG: @_ZZ8tls_dtorvE1t = internal thread_local global
|
|
|
|
// CHECK-DAG: @_ZGVZ8tls_dtorvE1t = internal thread_local global i8 0
|
|
|
|
|
|
|
|
// CHECK-DAG: @_ZZ8tls_dtorvE1u = internal thread_local global
|
|
|
|
// CHECK-DAG: @_ZGVZ8tls_dtorvE1u = internal thread_local global i8 0
|
|
|
|
// CHECK-DAG: @_ZGRZ8tls_dtorvE1u_ = internal thread_local global
|
|
|
|
|
|
|
|
// CHECK-DAG: @_ZGVN1VIiE1mE = linkonce_odr thread_local global i64 0
|
|
|
|
|
|
|
|
// CHECK-DAG: @__tls_guard = internal thread_local global i8 0
|
|
|
|
|
|
|
|
// CHECK-DAG: @llvm.global_ctors = appending global {{.*}} @[[GLOBAL_INIT:[^ ]*]]
|
|
|
|
|
|
|
|
// LINUX-DAG: @_ZTH1a = alias void (), void ()* @__tls_init
|
|
|
|
// DARWIN-DAG: @_ZTH1a = internal alias void (), void ()* @__tls_init
|
|
|
|
// LINUX-DAG: @_ZTHN1U1mE = alias void (), void ()* @__tls_init
|
|
|
|
// DARWIN-DAG: @_ZTHN1U1mE = internal alias void (), void ()* @__tls_init
|
|
|
|
// CHECK-DAG: @_ZTHN1VIiE1mE = linkonce_odr alias void (), void ()* @[[V_M_INIT:[^, ]*]]
|
|
|
|
// CHECK-DAG: @_ZTHN1XIiE1mE = linkonce_odr alias void (), void ()* @[[X_M_INIT:[^, ]*]]
|
|
|
|
// CHECK-DAG: @_ZTHN1VIfE1mE = weak_odr alias void (), void ()* @[[VF_M_INIT:[^, ]*]]
|
|
|
|
// CHECK-DAG: @_ZTHN1XIfE1mE = weak_odr alias void (), void ()* @[[XF_M_INIT:[^, ]*]]
|
2019-09-13 04:00:24 +08:00
|
|
|
// FIXME: We really want a CHECK-DAG-NOT for these.
|
|
|
|
// CHECK-NOT: @_ZTHN1WIiE1mE =
|
|
|
|
// CHECK-NOT: @_ZTHN1WIfE1mE =
|
|
|
|
// CHECK-NOT: @_ZTHL1d =
|
2013-04-20 00:42:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Individual variable initialization functions:
|
|
|
|
|
|
|
|
// CHECK: define {{.*}} @[[A_INIT:.*]]()
|
|
|
|
// CHECK: call i32 @_Z1fv()
|
|
|
|
// CHECK-NEXT: store i32 {{.*}}, i32* @a, align 4
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i32 @_Z1fv()
|
2013-04-15 07:01:42 +08:00
|
|
|
int f() {
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: %[[GUARD:.*]] = load i8, i8* @_ZGVZ1fvE1n, align 1
|
2013-04-15 07:01:42 +08:00
|
|
|
// CHECK: %[[NEED_INIT:.*]] = icmp eq i8 %[[GUARD]], 0
|
|
|
|
// CHECK: br i1 %[[NEED_INIT]]
|
|
|
|
|
|
|
|
// CHECK: %[[CALL:.*]] = call i32 @_Z1gv()
|
|
|
|
// CHECK: store i32 %[[CALL]], i32* @_ZZ1fvE1n, align 4
|
|
|
|
// CHECK: store i8 1, i8* @_ZGVZ1fvE1n
|
|
|
|
// CHECK: br label
|
|
|
|
static thread_local int n = g();
|
|
|
|
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i32, i32* @_ZZ1fvE1n, align 4
|
2013-04-15 07:01:42 +08:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: define {{.*}} @[[C_INIT:.*]]()
|
2015-12-17 08:42:36 +08:00
|
|
|
// LINUX: call i32* @_ZTW1b()
|
|
|
|
// DARWIN: call cxx_fast_tlscc i32* @_ZTW1b()
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: load i32, i32* %{{.*}}, align 4
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK-NEXT: store i32 %{{.*}}, i32* @c, align 4
|
|
|
|
|
2019-09-13 04:00:24 +08:00
|
|
|
// LINUX-LABEL: define linkonce_odr hidden i32* @_ZTW1b()
|
2015-11-12 06:42:31 +08:00
|
|
|
// LINUX: br i1 icmp ne (void ()* @_ZTH1b, void ()* null),
|
2013-04-20 00:42:07 +08:00
|
|
|
// not null:
|
2015-11-12 06:42:31 +08:00
|
|
|
// LINUX: call void @_ZTH1b()
|
|
|
|
// LINUX: br label
|
2013-04-20 00:42:07 +08:00
|
|
|
// finally:
|
2015-11-12 06:42:31 +08:00
|
|
|
// LINUX: ret i32* @b
|
2015-12-17 08:42:36 +08:00
|
|
|
// DARWIN-LABEL: declare cxx_fast_tlscc i32* @_ZTW1b()
|
2015-11-12 06:42:31 +08:00
|
|
|
// There is no definition of the thread wrapper on Darwin for external TLV.
|
2013-04-20 00:42:07 +08:00
|
|
|
|
|
|
|
// CHECK: define {{.*}} @[[D_INIT:.*]]()
|
|
|
|
// CHECK: call i32 @_Z1gv()
|
|
|
|
// CHECK-NEXT: store i32 %{{.*}}, i32* @_ZL1d, align 4
|
|
|
|
|
|
|
|
// CHECK: define {{.*}} @[[U_M_INIT:.*]]()
|
|
|
|
// CHECK: call i32 @_Z1fv()
|
|
|
|
// CHECK-NEXT: store i32 %{{.*}}, i32* @_ZN1U1mE, align 4
|
|
|
|
|
|
|
|
// CHECK: define {{.*}} @[[E_INIT:.*]]()
|
2015-12-17 08:42:36 +08:00
|
|
|
// LINUX: call i32* @_ZTWN1VIiE1mE()
|
|
|
|
// DARWIN: call cxx_fast_tlscc i32* @_ZTWN1VIiE1mE()
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: load i32, i32* %{{.*}}, align 4
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX: call {{.*}}* @_ZTWN1XIiE1mE()
|
|
|
|
// DARWIN: call cxx_fast_tlscc {{.*}}* @_ZTWN1XIiE1mE()
|
|
|
|
// CHECK: store {{.*}} @e
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2015-12-17 08:42:36 +08:00
|
|
|
// LINUX-LABEL: define weak_odr hidden i32* @_ZTWN1VIiE1mE()
|
|
|
|
// DARWIN-LABEL: define weak_odr hidden cxx_fast_tlscc i32* @_ZTWN1VIiE1mE()
|
2016-03-19 07:35:21 +08:00
|
|
|
// LINUX: call void @_ZTHN1VIiE1mE()
|
|
|
|
// DARWIN: call cxx_fast_tlscc void @_ZTHN1VIiE1mE()
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: ret i32* @_ZN1VIiE1mE
|
|
|
|
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX-LABEL: define weak_odr hidden i32* @_ZTWN1WIiE1mE()
|
|
|
|
// DARWIN-LABEL: define weak_odr hidden cxx_fast_tlscc i32* @_ZTWN1WIiE1mE()
|
|
|
|
// CHECK-NOT: call
|
|
|
|
// CHECK: ret i32* @_ZN1WIiE1mE
|
|
|
|
|
|
|
|
// LINUX-LABEL: define weak_odr hidden {{.*}}* @_ZTWN1XIiE1mE()
|
|
|
|
// DARWIN-LABEL: define weak_odr hidden cxx_fast_tlscc {{.*}}* @_ZTWN1XIiE1mE()
|
|
|
|
// LINUX: call void @_ZTHN1XIiE1mE()
|
|
|
|
// DARWIN: call cxx_fast_tlscc void @_ZTHN1XIiE1mE()
|
|
|
|
// CHECK: ret {{.*}}* @_ZN1XIiE1mE
|
|
|
|
|
2018-05-30 02:28:49 +08:00
|
|
|
// LINUX: define internal void @[[VF_M_INIT]]()
|
|
|
|
// DARWIN: define internal cxx_fast_tlscc void @[[VF_M_INIT]]()
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX-SAME: comdat($_ZN1VIfE1mE)
|
|
|
|
// DARWIN-NOT: comdat
|
|
|
|
// CHECK: load i8, i8* bitcast (i64* @_ZGVN1VIfE1mE to i8*)
|
|
|
|
// CHECK: %[[VF_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
|
|
|
|
// CHECK: br i1 %[[VF_M_INITIALIZED]],
|
|
|
|
// need init:
|
|
|
|
// CHECK: call i32 @_Z1gv()
|
|
|
|
// CHECK: store i32 %{{.*}}, i32* @_ZN1VIfE1mE, align 4
|
|
|
|
// CHECK: store i64 1, i64* @_ZGVN1VIfE1mE
|
|
|
|
// CHECK: br label
|
|
|
|
|
2018-05-30 02:28:49 +08:00
|
|
|
// LINUX: define internal void @[[XF_M_INIT]]()
|
|
|
|
// DARWIN: define internal cxx_fast_tlscc void @[[XF_M_INIT]]()
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX-SAME: comdat($_ZN1XIfE1mE)
|
|
|
|
// DARWIN-NOT: comdat
|
|
|
|
// CHECK: load i8, i8* bitcast (i64* @_ZGVN1XIfE1mE to i8*)
|
|
|
|
// CHECK: %[[XF_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
|
|
|
|
// CHECK: br i1 %[[XF_M_INITIALIZED]],
|
|
|
|
// need init:
|
|
|
|
// LINUX: call {{.*}}__cxa_thread_atexit
|
|
|
|
// DARWIN: call {{.*}}_tlv_atexit
|
|
|
|
// CHECK: store i64 1, i64* @_ZGVN1XIfE1mE
|
|
|
|
// CHECK: br label
|
|
|
|
|
|
|
|
// LINUX: declare i32 @__cxa_thread_atexit(void (i8*)*, i8*, i8*)
|
|
|
|
// DARWIN: declare i32 @_tlv_atexit(void (i8*)*, i8*, i8*)
|
|
|
|
|
|
|
|
// DARWIN: declare cxx_fast_tlscc i32* @_ZTWN1VIcE1mE()
|
2019-12-17 06:20:32 +08:00
|
|
|
// LINUX: define linkonce_odr hidden i32* @_ZTWN1VIcE1mE() {{#[0-9]+}} comdat {
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX: br i1 icmp ne (void ()* @_ZTHN1VIcE1mE,
|
|
|
|
// LINUX: call void @_ZTHN1VIcE1mE()
|
|
|
|
// LINUX: ret i32* @_ZN1VIcE1mE
|
|
|
|
|
|
|
|
// DARWIN: declare cxx_fast_tlscc i32* @_ZTWN1WIcE1mE()
|
2019-12-17 06:20:32 +08:00
|
|
|
// LINUX: define linkonce_odr hidden i32* @_ZTWN1WIcE1mE() {{#[0-9]+}} comdat {
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX: br i1 icmp ne (void ()* @_ZTHN1WIcE1mE,
|
|
|
|
// LINUX: call void @_ZTHN1WIcE1mE()
|
|
|
|
// LINUX: ret i32* @_ZN1WIcE1mE
|
|
|
|
|
|
|
|
// DARWIN: declare cxx_fast_tlscc {{.*}}* @_ZTWN1XIcE1mE()
|
2019-12-17 06:20:32 +08:00
|
|
|
// LINUX: define linkonce_odr hidden {{.*}}* @_ZTWN1XIcE1mE() {{#[0-9]+}} comdat {
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX: br i1 icmp ne (void ()* @_ZTHN1XIcE1mE,
|
|
|
|
// LINUX: call void @_ZTHN1XIcE1mE()
|
|
|
|
// LINUX: ret {{.*}}* @_ZN1XIcE1mE
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2013-04-15 07:01:42 +08:00
|
|
|
struct S { S(); ~S(); };
|
|
|
|
struct T { ~T(); };
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z8tls_dtorv()
|
2013-04-15 07:01:42 +08:00
|
|
|
void tls_dtor() {
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i8, i8* @_ZGVZ8tls_dtorvE1s
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN1SC1Ev(%struct.S* {{[^,]*}} @_ZZ8tls_dtorvE1s)
|
2015-11-12 06:42:31 +08:00
|
|
|
// LINUX: call i32 @__cxa_thread_atexit({{.*}}@_ZN1SD1Ev {{.*}} @_ZZ8tls_dtorvE1s{{.*}} @__dso_handle
|
|
|
|
// DARWIN: call i32 @_tlv_atexit({{.*}}@_ZN1SD1Ev {{.*}} @_ZZ8tls_dtorvE1s{{.*}} @__dso_handle
|
2013-04-15 07:01:42 +08:00
|
|
|
// CHECK: store i8 1, i8* @_ZGVZ8tls_dtorvE1s
|
|
|
|
static thread_local S s;
|
|
|
|
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i8, i8* @_ZGVZ8tls_dtorvE1t
|
2013-04-15 07:01:42 +08:00
|
|
|
// CHECK-NOT: _ZN1T
|
2015-11-12 06:42:31 +08:00
|
|
|
// LINUX: call i32 @__cxa_thread_atexit({{.*}}@_ZN1TD1Ev {{.*}}@_ZZ8tls_dtorvE1t{{.*}} @__dso_handle
|
|
|
|
// DARWIN: call i32 @_tlv_atexit({{.*}}@_ZN1TD1Ev {{.*}}@_ZZ8tls_dtorvE1t{{.*}} @__dso_handle
|
2013-04-15 07:01:42 +08:00
|
|
|
// CHECK: store i8 1, i8* @_ZGVZ8tls_dtorvE1t
|
|
|
|
static thread_local T t;
|
|
|
|
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i8, i8* @_ZGVZ8tls_dtorvE1u
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN1SC1Ev(%struct.S* {{[^,]*}} @_ZGRZ8tls_dtorvE1u_)
|
2015-11-12 06:42:31 +08:00
|
|
|
// LINUX: call i32 @__cxa_thread_atexit({{.*}}@_ZN1SD1Ev {{.*}} @_ZGRZ8tls_dtorvE1u_{{.*}} @__dso_handle
|
|
|
|
// DARWIN: call i32 @_tlv_atexit({{.*}}@_ZN1SD1Ev {{.*}} @_ZGRZ8tls_dtorvE1u_{{.*}} @__dso_handle
|
2013-04-15 07:01:42 +08:00
|
|
|
// CHECK: store i8 1, i8* @_ZGVZ8tls_dtorvE1u
|
|
|
|
static thread_local const S &u = S();
|
|
|
|
}
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2013-05-17 03:52:25 +08:00
|
|
|
// CHECK: define {{.*}} @_Z7PR15991v(
|
|
|
|
int PR15991() {
|
|
|
|
thread_local int n;
|
|
|
|
auto l = [] { return n; };
|
|
|
|
return l();
|
|
|
|
}
|
|
|
|
|
2014-03-27 06:48:22 +08:00
|
|
|
struct PR19254 {
|
|
|
|
static thread_local int n;
|
|
|
|
int f();
|
|
|
|
};
|
|
|
|
// CHECK: define {{.*}} @_ZN7PR192541fEv(
|
|
|
|
int PR19254::f() {
|
2015-11-12 06:42:31 +08:00
|
|
|
// LINUX: call void @_ZTHN7PR192541nE(
|
2015-12-17 08:42:36 +08:00
|
|
|
// DARWIN: call cxx_fast_tlscc i32* @_ZTWN7PR192541nE(
|
2014-03-27 06:48:22 +08:00
|
|
|
return this->n;
|
|
|
|
}
|
|
|
|
|
2014-05-06 02:54:23 +08:00
|
|
|
namespace {
|
2019-09-13 04:00:24 +08:00
|
|
|
thread_local int anon_i{f()};
|
2014-05-06 02:54:23 +08:00
|
|
|
}
|
|
|
|
void set_anon_i() {
|
|
|
|
anon_i = 2;
|
|
|
|
}
|
2015-12-17 08:42:36 +08:00
|
|
|
// LINUX-LABEL: define internal i32* @_ZTWN12_GLOBAL__N_16anon_iE()
|
|
|
|
// DARWIN-LABEL: define internal cxx_fast_tlscc i32* @_ZTWN12_GLOBAL__N_16anon_iE()
|
2014-05-06 02:54:23 +08:00
|
|
|
|
2018-05-30 02:28:49 +08:00
|
|
|
// LINUX: define internal void @[[V_M_INIT]]()
|
|
|
|
// DARWIN: define internal cxx_fast_tlscc void @[[V_M_INIT]]()
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX-SAME: comdat($_ZN1VIiE1mE)
|
|
|
|
// DARWIN-NOT: comdat
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i8, i8* bitcast (i64* @_ZGVN1VIiE1mE to i8*)
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: %[[V_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
|
|
|
|
// CHECK: br i1 %[[V_M_INITIALIZED]],
|
|
|
|
// need init:
|
|
|
|
// CHECK: call i32 @_Z1gv()
|
|
|
|
// CHECK: store i32 %{{.*}}, i32* @_ZN1VIiE1mE, align 4
|
|
|
|
// CHECK: store i64 1, i64* @_ZGVN1VIiE1mE
|
|
|
|
// CHECK: br label
|
|
|
|
|
2018-05-30 02:28:49 +08:00
|
|
|
// LINUX: define internal void @[[X_M_INIT]]()
|
|
|
|
// DARWIN: define internal cxx_fast_tlscc void @[[X_M_INIT]]()
|
2017-01-13 08:43:31 +08:00
|
|
|
// LINUX-SAME: comdat($_ZN1XIiE1mE)
|
|
|
|
// DARWIN-NOT: comdat
|
|
|
|
// CHECK: load i8, i8* bitcast (i64* @_ZGVN1XIiE1mE to i8*)
|
|
|
|
// CHECK: %[[X_M_INITIALIZED:.*]] = icmp eq i8 %{{.*}}, 0
|
|
|
|
// CHECK: br i1 %[[X_M_INITIALIZED]],
|
|
|
|
// need init:
|
|
|
|
// LINUX: call {{.*}}__cxa_thread_atexit
|
|
|
|
// DARWIN: call {{.*}}_tlv_atexit
|
|
|
|
// CHECK: store i64 1, i64* @_ZGVN1XIiE1mE
|
|
|
|
// CHECK: br label
|
|
|
|
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: define {{.*}}@[[GLOBAL_INIT:.*]]()
|
|
|
|
// CHECK: call void @[[C_INIT]]()
|
|
|
|
// CHECK: call void @[[E_INIT]]()
|
|
|
|
|
|
|
|
|
|
|
|
// CHECK: define {{.*}}@__tls_init()
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i8, i8* @__tls_guard
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: %[[NEED_TLS_INIT:.*]] = icmp eq i8 %{{.*}}, 0
|
|
|
|
// CHECK: br i1 %[[NEED_TLS_INIT]],
|
|
|
|
// init:
|
2015-11-12 03:19:26 +08:00
|
|
|
// CHECK: store i8 1, i8* @__tls_guard
|
2018-11-01 04:39:26 +08:00
|
|
|
// CHECK-OPT: call {}* @llvm.invariant.start.p0i8(i64 1, i8* @__tls_guard)
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-NOT: call void @[[V_M_INIT]]()
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: call void @[[A_INIT]]()
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-NOT: call void @[[V_M_INIT]]()
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: call void @[[D_INIT]]()
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-NOT: call void @[[V_M_INIT]]()
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: call void @[[U_M_INIT]]()
|
2017-01-13 08:43:31 +08:00
|
|
|
// CHECK-NOT: call void @[[V_M_INIT]]()
|
2013-04-20 00:42:07 +08:00
|
|
|
|
|
|
|
|
2019-01-18 01:53:45 +08:00
|
|
|
// LINUX: define weak_odr hidden i32* @_ZTW1a()
|
2015-12-17 08:42:36 +08:00
|
|
|
// DARWIN: define cxx_fast_tlscc i32* @_ZTW1a()
|
2016-03-19 07:35:21 +08:00
|
|
|
// LINUX: call void @_ZTH1a()
|
|
|
|
// DARWIN: call cxx_fast_tlscc void @_ZTH1a()
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: ret i32* @a
|
|
|
|
// CHECK: }
|
|
|
|
|
|
|
|
|
2019-09-13 04:00:24 +08:00
|
|
|
// Should not emit a thread wrapper for internal-linkage unused variable 'd'.
|
|
|
|
// We separately check that 'd' does in fact get initialized with the other
|
|
|
|
// thread-local variables in this TU.
|
|
|
|
// CHECK-NOT: define {{.*}} @_ZTWL1d()
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2015-11-12 06:42:31 +08:00
|
|
|
// LINUX-LABEL: define weak_odr hidden i32* @_ZTWN1U1mE()
|
2015-12-17 08:42:36 +08:00
|
|
|
// DARWIN-LABEL: define cxx_fast_tlscc i32* @_ZTWN1U1mE()
|
2016-03-19 07:35:21 +08:00
|
|
|
// LINUX: call void @_ZTHN1U1mE()
|
|
|
|
// DARWIN: call cxx_fast_tlscc void @_ZTHN1U1mE()
|
2013-04-20 00:42:07 +08:00
|
|
|
// CHECK: ret i32* @_ZN1U1mE
|
2016-01-15 11:34:06 +08:00
|
|
|
|
2019-09-13 04:00:24 +08:00
|
|
|
// LINUX: declare extern_weak void @_ZTH1b() [[ATTR:#[0-9]+]]
|
|
|
|
|
2016-01-15 11:34:06 +08:00
|
|
|
// LINUX: attributes [[ATTR]] = { {{.+}} }
|