1 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s -w | FileCheck %s
5 // CHECK-LABEL: define linkonce_odr void @_Z11inline_funci
6 inline void inline_func(int n
) {
7 // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE_clEv
8 int i
= []{ return side_effect(), 1; }();
10 // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE0_clEv
11 int j
= [=] { return n
+ i
; }();
13 // CHECK: call noundef double @_ZZ11inline_funciENKUlvE1_clEv
14 int k
= [=] () -> double { return n
+ i
; }();
16 // CHECK: call noundef i32 @_ZZ11inline_funciENKUliE_clEi
17 int l
= [=] (int x
) -> int { return x
+ i
; }(n
);
19 int inner(int i
= []{ return side_effect(), 17; }());
20 // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE2_clEv
21 // CHECK-NEXT: call noundef i32 @_Z5inneri
24 // CHECK-NEXT: ret void
27 void call_inline_func() {
31 // CHECK-LABEL: define linkonce_odr noundef ptr @_ZNK10inline_varMUlvE_clEv(
32 // CHECK: @_ZZNK10inline_varMUlvE_clEvE1n
33 inline auto inline_var
= [] {
38 int *use_inline_var
= inline_var();
40 // CHECK-LABEL: define linkonce_odr noundef ptr @_ZNK12var_templateIiEMUlvE_clEv(
41 // CHECK: @_ZZNK12var_templateIiEMUlvE_clEvE1n
42 template<typename T
> auto var_template
= [] {
47 int *use_var_template
= var_template
<int>();
49 // CHECK-LABEL: define {{.*}} @_Z29use_var_template_substitutionN12var_templateIiEMUlvE_ENS_IfEMUlvE_E
50 void use_var_template_substitution(decltype(var_template
<int>), decltype(var_template
<float>)) {}
53 void f(int = []{return side_effect(), 1;}()
54 + []{return side_effect(), 2;}(),
55 int = []{return side_effect(), 3;}());
59 void S::g(int i
= []{return side_effect(), 1;}(),
60 int j
= []{return side_effect(), 2; }()) {}
62 // CHECK-LABEL: define{{.*}} void @_Z6test_S1S
64 // CHECK: call noundef i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv
65 // CHECK-NEXT: call noundef i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv
66 // CHECK-NEXT: add nsw i32
67 // CHECK-NEXT: call noundef i32 @_ZZN1S1fEiiEd_NKUlvE_clEv
68 // CHECK-NEXT: call void @_ZN1S1fEii
71 // NOTE: These manglings don't actually matter that much, because
72 // the lambdas in the default arguments of g() won't be seen by
73 // multiple translation units. We check them mainly to ensure that they don't
74 // get the special mangling for lambdas in in-class default arguments.
75 // CHECK: call noundef i32 @"_ZNK1S3$_0clEv"
76 // CHECK-NEXT: call noundef i32 @"_ZNK1S3$_1clEv"
77 // CHECK-NEXT: call void @_ZN1S1gEi
80 // CHECK-NEXT: ret void
83 // Check the linkage of the lambda call operators used in test_S.
84 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv
86 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv
88 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN1S1fEiiEd_NKUlvE_clEv
90 // CHECK-LABEL: define internal noundef i32 @"_ZNK1S3$_0clEv"
92 // CHECK-LABEL: define internal noundef i32 @"_ZNK1S3$_1clEv"
97 void f(T
= []{return T() + 1;}()
98 + []{return T() + 2;}(),
99 T
= []{return T(3);}());
102 // CHECK-LABEL: define{{.*}} void @_Z7test_ST2STIdE
103 void test_ST(ST
<double> st
) {
104 // CHECK: call noundef double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv
105 // CHECK-NEXT: call noundef double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv
106 // CHECK-NEXT: fadd double
107 // CHECK-NEXT: call noundef double @_ZZN2STIdE1fEddEd_NKUlvE_clEv
108 // CHECK-NEXT: call void @_ZN2STIdE1fEdd
111 // CHECK-NEXT: ret void
114 // Check the linkage of the lambda call operators used in test_ST.
115 // CHECK-LABEL: define linkonce_odr noundef double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv
116 // CHECK: ret double 1
117 // CHECK-LABEL: define linkonce_odr noundef double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv
118 // CHECK: ret double 2
119 // CHECK-LABEL: define linkonce_odr noundef double @_ZZN2STIdE1fEddEd_NKUlvE_clEv
120 // CHECK: ret double 3
123 struct StaticMembers
{
130 template<typename T
> int accept_lambda(T
);
133 T StaticMembers
<T
>::x
= []{return side_effect(), 1;}() + []{return side_effect(), 2;}();
136 T StaticMembers
<T
>::y
= []{return side_effect(), 3;}();
139 T StaticMembers
<T
>::z
= accept_lambda([]{return side_effect(), 4;});
142 int (*StaticMembers
<T
>::f
)() = (side_effect(), []{return side_effect(), 5;});
144 // CHECK-LABEL: define internal void @__cxx_global_var_init
145 // CHECK: call noundef i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv
146 // CHECK-NEXT: call noundef i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv
147 // CHECK-NEXT: add nsw
148 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv
150 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv
152 template float StaticMembers
<float>::x
;
154 // CHECK-LABEL: define internal void @__cxx_global_var_init
155 // CHECK: call noundef i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv
156 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv
158 template float StaticMembers
<float>::y
;
160 // CHECK-LABEL: define internal void @__cxx_global_var_init
161 // CHECK: call noundef i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_
162 // CHECK: declare noundef i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_()
163 template float StaticMembers
<float>::z
;
165 // CHECK-LABEL: define internal void @__cxx_global_var_init
166 // CHECK: call {{.*}} @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv
167 // CHECK-LABEL: define linkonce_odr noundef ptr @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv
168 template int (*StaticMembers
<float>::f
)();
170 // CHECK-LABEL: define internal void @__cxx_global_var_init
171 // CHECK: call noundef i32 @"_ZNK13StaticMembersIdE3$_2clEv"
172 // CHECK-LABEL: define internal noundef i32 @"_ZNK13StaticMembersIdE3$_2clEv"
174 template<> double StaticMembers
<double>::z
= []{return side_effect(), 42; }();
177 void func_template(T
= []{ return T(); }());
179 // CHECK-LABEL: define{{.*}} void @_Z17use_func_templatev()
180 void use_func_template() {
181 // CHECK: call noundef i32 @"_ZZ13func_templateIiEvT_ENK3$_0clEv"
182 func_template
<int>();
187 bool before(const type_info
&) const noexcept
;
191 struct A
{ virtual ~A(); } g
;
192 struct C
{ virtual ~C(); } k
;
194 void f(const std::type_info
& x
= typeid([]()->A
& { return g
; }()));
196 void j(bool cond
= typeid([]() -> A
& { return g
; }()).before(typeid([]() -> C
& { return k
; }())));
198 void B::h() { f(); j(); }
201 // CHECK-LABEL: define linkonce_odr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZZN7PR121231B1fERKSt9type_infoEd_NKUlvE_clEv
202 // CHECK-LABEL: define linkonce_odr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZZN7PR121231B1jEbEd_NKUlvE_clEv
203 // CHECK-LABEL: define linkonce_odr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZZN7PR121231B1jEbEd_NKUlvE0_clEv
205 // CHECK-LABEL: define {{.*}} @_Z{{[0-9]*}}testVarargsLambdaNumberingv(
206 inline int testVarargsLambdaNumbering() {
207 // CHECK: testVarargsLambdaNumberingvE{{.*}}UlzE_
208 auto a
= [](...) { static int n
; return ++n
; };
209 // CHECK: testVarargsLambdaNumberingvE{{.*}}UlvE_
210 auto b
= []() { static int n
; return ++n
; };
213 int k
= testVarargsLambdaNumbering();
216 template<typename
= int>
217 void ft1(int = [](int p
= [] { return side_effect(), 42; } ()) {
221 // CHECK: call noundef i32 @"_ZZZ3ft1IiEviENK3$_0clEiEd_NKUlvE_clEv"
222 // CHECK: call noundef i32 @"_ZZ3ft1IiEviENK3$_0clEi"
225 // CHECK-LABEL: define internal noundef i32 @"_ZZ3ft1IiEviENK3$_0clEi"
226 // CHECK-LABEL: define internal noundef i32 @"_ZZZ3ft1IiEviENK3$_0clEiEd_NKUlvE_clEv"
229 template<typename
= int>
230 void mft1(int = [](int p
= [] { return side_effect(), 42; } ()) {
234 void test_c1_mft1() {
235 // CHECK: call noundef i32 @_ZZZN2c14mft1IiEEviEd_NKUliE_clEiEd_NKUlvE_clEv
236 // CHECK: call noundef i32 @_ZZN2c14mft1IiEEviEd_NKUliE_clEi
239 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN2c14mft1IiEEviEd_NKUliE_clEi
240 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZN2c14mft1IiEEviEd_NKUliE_clEiEd_NKUlvE_clEv
242 template<typename
= int>
244 void mf1(int = [](int p
= [] { return side_effect(), 42; } ()) {
247 friend void ff(ct1
, int = [](int p
= [] { return side_effect(), 0; }()) { return p
; }()) {}
249 void test_ct1_mft1() {
250 // CHECK: call noundef i32 @_ZZZN3ct1IiE3mf1EiEd_NKUliE_clEiEd_NKUlvE_clEv
251 // CHECK: call noundef i32 @_ZZN3ct1IiE3mf1EiEd_NKUliE_clEi
253 // CHECK: call noundef i32 @_ZZZ2ff3ct1IiEiEd_NKUliE_clEiEd_NKUlvE_clEv
254 // CHECK: call noundef i32 @_ZZ2ff3ct1IiEiEd_NKUliE_clEi
257 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN3ct1IiE3mf1EiEd_NKUliE_clEi
258 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZN3ct1IiE3mf1EiEd_NKUliE_clEiEd_NKUlvE_clEv
259 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ2ff3ct1IiEiEd_NKUliE_clEi
260 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ2ff3ct1IiEiEd_NKUliE_clEiEd_NKUlvE_clEv
262 template<typename
= int>
264 [](int p
= [] { return side_effect(), 42; } ()) { return p
; } ();
266 template void ft2
<>();
267 // CHECK: call noundef i32 @_ZZZ3ft2IiEvvENKUliE_clEiEd_NKUlvE_clEv
268 // CHECK: call noundef i32 @_ZZ3ft2IiEvvENKUliE_clEi
269 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ3ft2IiEvvENKUliE_clEi
270 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ3ft2IiEvvENKUliE_clEiEd_NKUlvE_clEv
274 void f(int = []{ return side_effect(), 0; }());
277 template void ft3
<int>();
278 // CHECK: call noundef i32 @"_ZZ1fiENK3$_0clEv"
279 // CHECK-LABEL: define internal noundef i32 @"_ZZ1fiENK3$_0clEv"
284 void mf(int = []{ return side_effect(), 0; }()) {}
288 template void ft4
<int>();
289 // CHECK: call noundef i32 @_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv
290 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv
293 extern int ExternalVariable
;
294 struct StaticInlineMember
{
295 static constexpr auto x
= [] { return ExternalVariable
; };
298 // CHECK-LABEL: define void @_Z23test_StaticInlineMemberv
299 // CHECK: call {{.*}} @_ZNK18StaticInlineMember1xMUlvE_clEv
300 void test_StaticInlineMember() {
301 StaticInlineMember::x();
304 // Check linkage of the various lambdas.
305 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv
307 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE0_clEv
309 // CHECK-LABEL: define linkonce_odr noundef double @_ZZ11inline_funciENKUlvE1_clEv
311 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUliE_clEi
313 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE2_clEv
316 // CHECK-LABEL: define linkonce_odr void @_ZN7MembersC2Ev
317 // CHECK: call noundef i32 @_ZNK7Members1xMUlvE_clEv
318 // CHECK-NEXT: call noundef i32 @_ZNK7Members1xMUlvE0_clE
319 // CHECK-NEXT: add nsw i32
320 // CHECK: call noundef i32 @_ZNK7Members1yMUlvE_clEv
324 // Check the linkage of the lambdas used in test_Members.
325 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK7Members1xMUlvE_clEv
327 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK7Members1xMUlvE0_clEv
329 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK7Members1yMUlvE_clEv
332 // CHECK-LABEL: define linkonce_odr void @_Z1fIZZNK23TestNestedInstantiationclEvENKUlvE_clEvEUlvE_EvT_
336 template <typename
> struct B
{
338 template <typename L
> constexpr B(L
&& x
) : a(x()) { }
340 template <typename
> void b(int) {
341 [&]{ (void)B
<int>([&]{ return side_effect(), 1; }); }();
346 // CHECK-LABEL: define linkonce_odr void @_ZZN7PR128081bIiEEviENKUlvE_clEv
347 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZN7PR128081bIiEEviENKUlvE_clEvENKUlvE_clEv
352 int x
= [] { return side_effect(), 1; }() + [] { return side_effect(), 2; }();
353 int y
= [] { return side_effect(), 3; }();
356 void test_Members() {
360 template<typename P
> void f(P
) { }
362 struct TestNestedInstantiation
{
363 void operator()() const {
370 void test_NestedInstantiation() {
371 TestNestedInstantiation()();