1 // RUN: %clang_cc1 %s -std=c++1y -triple=x86_64-pc-linux -emit-llvm -o - | FileCheck --check-prefix=ELF --check-prefix=ALL %s
2 // RUN: %clang_cc1 %s -std=c++1y -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck --check-prefix=MACHO --check-prefix=ALL %s
3 // RUN: %clang_cc1 %s -std=c++1y -triple=x86_64-pc-linux -emit-llvm -fdeclspec -DSELECTANY -o - | FileCheck --check-prefix=ELF-SELECTANY %s
13 // ELF-SELECTANY: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init, ptr @selectany }]
14 // ELF-SELECTANY: @llvm.used = appending global [1 x ptr] [ptr @selectany]
15 int __declspec(selectany
) selectany
= f();
23 template<typename T
> struct A
{ static int a
; };
24 template<typename T
> int A
<T
>::a
= foo();
26 // ALLK-NOT: @_ZN1AIcE1aE
27 template<> int A
<char>::a
;
29 // ALL: @_ZN1AIbE1aE ={{.*}} global i32 10
30 template<> int A
<bool>::a
= 10;
32 // ALL: @llvm.global_ctors = appending global [16 x { i32, ptr, ptr }]
34 // ELF: [{ i32, ptr, ptr } { i32 65535, ptr @[[unordered:[^,]*]], ptr @_ZN1AIsE1aE },
35 // MACHO: [{ i32, ptr, ptr } { i32 65535, ptr @[[unordered:[^,]*]], ptr null },
37 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered7:[^,]*]], ptr @_Z1xIsE },
38 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered7:[^,]*]], ptr null },
40 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered10:[^,]*]], ptr @_ZN2ns1aIiE1iE },
41 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered10:[^,]*]], ptr null },
43 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered11:[^,]*]], ptr @_ZN2ns1b1iIiEE },
44 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered11:[^,]*]], ptr null },
46 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered14:[^,]*]], ptr @_ZN1AIvE1aE },
47 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered14:[^,]*]], ptr null },
49 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered15:[^,]*]], ptr @_Z1xIcE },
50 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered15:[^,]*]], ptr null },
52 // ALL: { i32, ptr, ptr } { i32 65535, ptr @[[unordered16:[^,]*]], ptr null },
54 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered19:[^,]*]], ptr @_ZN3FibILi2EE1aE },
55 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered19:[^,]*]], ptr null },
57 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered18:[^,]*]], ptr @_ZN3FibILi3EE1aE },
58 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered18:[^,]*]], ptr null },
60 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered20:[^,]*]], ptr @_ZN3FibILi4EE1aE },
61 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered20:[^,]*]], ptr null },
63 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered17:[^,]*]], ptr @_ZN3FibILi5EE1aE },
64 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered17:[^,]*]], ptr null },
66 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered23:[^,]*]], ptr @_ZN4Fib2ILi2EE1aE },
67 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered23:[^,]*]], ptr null },
69 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered24:[^,]*]], ptr @_ZN4Fib2ILi3EE1aE },
70 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered24:[^,]*]], ptr null },
72 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered22:[^,]*]], ptr @_ZN4Fib2ILi4EE1aE },
73 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered22:[^,]*]], ptr null },
75 // ELF: { i32, ptr, ptr } { i32 65535, ptr @[[unordered21:[^,]*]], ptr @_ZN4Fib2ILi5EE1aE },
76 // MACHO: { i32, ptr, ptr } { i32 65535, ptr @[[unordered21:[^,]*]], ptr null },
78 // ALL: { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_static_member_variable_explicit_specialization.cpp, ptr null }]
80 /// llvm.used ensures SHT_INIT_ARRAY in a section group cannot be GCed.
81 // ELF: @llvm.used = appending global [14 x ptr] [ptr @_ZN1AIsE1aE, ptr @_Z1xIsE, ptr @_ZN2ns1aIiE1iE, ptr @_ZN2ns1b1iIiEE, ptr @_ZN1AIvE1aE, ptr @_Z1xIcE, ptr @_ZN3FibILi5EE1aE, ptr @_ZN3FibILi3EE1aE, ptr @_ZN3FibILi2EE1aE, ptr @_ZN3FibILi4EE1aE, ptr @_ZN4Fib2ILi5EE1aE, ptr @_ZN4Fib2ILi4EE1aE, ptr @_ZN4Fib2ILi2EE1aE, ptr @_ZN4Fib2ILi3EE1aE]
83 template int A
<short>::a
; // Unordered
86 int d
= A
<void>::a
; // Unordered
88 // An explicit specialization is ordered, and goes in __GLOBAL_sub_I_static_member_variable_explicit_specialization.cpp.
89 template<> struct A
<int> { static int a
; };
90 int A
<int>::a
= foo();
92 template<typename T
> struct S
{ static T x
; static T y
; };
93 template<> int S
<int>::x
= foo();
94 template<> int S
<int>::y
= S
<int>::x
;
96 template<typename T
> T x
= foo();
97 template short x
<short>; // Unordered
98 template<> int x
<int> = foo();
99 int e
= x
<char>; // Unordered
102 template <typename T
> struct a
{
105 template<typename T
> int a
<T
>::i
= foo();
106 template struct a
<int>;
109 template <typename T
> static T i
;
111 template<typename T
> T
b::i
= foo();
112 template int b::i
<int>;
116 template<typename T
> struct Internal
{ static int a
; };
117 template<typename T
> int Internal
<T
>::a
= foo();
119 int *use_internal_a
= &Internal
<int>::a
;
121 template<int n
> struct Fib
{ static int a
; };
122 template<> int Fib
<0>::a
= 0;
123 template<> int Fib
<1>::a
= 1;
124 template<int n
> int Fib
<n
>::a
= Fib
<n
-2>::a
+ Fib
<n
-1>::a
;
127 template<int n
> struct Fib2
{ static int a
; };
128 template<> int Fib2
<0>::a
= 0;
129 template<> int Fib2
<1>::a
= 1;
130 template<int n
> int Fib2
<n
>::a
= Fib2
<n
-1>::a
+ Fib2
<n
-2>::a
;
135 // ALL: define internal void @[[unordered]](
136 // ALL: call i32 @foo()
137 // ALL: store {{.*}} @_ZN1AIsE1aE
140 // ALL: define internal void @[[unordered7]](
141 // ALL: call i32 @foo()
142 // ALL: store {{.*}} @_Z1xIsE
145 // ALL: define internal void @[[unordered10]](
146 // ALL: call i32 @foo()
147 // ALL: store {{.*}} @_ZN2ns1aIiE1iE
150 // ALL: define internal void @[[unordered11]](
151 // ALL: call i32 @foo()
152 // ALL: store {{.*}} @_ZN2ns1b1iIiEE
155 // ALL: define internal void @[[unordered15]](
156 // ALL: call i32 @foo()
157 // ALL: store {{.*}} @_Z1xIcE
160 // ALL: define internal void @[[unordered16]](
161 // ALL: call i32 @foo()
162 // ALL: store {{.*}} @_ZN12_GLOBAL__N_18InternalIiE1aE
165 // ALL: define internal void @[[unordered17]](
166 // ALL: store {{.*}} @_ZN3FibILi5EE1aE
169 // ALL: define internal void @[[unordered18]](
170 // ALL: store {{.*}} @_ZN3FibILi3EE1aE
173 // ALL: define internal void @[[unordered19]](
174 // ALL: store {{.*}} @_ZN3FibILi2EE1aE
177 // ALL: define internal void @[[unordered20]](
178 // ALL: store {{.*}} @_ZN3FibILi4EE1aE
181 // ALL: define internal void @[[unordered21]](
182 // ALL: store {{.*}} @_ZN4Fib2ILi5EE1aE
185 // ALL: define internal void @[[unordered22]](
186 // ALL: store {{.*}} @_ZN4Fib2ILi4EE1aE
189 // ALL: define internal void @[[unordered23]](
190 // ALL: store {{.*}} @_ZN4Fib2ILi2EE1aE
193 // ALL: define internal void @[[unordered24]](
194 // ALL: store {{.*}} @_ZN4Fib2ILi3EE1aE
197 // ALL: define internal void @_GLOBAL__sub_I_static_member_variable_explicit_specialization.cpp()
198 // We call unique stubs for every ordered dynamic initializer in the TU.