1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s -w | FileCheck %s
3 // CHECK-LABEL: define linkonce_odr void @_Z11inline_funci
4 inline void inline_func(int n
) {
5 // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE_clEv
6 int i
= []{ return 1; }();
8 // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE0_clEv
9 int j
= [=] { return n
+ i
; }();
11 // CHECK: call noundef double @_ZZ11inline_funciENKUlvE1_clEv
12 int k
= [=] () -> double { return n
+ i
; }();
14 // CHECK: call noundef i32 @_ZZ11inline_funciENKUliE_clEi
15 int l
= [=] (int x
) -> int { return x
+ i
; }(n
);
17 int inner(int i
= []{ return 17; }());
18 // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE2_clEv
19 // CHECK-NEXT: call noundef i32 @_Z5inneri
22 // CHECK-NEXT: ret void
25 void call_inline_func() {
29 // CHECK-LABEL: define linkonce_odr noundef i32* @_ZNK10inline_varMUlvE_clEv(
30 // CHECK: @_ZZNK10inline_varMUlvE_clEvE1n
31 inline auto inline_var
= [] {
36 int *use_inline_var
= inline_var();
38 // CHECK-LABEL: define linkonce_odr noundef i32* @_ZNK12var_templateIiEMUlvE_clEv(
39 // CHECK: @_ZZNK12var_templateIiEMUlvE_clEvE1n
40 template<typename T
> auto var_template
= [] {
45 int *use_var_template
= var_template
<int>();
47 // CHECK-LABEL: define {{.*}} @_Z29use_var_template_substitutionN12var_templateIiEMUlvE_ENS_IfEMUlvE_E
48 void use_var_template_substitution(decltype(var_template
<int>), decltype(var_template
<float>)) {}
51 void f(int = []{return 1;}()
53 int = []{return 3;}());
57 void S::g(int i
= []{return 1;}(),
58 int j
= []{return 2; }()) {}
60 // CHECK-LABEL: define{{.*}} void @_Z6test_S1S
62 // CHECK: call noundef i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv
63 // CHECK-NEXT: call noundef i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv
64 // CHECK-NEXT: add nsw i32
65 // CHECK-NEXT: call noundef i32 @_ZZN1S1fEiiEd_NKUlvE_clEv
66 // CHECK-NEXT: call void @_ZN1S1fEii
69 // NOTE: These manglings don't actually matter that much, because
70 // the lambdas in the default arguments of g() won't be seen by
71 // multiple translation units. We check them mainly to ensure that they don't
72 // get the special mangling for lambdas in in-class default arguments.
73 // CHECK: call noundef i32 @"_ZNK1S3$_0clEv"
74 // CHECK-NEXT: call noundef i32 @"_ZNK1S3$_1clEv"
75 // CHECK-NEXT: call void @_ZN1S1gEi
78 // CHECK-NEXT: ret void
81 // Check the linkage of the lambda call operators used in test_S.
82 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv
84 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv
86 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN1S1fEiiEd_NKUlvE_clEv
88 // CHECK-LABEL: define internal noundef i32 @"_ZNK1S3$_0clEv"
90 // CHECK-LABEL: define internal noundef i32 @"_ZNK1S3$_1clEv"
95 void f(T
= []{return T() + 1;}()
96 + []{return T() + 2;}(),
97 T
= []{return T(3);}());
100 // CHECK-LABEL: define{{.*}} void @_Z7test_ST2STIdE
101 void test_ST(ST
<double> st
) {
102 // CHECK: call noundef double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv
103 // CHECK-NEXT: call noundef double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv
104 // CHECK-NEXT: fadd double
105 // CHECK-NEXT: call noundef double @_ZZN2STIdE1fEddEd_NKUlvE_clEv
106 // CHECK-NEXT: call void @_ZN2STIdE1fEdd
109 // CHECK-NEXT: ret void
112 // Check the linkage of the lambda call operators used in test_ST.
113 // CHECK-LABEL: define linkonce_odr noundef double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv
114 // CHECK: ret double 1
115 // CHECK-LABEL: define linkonce_odr noundef double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv
116 // CHECK: ret double 2
117 // CHECK-LABEL: define linkonce_odr noundef double @_ZZN2STIdE1fEddEd_NKUlvE_clEv
118 // CHECK: ret double 3
121 struct StaticMembers
{
128 template<typename T
> int accept_lambda(T
);
131 T StaticMembers
<T
>::x
= []{return 1;}() + []{return 2;}();
134 T StaticMembers
<T
>::y
= []{return 3;}();
137 T StaticMembers
<T
>::z
= accept_lambda([]{return 4;});
140 int (*StaticMembers
<T
>::f
)() = []{return 5;};
142 // CHECK-LABEL: define internal void @__cxx_global_var_init
143 // CHECK: call noundef i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv
144 // CHECK-NEXT: call noundef i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv
145 // CHECK-NEXT: add nsw
146 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv
148 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv
150 template float StaticMembers
<float>::x
;
152 // CHECK-LABEL: define internal void @__cxx_global_var_init
153 // CHECK: call noundef i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv
154 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv
156 template float StaticMembers
<float>::y
;
158 // CHECK-LABEL: define internal void @__cxx_global_var_init
159 // CHECK: call noundef i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_
160 // CHECK: declare noundef i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_()
161 template float StaticMembers
<float>::z
;
163 // CHECK-LABEL: define internal void @__cxx_global_var_init
164 // CHECK: call {{.*}} @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv
165 // CHECK-LABEL: define linkonce_odr noundef i32 ()* @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv
166 template int (*StaticMembers
<float>::f
)();
168 // CHECK-LABEL: define internal void @__cxx_global_var_init
169 // CHECK: call noundef i32 @"_ZNK13StaticMembersIdE3$_2clEv"
170 // CHECK-LABEL: define internal noundef i32 @"_ZNK13StaticMembersIdE3$_2clEv"
172 template<> double StaticMembers
<double>::z
= []{return 42; }();
175 void func_template(T
= []{ return T(); }());
177 // CHECK-LABEL: define{{.*}} void @_Z17use_func_templatev()
178 void use_func_template() {
179 // CHECK: call noundef i32 @"_ZZ13func_templateIiEvT_ENK3$_3clEv"
180 func_template
<int>();
185 bool before(const type_info
&) const noexcept
;
189 struct A
{ virtual ~A(); } g
;
190 struct C
{ virtual ~C(); } k
;
192 void f(const std::type_info
& x
= typeid([]()->A
& { return g
; }()));
194 void j(bool cond
= typeid([]() -> A
& { return g
; }()).before(typeid([]() -> C
& { return k
; }())));
196 void B::h() { f(); j(); }
199 // CHECK-LABEL: define linkonce_odr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %"struct.PR12123::A"* @_ZZN7PR121231B1fERKSt9type_infoEd_NKUlvE_clEv
200 // CHECK-LABEL: define linkonce_odr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %"struct.PR12123::A"* @_ZZN7PR121231B1jEbEd_NKUlvE_clEv
201 // CHECK-LABEL: define linkonce_odr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %"struct.PR12123::C"* @_ZZN7PR121231B1jEbEd_NKUlvE0_clEv
203 // CHECK-LABEL: define {{.*}} @_Z{{[0-9]*}}testVarargsLambdaNumberingv(
204 inline int testVarargsLambdaNumbering() {
205 // CHECK: testVarargsLambdaNumberingvE{{.*}}UlzE_
206 auto a
= [](...) { static int n
; return ++n
; };
207 // CHECK: testVarargsLambdaNumberingvE{{.*}}UlvE_
208 auto b
= []() { static int n
; return ++n
; };
211 int k
= testVarargsLambdaNumbering();
213 // Check linkage of the various lambdas.
214 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv
216 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE0_clEv
218 // CHECK-LABEL: define linkonce_odr noundef double @_ZZ11inline_funciENKUlvE1_clEv
220 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUliE_clEi
222 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE2_clEv
225 // CHECK-LABEL: define linkonce_odr void @_ZN7MembersC2Ev
226 // CHECK: call noundef i32 @_ZNK7Members1xMUlvE_clEv
227 // CHECK-NEXT: call noundef i32 @_ZNK7Members1xMUlvE0_clE
228 // CHECK-NEXT: add nsw i32
229 // CHECK: call noundef i32 @_ZNK7Members1yMUlvE_clEv
233 // Check the linkage of the lambdas used in test_Members.
234 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK7Members1xMUlvE_clEv
236 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK7Members1xMUlvE0_clEv
238 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK7Members1yMUlvE_clEv
241 // CHECK-LABEL: define linkonce_odr void @_Z1fIZZNK23TestNestedInstantiationclEvENKUlvE_clEvEUlvE_EvT_
245 template <typename
> struct B
{
247 template <typename L
> constexpr B(L
&& x
) : a(x()) { }
249 template <typename
> void b(int) {
250 [&]{ (void)B
<int>([&]{ return 1; }); }();
255 // CHECK-LABEL: define linkonce_odr void @_ZZN7PR128081bIiEEviENKUlvE_clEv
256 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZN7PR128081bIiEEviENKUlvE_clEvENKUlvE_clEv
261 int x
= [] { return 1; }() + [] { return 2; }();
262 int y
= [] { return 3; }();
265 void test_Members() {
269 template<typename P
> void f(P
) { }
271 struct TestNestedInstantiation
{
272 void operator()() const {
279 void test_NestedInstantiation() {
280 TestNestedInstantiation()();