1 // RUN: %clang_cc1 -emit-llvm -std=c++1z %s -o - -triple=x86_64-linux-gnu | FileCheck %s
3 struct S
{ S(); ~S(); };
5 // CHECK-LABEL: define {{.*}}global_var_init
7 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @global)
10 // CHECK-LABEL: define {{.*}}global_var_init
11 // FIXME: Do we really need thread-safe initialization here? We don't run
12 // global ctors on multiple threads. (If we were to do so, we'd need thread-safe
13 // init for B<int>::member and B<int>::inline_member too.)
14 // CHECK: load atomic i8, ptr @_ZGV13inline_global acquire, align 8
15 // CHECK: icmp eq i8 {{.*}}, 0
18 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @inline_global)
19 inline S inline_global
;
21 // CHECK-LABEL: define {{.*}}global_var_init
23 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @thread_local_global)
24 thread_local S thread_local_global
;
26 // CHECK-LABEL: define {{.*}}global_var_init
27 // CHECK: load i8, ptr @_ZGV26thread_local_inline_global
28 // CHECK: icmp eq i8 {{.*}}, 0
31 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @thread_local_inline_global)
32 thread_local
inline S thread_local_inline_global
;
36 static thread_local S thread_local_member
;
38 // CHECK-LABEL: define {{.*}}global_var_init
39 // CHECK: load atomic i8, ptr @_ZGVN1A13inline_memberE acquire, align 8
40 // CHECK: icmp eq i8 {{.*}}, 0
43 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1A13inline_memberE)
44 static inline S inline_member
;
46 // CHECK-LABEL: define {{.*}}global_var_init
47 // CHECK: load i8, ptr @_ZGVN1A26thread_local_inline_memberE
48 // CHECK: icmp eq i8 {{.*}}, 0
51 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1A26thread_local_inline_memberE)
52 static thread_local
inline S thread_local_inline_member
;
55 // CHECK-LABEL: define{{.*}} void @_Z1fv()
57 // CHECK: load atomic i8, ptr @_ZGVZ1fvE12static_local acquire, align 8
58 // CHECK: icmp eq i8 {{.*}}, 0
59 // CHECK: br i1 {{.*}}, !prof ![[WEIGHTS_LOCAL:[0-9]*]]
60 static S static_local
;
62 // CHECK: load i8, ptr @_ZGVZ1fvE19static_thread_local,
63 // CHECK: icmp eq i8 {{.*}}, 0
64 // CHECK: br i1 {{.*}}, !prof ![[WEIGHTS_THREAD_LOCAL:[0-9]*]]
65 static thread_local S static_thread_local
;
68 // CHECK-LABEL: define {{.*}}global_var_init
70 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1A6memberE)
73 // CHECK-LABEL: define {{.*}}global_var_init
75 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1A19thread_local_memberE)
76 thread_local S
A::thread_local_member
;
78 template <typename T
> struct B
{
79 // CHECK-LABEL: define {{.*}}global_var_init
80 // CHECK: load i8, ptr @_ZGVN1BIiE6memberE
81 // CHECK: icmp eq i8 {{.*}}, 0
84 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1BIiE6memberE)
87 // CHECK-LABEL: define {{.*}}global_var_init
88 // CHECK: load i8, ptr @_ZGVN1BIiE13inline_memberE
89 // CHECK: icmp eq i8 {{.*}}, 0
92 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1BIiE13inline_memberE)
93 static inline S inline_member
;
95 // CHECK-LABEL: define {{.*}}global_var_init
96 // CHECK: load i8, ptr @_ZGVN1BIiE19thread_local_memberE
97 // CHECK: icmp eq i8 {{.*}}, 0
100 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1BIiE19thread_local_memberE)
101 static thread_local S thread_local_member
;
103 // CHECK-LABEL: define {{.*}}global_var_init
104 // CHECK: load i8, ptr @_ZGVN1BIiE26thread_local_inline_memberE
105 // CHECK: icmp eq i8 {{.*}}, 0
108 // CHECK: call void @_ZN1SC1Ev(ptr {{[^,]*}} @_ZN1BIiE26thread_local_inline_memberE)
109 static thread_local
inline S thread_local_inline_member
;
111 template<typename T
> S B
<T
>::member
;
112 template<typename T
> thread_local S B
<T
>::thread_local_member
;
114 template<typename
...T
> void use(T
&...);
116 use(B
<int>::member
, B
<int>::inline_member
, B
<int>::thread_local_member
,
117 B
<int>::thread_local_inline_member
);
120 // CHECK-LABEL: define {{.*}}tls_init()
121 // CHECK: load i8, ptr @__tls_guard, align 1
122 // CHECK: icmp eq i8 {{.*}}, 0
123 // CHECK: br i1 {{.*}}, !prof ![[WEIGHTS_THREAD_LOCAL]]
125 // CHECK-DAG: ![[WEIGHTS_THREAD_LOCAL]] = !{!"branch_weights", i32 1, i32 1023}
126 // CHECK-DAG: ![[WEIGHTS_LOCAL]] = !{!"branch_weights", i32 1, i32 1048575}