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 i32 @_ZZ11inline_funciENKUlvE_clEv
6 int i = []{ return 1; }();
8 // CHECK: call i32 @_ZZ11inline_funciENKUlvE0_clEv
9 int j = [=] { return n + i; }();
11 // CHECK: call double @_ZZ11inline_funciENKUlvE1_clEv
12 int k = [=] () -> double { return n + i; }();
14 // CHECK: call i32 @_ZZ11inline_funciENKUliE_clEi
15 int l = [=] (int x) -> int { return x + i; }(n);
17 int inner(int i = []{ return 17; }());
18 // CHECK: call i32 @_ZZ11inline_funciENKUlvE2_clEv
19 // CHECK-NEXT: call i32 @_Z5inneri
22 // CHECK-NEXT: ret void
25 void call_inline_func() {
30 void f(int = []{return 1;}()
32 int = []{return 3;}());
36 void S::g(int i = []{return 1;}(),
37 int j = []{return 2; }()) {}
39 // CHECK-LABEL: define void @_Z6test_S1S
41 // CHECK: call i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv
42 // CHECK-NEXT: call i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv
43 // CHECK-NEXT: add nsw i32
44 // CHECK-NEXT: call i32 @_ZZN1S1fEiiEd_NKUlvE_clEv
45 // CHECK-NEXT: call void @_ZN1S1fEii
48 // NOTE: These manglings don't actually matter that much, because
49 // the lambdas in the default arguments of g() won't be seen by
50 // multiple translation units. We check them mainly to ensure that they don't
51 // get the special mangling for lambdas in in-class default arguments.
52 // CHECK: call i32 @"_ZNK1S3$_0clEv"
53 // CHECK-NEXT: call i32 @"_ZNK1S3$_1clEv"
54 // CHECK-NEXT: call void @_ZN1S1gEi
57 // CHECK-NEXT: ret void
60 // Check the linkage of the lambda call operators used in test_S.
61 // CHECK-LABEL: define linkonce_odr i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv
63 // CHECK-LABEL: define linkonce_odr i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv
65 // CHECK-LABEL: define linkonce_odr i32 @_ZZN1S1fEiiEd_NKUlvE_clEv
67 // CHECK-LABEL: define internal i32 @"_ZNK1S3$_0clEv"
69 // CHECK-LABEL: define internal i32 @"_ZNK1S3$_1clEv"
74 void f(T = []{return T() + 1;}()
75 + []{return T() + 2;}(),
76 T = []{return T(3);}());
79 // CHECK-LABEL: define void @_Z7test_ST2STIdE
80 void test_ST(ST<double> st) {
81 // CHECK: call double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv
82 // CHECK-NEXT: call double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv
83 // CHECK-NEXT: fadd double
84 // CHECK-NEXT: call double @_ZZN2STIdE1fEddEd_NKUlvE_clEv
85 // CHECK-NEXT: call void @_ZN2STIdE1fEdd
88 // CHECK-NEXT: ret void
91 // Check the linkage of the lambda call operators used in test_ST.
92 // CHECK-LABEL: define linkonce_odr double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv
93 // CHECK: ret double 1
94 // CHECK-LABEL: define linkonce_odr double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv
95 // CHECK: ret double 2
96 // CHECK-LABEL: define linkonce_odr double @_ZZN2STIdE1fEddEd_NKUlvE_clEv
97 // CHECK: ret double 3
100 struct StaticMembers {
107 template<typename T> int accept_lambda(T);
110 T StaticMembers<T>::x = []{return 1;}() + []{return 2;}();
113 T StaticMembers<T>::y = []{return 3;}();
116 T StaticMembers<T>::z = accept_lambda([]{return 4;});
119 int (*StaticMembers<T>::f)() = []{return 5;};
121 // CHECK-LABEL: define internal void @__cxx_global_var_init()
122 // CHECK: call i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv
123 // CHECK-NEXT: call i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv
124 // CHECK-NEXT: add nsw
125 // CHECK-LABEL: define linkonce_odr i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv
127 // CHECK-LABEL: define linkonce_odr i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv
129 template float StaticMembers<float>::x;
131 // CHECK-LABEL: define internal void @__cxx_global_var_init.1()
132 // CHECK: call i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv
133 // CHECK-LABEL: define linkonce_odr i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv
135 template float StaticMembers<float>::y;
137 // CHECK-LABEL: define internal void @__cxx_global_var_init.2()
138 // CHECK: call i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_
139 // CHECK: declare i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_()
140 template float StaticMembers<float>::z;
142 // CHECK-LABEL: define internal void @__cxx_global_var_init.3()
143 // CHECK: call {{.*}} @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv
144 // CHECK-LABEL: define linkonce_odr i32 ()* @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv
145 template int (*StaticMembers<float>::f)();
147 // CHECK-LABEL: define internal void @__cxx_global_var_init.4
148 // CHECK: call i32 @"_ZNK13StaticMembersIdE3$_2clEv"
149 // CHECK-LABEL: define internal i32 @"_ZNK13StaticMembersIdE3$_2clEv"
151 template<> double StaticMembers<double>::z = []{return 42; }();
154 void func_template(T = []{ return T(); }());
156 // CHECK-LABEL: define void @_Z17use_func_templatev()
157 void use_func_template() {
158 // CHECK: call i32 @"_ZZ13func_templateIiEvT_ENK3$_3clEv"
159 func_template<int>();
166 struct A { virtual ~A(); } g;
168 void f(const std::type_info& x = typeid([]()->A& { return g; }()));
174 // CHECK-LABEL: define linkonce_odr dereferenceable({{[0-9]+}}) %"struct.PR12123::A"* @_ZZN7PR121231B1fERKSt9type_infoEd_NKUlvE_clEv
176 // CHECK-LABEL: define {{.*}} @_Z{{[0-9]*}}testVarargsLambdaNumberingv(
177 inline int testVarargsLambdaNumbering() {
178 // CHECK: testVarargsLambdaNumberingvE{{.*}}UlzE_
179 auto a = [](...) { static int n; return ++n; };
180 // CHECK: testVarargsLambdaNumberingvE{{.*}}UlvE_
181 auto b = []() { static int n; return ++n; };
184 int k = testVarargsLambdaNumbering();
186 // Check linkage of the various lambdas.
187 // CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE_clEv
189 // CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE0_clEv
191 // CHECK-LABEL: define linkonce_odr double @_ZZ11inline_funciENKUlvE1_clEv
193 // CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUliE_clEi
195 // CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE2_clEv
198 // CHECK-LABEL: define linkonce_odr void @_ZN7MembersC2Ev
199 // CHECK: call i32 @_ZNK7Members1xMUlvE_clEv
200 // CHECK-NEXT: call i32 @_ZNK7Members1xMUlvE0_clE
201 // CHECK-NEXT: add nsw i32
202 // CHECK: call i32 @_ZNK7Members1yMUlvE_clEv
206 // Check the linkage of the lambdas used in test_Members.
207 // CHECK-LABEL: define linkonce_odr i32 @_ZNK7Members1xMUlvE_clEv
209 // CHECK-LABEL: define linkonce_odr i32 @_ZNK7Members1xMUlvE0_clEv
211 // CHECK-LABEL: define linkonce_odr i32 @_ZNK7Members1yMUlvE_clEv
214 // CHECK-LABEL: define linkonce_odr void @_Z1fIZZNK23TestNestedInstantiationclEvENKUlvE_clEvEUlvE_EvT_
218 template <typename> struct B {
220 template <typename L> constexpr B(L&& x) : a(x()) { }
222 template <typename> void b(int) {
223 [&]{ (void)B<int>([&]{ return 1; }); }();
228 // CHECK-LABEL: define linkonce_odr void @_ZZN7PR128081bIiEEviENKUlvE_clEv
229 // CHECK-LABEL: define linkonce_odr i32 @_ZZZN7PR128081bIiEEviENKUlvE_clEvENKUlvE_clEv
234 int x = [] { return 1; }() + [] { return 2; }();
235 int y = [] { return 3; }();
238 void test_Members() {
242 template<typename P> void f(P) { }
244 struct TestNestedInstantiation {
245 void operator()() const {
252 void test_NestedInstantiation() {
253 TestNestedInstantiation()();