373 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s -w | FileCheck %s2 3void side_effect();4 5// CHECK-LABEL: define linkonce_odr void @_Z11inline_funci6inline void inline_func(int n) {7 // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE_clEv8 int i = []{ return side_effect(), 1; }();9 10 // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE0_clEv11 int j = [=] { return n + i; }();12 13 // CHECK: call noundef double @_ZZ11inline_funciENKUlvE1_clEv14 int k = [=] () -> double { return n + i; }();15 16 // CHECK: call noundef i32 @_ZZ11inline_funciENKUliE_clEi17 int l = [=] (int x) -> int { return x + i; }(n);18 19 int inner(int i = []{ return side_effect(), 17; }());20 // CHECK: call noundef i32 @_ZZ11inline_funciENKUlvE2_clEv21 // CHECK-NEXT: call noundef i32 @_Z5inneri22 inner();23 24 // CHECK-NEXT: ret void25}26 27void call_inline_func() {28 inline_func(17);29}30 31// CHECK-LABEL: define linkonce_odr noundef ptr @_ZNK10inline_varMUlvE_clEv(32// CHECK: @_ZZNK10inline_varMUlvE_clEvE1n33inline auto inline_var = [] {34 static int n = 5;35 return &n;36};37 38int *use_inline_var = inline_var();39 40// CHECK-LABEL: define linkonce_odr noundef ptr @_ZNK12var_templateIiEMUlvE_clEv(41// CHECK: @_ZZNK12var_templateIiEMUlvE_clEvE1n42template<typename T> auto var_template = [] {43 static int n = 9;44 return &n;45};46 47int *use_var_template = var_template<int>();48 49// CHECK-LABEL: define {{.*}} @_Z29use_var_template_substitutionN12var_templateIiEMUlvE_ENS_IfEMUlvE_E50void use_var_template_substitution(decltype(var_template<int>), decltype(var_template<float>)) {}51 52struct S {53 void f(int = []{return side_effect(), 1;}()54 + []{return side_effect(), 2;}(),55 int = []{return side_effect(), 3;}());56 void g(int, int);57};58 59void S::g(int i = []{return side_effect(), 1;}(),60 int j = []{return side_effect(), 2; }()) {}61 62// CHECK-LABEL: define{{.*}} void @_Z6test_S1S63void test_S(S s) {64 // CHECK: call noundef i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv65 // CHECK-NEXT: call noundef i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv66 // CHECK-NEXT: add nsw i3267 // CHECK-NEXT: call noundef i32 @_ZZN1S1fEiiEd_NKUlvE_clEv68 // CHECK-NEXT: call void @_ZN1S1fEii69 s.f();70 71 // NOTE: These manglings don't actually matter that much, because72 // the lambdas in the default arguments of g() won't be seen by73 // 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 @_ZN1S1gEi78 s.g();79 80 // CHECK-NEXT: ret void81}82 83// Check the linkage of the lambda call operators used in test_S.84// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv85// CHECK: ret i32 186// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv87// CHECK: ret i32 288// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN1S1fEiiEd_NKUlvE_clEv89// CHECK: ret i32 390// CHECK-LABEL: define internal noundef i32 @"_ZNK1S3$_0clEv"91// CHECK: ret i32 192// CHECK-LABEL: define internal noundef i32 @"_ZNK1S3$_1clEv"93// CHECK: ret i32 294 95template<typename T>96struct ST {97 void f(T = []{return T() + 1;}()98 + []{return T() + 2;}(),99 T = []{return T(3);}());100};101 102// CHECK-LABEL: define{{.*}} void @_Z7test_ST2STIdE103void test_ST(ST<double> st) {104 // CHECK: call noundef double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv105 // CHECK-NEXT: call noundef double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv106 // CHECK-NEXT: fadd double107 // CHECK-NEXT: call noundef double @_ZZN2STIdE1fEddEd_NKUlvE_clEv108 // CHECK-NEXT: call void @_ZN2STIdE1fEdd109 st.f();110 111 // CHECK-NEXT: ret void112}113 114// Check the linkage of the lambda call operators used in test_ST.115// CHECK-LABEL: define linkonce_odr noundef double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv116// CHECK: ret double 1117// CHECK-LABEL: define linkonce_odr noundef double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv118// CHECK: ret double 2119// CHECK-LABEL: define linkonce_odr noundef double @_ZZN2STIdE1fEddEd_NKUlvE_clEv120// CHECK: ret double 3121 122template<typename T> 123struct StaticMembers {124 static T x;125 static T y;126 static T z;127 static int (*f)();128};129 130template<typename T> int accept_lambda(T);131 132template<typename T>133T StaticMembers<T>::x = []{return side_effect(), 1;}() + []{return side_effect(), 2;}();134 135template<typename T>136T StaticMembers<T>::y = []{return side_effect(), 3;}();137 138template<typename T>139T StaticMembers<T>::z = accept_lambda([]{return side_effect(), 4;});140 141template<typename T>142int (*StaticMembers<T>::f)() = (side_effect(), []{return side_effect(), 5;});143 144// CHECK-LABEL: define internal void @__cxx_global_var_init145// CHECK: call noundef i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv146// CHECK-NEXT: call noundef i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv147// CHECK-NEXT: add nsw148// CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv149// CHECK: ret i32 1150// CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv151// CHECK: ret i32 2152template float StaticMembers<float>::x;153 154// CHECK-LABEL: define internal void @__cxx_global_var_init155// CHECK: call noundef i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv156// CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv157// CHECK: ret i32 3158template float StaticMembers<float>::y;159 160// CHECK-LABEL: define internal void @__cxx_global_var_init161// CHECK: call noundef i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_162// CHECK: declare noundef i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_()163template float StaticMembers<float>::z;164 165// CHECK-LABEL: define internal void @__cxx_global_var_init166// CHECK: call {{.*}} @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv167// CHECK-LABEL: define linkonce_odr noundef ptr @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv168template int (*StaticMembers<float>::f)();169 170// CHECK-LABEL: define internal void @__cxx_global_var_init171// CHECK: call noundef i32 @"_ZNK13StaticMembersIdE3$_2clEv"172// CHECK-LABEL: define internal noundef i32 @"_ZNK13StaticMembersIdE3$_2clEv"173// CHECK: ret i32 42174template<> double StaticMembers<double>::z = []{return side_effect(), 42; }();175 176template<typename T>177void func_template(T = []{ return T(); }());178 179// CHECK-LABEL: define{{.*}} void @_Z17use_func_templatev()180void use_func_template() {181 // CHECK: call noundef i32 @"_ZZ13func_templateIiEvT_ENK3$_0clEv"182 func_template<int>();183}184 185namespace std {186 struct type_info {187 bool before(const type_info &) const noexcept;188 };189}190namespace PR12123 {191 struct A { virtual ~A(); } g;192 struct C { virtual ~C(); } k;193 struct B {194 void f(const std::type_info& x = typeid([]()->A& { return g; }()));195 void h();196 void j(bool cond = typeid([]() -> A & { return g; }()).before(typeid([]() -> C & { return k; }())));197 };198 void B::h() { f(); j(); }199}200 201// CHECK-LABEL: define linkonce_odr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZZN7PR121231B1fERKSt9type_infoEd_NKUlvE_clEv202// CHECK-LABEL: define linkonce_odr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZZN7PR121231B1jEbEd_NKUlvE_clEv203// CHECK-LABEL: define linkonce_odr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZZN7PR121231B1jEbEd_NKUlvE0_clEv204 205// CHECK-LABEL: define {{.*}} @_Z{{[0-9]*}}testVarargsLambdaNumberingv(206inline 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; };211 return a() + b();212}213int k = testVarargsLambdaNumbering();214 215 216template<typename = int>217void ft1(int = [](int p = [] { return side_effect(), 42; } ()) {218 return p;219 } ());220void test_ft1() {221 // CHECK: call noundef i32 @"_ZZZ3ft1IiEviENK3$_0clEiEd_NKUlvE_clEv"222 // CHECK: call noundef i32 @"_ZZ3ft1IiEviENK3$_0clEi"223 ft1();224}225// CHECK-LABEL: define internal noundef i32 @"_ZZ3ft1IiEviENK3$_0clEi"226// CHECK-LABEL: define internal noundef i32 @"_ZZZ3ft1IiEviENK3$_0clEiEd_NKUlvE_clEv"227 228struct c1 {229 template<typename = int>230 void mft1(int = [](int p = [] { return side_effect(), 42; } ()) {231 return p;232 } ());233};234void test_c1_mft1() {235 // CHECK: call noundef i32 @_ZZZN2c14mft1IiEEviEd_NKUliE_clEiEd_NKUlvE_clEv236 // CHECK: call noundef i32 @_ZZN2c14mft1IiEEviEd_NKUliE_clEi237 c1{}.mft1();238}239// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN2c14mft1IiEEviEd_NKUliE_clEi240// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZN2c14mft1IiEEviEd_NKUliE_clEiEd_NKUlvE_clEv241 242template<typename = int>243struct ct1 {244 void mf1(int = [](int p = [] { return side_effect(), 42; } ()) {245 return p;246 } ());247 friend void ff(ct1, int = [](int p = [] { return side_effect(), 0; }()) { return p; }()) {}248};249void test_ct1_mft1() {250 // CHECK: call noundef i32 @_ZZZN3ct1IiE3mf1EiEd_NKUliE_clEiEd_NKUlvE_clEv251 // CHECK: call noundef i32 @_ZZN3ct1IiE3mf1EiEd_NKUliE_clEi252 ct1<>{}.mf1();253 // CHECK: call noundef i32 @_ZZZ2ff3ct1IiEiEd_NKUliE_clEiEd_NKUlvE_clEv254 // CHECK: call noundef i32 @_ZZ2ff3ct1IiEiEd_NKUliE_clEi255 ff(ct1<>{});256}257// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZN3ct1IiE3mf1EiEd_NKUliE_clEi258// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZN3ct1IiE3mf1EiEd_NKUliE_clEiEd_NKUlvE_clEv259// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ2ff3ct1IiEiEd_NKUliE_clEi260// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ2ff3ct1IiEiEd_NKUliE_clEiEd_NKUlvE_clEv261 262template<typename = int>263void ft2() {264 [](int p = [] { return side_effect(), 42; } ()) { return p; } ();265}266template void ft2<>();267// CHECK: call noundef i32 @_ZZZ3ft2IiEvvENKUliE_clEiEd_NKUlvE_clEv268// CHECK: call noundef i32 @_ZZ3ft2IiEvvENKUliE_clEi269// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ3ft2IiEvvENKUliE_clEi270// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ3ft2IiEvvENKUliE_clEiEd_NKUlvE_clEv271 272template<typename>273void ft3() {274 void f(int = []{ return side_effect(), 0; }());275 f();276}277template void ft3<int>();278// CHECK: call noundef i32 @"_ZZ1fiENK3$_0clEv"279// CHECK-LABEL: define internal noundef i32 @"_ZZ1fiENK3$_0clEv"280 281template<typename>282void ft4() {283 struct lc {284 void mf(int = []{ return side_effect(), 0; }()) {}285 };286 lc().mf();287}288template void ft4<int>();289// CHECK: call noundef i32 @_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv290// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZ3ft4IiEvvEN2lc2mfEiEd_NKUlvE_clEv291 292 293extern int ExternalVariable;294struct StaticInlineMember {295 static constexpr auto x = [] { return ExternalVariable; };296};297 298// CHECK-LABEL: define void @_Z23test_StaticInlineMemberv299// CHECK: call {{.*}} @_ZNK18StaticInlineMember1xMUlvE_clEv300void test_StaticInlineMember() {301 StaticInlineMember::x();302}303 304// Check linkage of the various lambdas.305// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE_clEv306// CHECK: ret i32 1307// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE0_clEv308// CHECK: ret i32309// CHECK-LABEL: define linkonce_odr noundef double @_ZZ11inline_funciENKUlvE1_clEv310// CHECK: ret double311// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUliE_clEi312// CHECK: ret i32313// CHECK-LABEL: define linkonce_odr noundef i32 @_ZZ11inline_funciENKUlvE2_clEv314// CHECK: ret i32 17315 316// CHECK-LABEL: define linkonce_odr void @_ZN7MembersC2Ev317// CHECK: call noundef i32 @_ZNK7Members1xMUlvE_clEv318// CHECK-NEXT: call noundef i32 @_ZNK7Members1xMUlvE0_clE319// CHECK-NEXT: add nsw i32320// CHECK: call noundef i32 @_ZNK7Members1yMUlvE_clEv321// CHECK: ret void322 323 324// Check the linkage of the lambdas used in test_Members.325// CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK7Members1xMUlvE_clEv326// CHECK: ret i32 1327// CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK7Members1xMUlvE0_clEv328// CHECK: ret i32 2329// CHECK-LABEL: define linkonce_odr noundef i32 @_ZNK7Members1yMUlvE_clEv330// CHECK: ret i32 3331 332// CHECK-LABEL: define linkonce_odr void @_Z1fIZZNK23TestNestedInstantiationclEvENKUlvE_clEvEUlvE_EvT_333 334 335namespace PR12808 {336 template <typename> struct B {337 int a;338 template <typename L> constexpr B(L&& x) : a(x()) { }339 };340 template <typename> void b(int) {341 [&]{ (void)B<int>([&]{ return side_effect(), 1; }); }();342 }343 void f() {344 b<int>(1);345 }346 // CHECK-LABEL: define linkonce_odr void @_ZZN7PR128081bIiEEviENKUlvE_clEv347 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZZZN7PR128081bIiEEviENKUlvE_clEvENKUlvE_clEv348}349 350 351struct Members {352 int x = [] { return side_effect(), 1; }() + [] { return side_effect(), 2; }();353 int y = [] { return side_effect(), 3; }();354};355 356void test_Members() {357 Members members;358}359 360template<typename P> void f(P) { }361 362struct TestNestedInstantiation {363 void operator()() const {364 []() -> void {365 return f([]{});366 }();367 }368};369 370void test_NestedInstantiation() {371 TestNestedInstantiation()();372}373