1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s | FileCheck %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc // CHECK: @_ZZNK7PR12917IJiiEE1nMUlvE_clEvE1n = linkonce_odr global i32 0 4f4a2713aSLionel Sambuc // CHECK: @_ZZZN7PR12917IJicdEEC1EicdEd_NKUlvE_clEvE1n = linkonce_odr global i32 0 5f4a2713aSLionel Sambuc // CHECK: @_ZZZN7PR12917IJicdEEC1EicdEd0_NKUlvE_clEvE1n = linkonce_odr global i32 0 6f4a2713aSLionel Sambuc // CHECK: @_ZZZN7PR12917IJicdEEC1EicdEd1_NKUlvE_clEvE1n = linkonce_odr global i32 0 7f4a2713aSLionel Sambuc 8f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr void @_Z11inline_funci inline_func(int n)9f4a2713aSLionel Sambucinline void inline_func(int n) { 10f4a2713aSLionel Sambuc // CHECK: call i32 @_ZZ11inline_funciENKUlvE_clEv 11f4a2713aSLionel Sambuc int i = []{ return 1; }(); 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc // CHECK: call i32 @_ZZ11inline_funciENKUlvE0_clEv 14f4a2713aSLionel Sambuc int j = [=] { return n + i; }(); 15f4a2713aSLionel Sambuc 16f4a2713aSLionel Sambuc // CHECK: call double @_ZZ11inline_funciENKUlvE1_clEv 17f4a2713aSLionel Sambuc int k = [=] () -> double { return n + i; }(); 18f4a2713aSLionel Sambuc 19f4a2713aSLionel Sambuc // CHECK: call i32 @_ZZ11inline_funciENKUliE_clEi 20f4a2713aSLionel Sambuc int l = [=] (int x) -> int { return x + i; }(n); 21f4a2713aSLionel Sambuc 22f4a2713aSLionel Sambuc int inner(int i = []{ return 17; }()); 23f4a2713aSLionel Sambuc // CHECK: call i32 @_ZZ11inline_funciENKUlvE2_clEv 24f4a2713aSLionel Sambuc // CHECK-NEXT: call i32 @_Z5inneri 25f4a2713aSLionel Sambuc inner(); 26f4a2713aSLionel Sambuc 27f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 28f4a2713aSLionel Sambuc } 29f4a2713aSLionel Sambuc call_inline_func()30f4a2713aSLionel Sambucvoid call_inline_func() { 31f4a2713aSLionel Sambuc inline_func(17); 32f4a2713aSLionel Sambuc } 33f4a2713aSLionel Sambuc 34f4a2713aSLionel Sambuc struct S { __anon2adca4220602S35f4a2713aSLionel Sambuc void f(int = []{return 1;}() __anon2adca4220702S36f4a2713aSLionel Sambuc + []{return 2;}(), __anon2adca4220802S37f4a2713aSLionel Sambuc int = []{return 3;}()); 38f4a2713aSLionel Sambuc void g(int, int); 39f4a2713aSLionel Sambuc }; 40f4a2713aSLionel Sambuc g(int i=[]{}(),int j=[]{}())41f4a2713aSLionel Sambucvoid S::g(int i = []{return 1;}(), __anon2adca4220a02null42f4a2713aSLionel Sambuc int j = []{return 2; }()) {} 43f4a2713aSLionel Sambuc 44f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z6test_S1S test_S(S s)45f4a2713aSLionel Sambucvoid test_S(S s) { 46f4a2713aSLionel Sambuc // CHECK: call i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv 47f4a2713aSLionel Sambuc // CHECK-NEXT: call i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv 48f4a2713aSLionel Sambuc // CHECK-NEXT: add nsw i32 49f4a2713aSLionel Sambuc // CHECK-NEXT: call i32 @_ZZN1S1fEiiEd_NKUlvE_clEv 50f4a2713aSLionel Sambuc // CHECK-NEXT: call void @_ZN1S1fEii 51f4a2713aSLionel Sambuc s.f(); 52f4a2713aSLionel Sambuc 53f4a2713aSLionel Sambuc // NOTE: These manglings don't actually matter that much, because 54f4a2713aSLionel Sambuc // the lambdas in the default arguments of g() won't be seen by 55f4a2713aSLionel Sambuc // multiple translation units. We check them mainly to ensure that they don't 56f4a2713aSLionel Sambuc // get the special mangling for lambdas in in-class default arguments. 57f4a2713aSLionel Sambuc // CHECK: call i32 @"_ZNK1S3$_0clEv" 58f4a2713aSLionel Sambuc // CHECK-NEXT: call i32 @"_ZNK1S3$_1clEv" 59f4a2713aSLionel Sambuc // CHECK-NEXT: call void @_ZN1S1gEi 60f4a2713aSLionel Sambuc s.g(); 61f4a2713aSLionel Sambuc 62f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 63f4a2713aSLionel Sambuc } 64f4a2713aSLionel Sambuc 65f4a2713aSLionel Sambuc // Check the linkage of the lambda call operators used in test_S. 66f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv 67f4a2713aSLionel Sambuc // CHECK: ret i32 1 68f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv 69f4a2713aSLionel Sambuc // CHECK: ret i32 2 70f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZZN1S1fEiiEd_NKUlvE_clEv 71f4a2713aSLionel Sambuc // CHECK: ret i32 3 72f4a2713aSLionel Sambuc // CHECK-LABEL: define internal i32 @"_ZNK1S3$_0clEv" 73f4a2713aSLionel Sambuc // CHECK: ret i32 1 74f4a2713aSLionel Sambuc // CHECK-LABEL: define internal i32 @"_ZNK1S3$_1clEv" 75f4a2713aSLionel Sambuc // CHECK: ret i32 2 76f4a2713aSLionel Sambuc 77f4a2713aSLionel Sambuc template<typename T> 78f4a2713aSLionel Sambuc struct ST { __anon2adca4220b02ST79f4a2713aSLionel Sambuc void f(T = []{return T() + 1;}() __anon2adca4220c02ST80f4a2713aSLionel Sambuc + []{return T() + 2;}(), __anon2adca4220d02ST81f4a2713aSLionel Sambuc T = []{return T(3);}()); 82f4a2713aSLionel Sambuc }; 83f4a2713aSLionel Sambuc 84f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z7test_ST2STIdE test_ST(ST<double> st)85f4a2713aSLionel Sambucvoid test_ST(ST<double> st) { 86f4a2713aSLionel Sambuc // CHECK: call double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv 87f4a2713aSLionel Sambuc // CHECK-NEXT: call double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv 88f4a2713aSLionel Sambuc // CHECK-NEXT: fadd double 89f4a2713aSLionel Sambuc // CHECK-NEXT: call double @_ZZN2STIdE1fEddEd_NKUlvE_clEv 90f4a2713aSLionel Sambuc // CHECK-NEXT: call void @_ZN2STIdE1fEdd 91f4a2713aSLionel Sambuc st.f(); 92f4a2713aSLionel Sambuc 93f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 94f4a2713aSLionel Sambuc } 95f4a2713aSLionel Sambuc 96f4a2713aSLionel Sambuc // Check the linkage of the lambda call operators used in test_ST. 97f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv 98f4a2713aSLionel Sambuc // CHECK: ret double 1 99f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv 100f4a2713aSLionel Sambuc // CHECK: ret double 2 101f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr double @_ZZN2STIdE1fEddEd_NKUlvE_clEv 102f4a2713aSLionel Sambuc // CHECK: ret double 3 103f4a2713aSLionel Sambuc 104f4a2713aSLionel Sambuc template<typename T> 105f4a2713aSLionel Sambuc struct StaticMembers { 106f4a2713aSLionel Sambuc static T x; 107f4a2713aSLionel Sambuc static T y; 108f4a2713aSLionel Sambuc static T z; 109f4a2713aSLionel Sambuc static int (*f)(); 110f4a2713aSLionel Sambuc }; 111f4a2713aSLionel Sambuc 112f4a2713aSLionel Sambuc template<typename T> int accept_lambda(T); 113f4a2713aSLionel Sambuc 114f4a2713aSLionel Sambuc template<typename T> __anon2adca4220f02null115f4a2713aSLionel SambucT StaticMembers<T>::x = []{return 1;}() + []{return 2;}(); 116f4a2713aSLionel Sambuc 117f4a2713aSLionel Sambuc template<typename T> __anon2adca4221002null118f4a2713aSLionel SambucT StaticMembers<T>::y = []{return 3;}(); 119f4a2713aSLionel Sambuc 120f4a2713aSLionel Sambuc template<typename T> __anon2adca4221102null121f4a2713aSLionel SambucT StaticMembers<T>::z = accept_lambda([]{return 4;}); 122f4a2713aSLionel Sambuc 123f4a2713aSLionel Sambuc template<typename T> __anon2adca4221202null124f4a2713aSLionel Sambucint (*StaticMembers<T>::f)() = []{return 5;}; 125f4a2713aSLionel Sambuc 126f4a2713aSLionel Sambuc // CHECK-LABEL: define internal void @__cxx_global_var_init() 127f4a2713aSLionel Sambuc // CHECK: call i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv 128f4a2713aSLionel Sambuc // CHECK-NEXT: call i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv 129f4a2713aSLionel Sambuc // CHECK-NEXT: add nsw 130f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv 131f4a2713aSLionel Sambuc // CHECK: ret i32 1 132f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv 133f4a2713aSLionel Sambuc // CHECK: ret i32 2 134f4a2713aSLionel Sambuc template float StaticMembers<float>::x; 135f4a2713aSLionel Sambuc 136f4a2713aSLionel Sambuc // CHECK-LABEL: define internal void @__cxx_global_var_init1() 137f4a2713aSLionel Sambuc // CHECK: call i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv 138f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv 139f4a2713aSLionel Sambuc // CHECK: ret i32 3 140f4a2713aSLionel Sambuc template float StaticMembers<float>::y; 141f4a2713aSLionel Sambuc 142f4a2713aSLionel Sambuc // CHECK-LABEL: define internal void @__cxx_global_var_init2() 143f4a2713aSLionel Sambuc // CHECK: call i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_ 144f4a2713aSLionel Sambuc // CHECK: declare i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_() 145f4a2713aSLionel Sambuc template float StaticMembers<float>::z; 146f4a2713aSLionel Sambuc 147f4a2713aSLionel Sambuc // CHECK-LABEL: define internal void @__cxx_global_var_init3() 148f4a2713aSLionel Sambuc // CHECK: call {{.*}} @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv 149f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 ()* @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv 150f4a2713aSLionel Sambuc template int (*StaticMembers<float>::f)(); 151f4a2713aSLionel Sambuc 152f4a2713aSLionel Sambuc // CHECK-LABEL: define internal void @__cxx_global_var_init4 153f4a2713aSLionel Sambuc // CHECK: call i32 @"_ZNK13StaticMembersIdE3$_2clEv" 154f4a2713aSLionel Sambuc // CHECK-LABEL: define internal i32 @"_ZNK13StaticMembersIdE3$_2clEv" 155f4a2713aSLionel Sambuc // CHECK: ret i32 42 __anon2adca4221302null156f4a2713aSLionel Sambuctemplate<> double StaticMembers<double>::z = []{return 42; }(); 157f4a2713aSLionel Sambuc 158f4a2713aSLionel Sambuc template<typename T> __anon2adca4221402null159f4a2713aSLionel Sambucvoid func_template(T = []{ return T(); }()); 160f4a2713aSLionel Sambuc 161f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z17use_func_templatev() use_func_template()162f4a2713aSLionel Sambucvoid use_func_template() { 163f4a2713aSLionel Sambuc // CHECK: call i32 @"_ZZ13func_templateIiEvT_ENK3$_3clEv" 164f4a2713aSLionel Sambuc func_template<int>(); 165f4a2713aSLionel Sambuc } 166f4a2713aSLionel Sambuc 167f4a2713aSLionel Sambuc 168f4a2713aSLionel Sambuc template<typename...T> struct PR12917 { __anon2adca4221502PR12917169f4a2713aSLionel Sambuc PR12917(T ...t = []{ static int n = 0; return ++n; }()); 170f4a2713aSLionel Sambuc 171f4a2713aSLionel Sambuc static int n[3]; 172f4a2713aSLionel Sambuc }; 173f4a2713aSLionel Sambuc template<typename...T> int PR12917<T...>::n[3] = { __anon2adca4221602null174f4a2713aSLionel Sambuc []{ static int n = 0; return ++n; }() 175f4a2713aSLionel Sambuc }; 176f4a2713aSLionel Sambuc 177f4a2713aSLionel Sambuc // CHECK: call i32 @_ZZN7PR12917IJicdEEC1EicdEd1_NKUlvE_clEv( 178f4a2713aSLionel Sambuc // CHECK: call i32 @_ZZN7PR12917IJicdEEC1EicdEd0_NKUlvE_clEv( 179f4a2713aSLionel Sambuc // CHECK: call i32 @_ZZN7PR12917IJicdEEC1EicdEd_NKUlvE_clEv( 180f4a2713aSLionel Sambuc // CHECK: call void @_ZN7PR12917IJicdEEC1Eicd( 181f4a2713aSLionel Sambuc PR12917<int, char, double> pr12917; 182f4a2713aSLionel Sambuc int *pr12917_p = PR12917<int, int>::n; 183f4a2713aSLionel Sambuc 184f4a2713aSLionel Sambuc namespace std { 185f4a2713aSLionel Sambuc struct type_info; 186f4a2713aSLionel Sambuc } 187f4a2713aSLionel Sambuc namespace PR12123 { 188f4a2713aSLionel Sambuc struct A { virtual ~A(); } g; 189f4a2713aSLionel Sambuc struct B { __anon2adca4221702PR12123::B190f4a2713aSLionel Sambuc void f(const std::type_info& x = typeid([]()->A& { return g; }())); 191f4a2713aSLionel Sambuc void h(); 192f4a2713aSLionel Sambuc }; h()193f4a2713aSLionel Sambuc void B::h() { f(); } 194f4a2713aSLionel Sambuc } 195*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define linkonce_odr dereferenceable({{[0-9]+}}) %"struct.PR12123::A"* @_ZZN7PR121231B1fERKSt9type_infoEd_NKUlvE_clEv 196f4a2713aSLionel Sambuc 197f4a2713aSLionel Sambuc namespace PR12808 { 198f4a2713aSLionel Sambuc template <typename> struct B { 199f4a2713aSLionel Sambuc int a; BPR12808::B200f4a2713aSLionel Sambuc template <typename L> constexpr B(L&& x) : a(x()) { } 201f4a2713aSLionel Sambuc }; b(int)202f4a2713aSLionel Sambuc template <typename> void b(int) { 203f4a2713aSLionel Sambuc [&]{ (void)B<int>([&]{ return 1; }); }(); 204f4a2713aSLionel Sambuc } f()205f4a2713aSLionel Sambuc void f() { 206f4a2713aSLionel Sambuc b<int>(1); 207f4a2713aSLionel Sambuc } 208f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr void @_ZZN7PR128081bIiEEviENKUlvE_clEv 209f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZZZN7PR128081bIiEEviENKUlvE_clEvENKUlvE_clEv 210f4a2713aSLionel Sambuc } 211f4a2713aSLionel Sambuc 212f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr void @_Z1fIZZNK23TestNestedInstantiationclEvENKUlvE_clEvEUlvE_EvT_ 213f4a2713aSLionel Sambuc 214f4a2713aSLionel Sambuc struct Members { __anon2adca4221b02Members215f4a2713aSLionel Sambuc int x = [] { return 1; }() + [] { return 2; }(); __anon2adca4221c02Members216f4a2713aSLionel Sambuc int y = [] { return 3; }(); 217f4a2713aSLionel Sambuc }; 218f4a2713aSLionel Sambuc test_Members()219f4a2713aSLionel Sambucvoid test_Members() { 220f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr void @_ZN7MembersC2Ev 221f4a2713aSLionel Sambuc // CHECK: call i32 @_ZNK7Members1xMUlvE_clEv 222f4a2713aSLionel Sambuc // CHECK-NEXT: call i32 @_ZNK7Members1xMUlvE0_clE 223f4a2713aSLionel Sambuc // CHECK-NEXT: add nsw i32 224f4a2713aSLionel Sambuc // CHECK: call i32 @_ZNK7Members1yMUlvE_clEv 225f4a2713aSLionel Sambuc Members members; 226f4a2713aSLionel Sambuc // CHECK: ret void 227f4a2713aSLionel Sambuc } 228f4a2713aSLionel Sambuc f(P)229f4a2713aSLionel Sambuctemplate<typename P> void f(P) { } 230f4a2713aSLionel Sambuc 231f4a2713aSLionel Sambuc struct TestNestedInstantiation { operator ()TestNestedInstantiation232f4a2713aSLionel Sambuc void operator()() const { 233f4a2713aSLionel Sambuc []() -> void { 234f4a2713aSLionel Sambuc return f([]{}); 235f4a2713aSLionel Sambuc }(); 236f4a2713aSLionel Sambuc } 237f4a2713aSLionel Sambuc }; 238f4a2713aSLionel Sambuc test_NestedInstantiation()239f4a2713aSLionel Sambucvoid test_NestedInstantiation() { 240f4a2713aSLionel Sambuc TestNestedInstantiation()(); 241f4a2713aSLionel Sambuc } 242f4a2713aSLionel Sambuc 243f4a2713aSLionel Sambuc // Check the linkage of the lambdas used in test_Members. 244f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZNK7Members1xMUlvE_clEv 245f4a2713aSLionel Sambuc // CHECK: ret i32 1 246f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZNK7Members1xMUlvE0_clEv 247f4a2713aSLionel Sambuc // CHECK: ret i32 2 248f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZNK7Members1yMUlvE_clEv 249f4a2713aSLionel Sambuc // CHECK: ret i32 3 250f4a2713aSLionel Sambuc 251f4a2713aSLionel Sambuc // Check linkage of the various lambdas. 252f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE_clEv 253f4a2713aSLionel Sambuc // CHECK: ret i32 1 254f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE0_clEv 255f4a2713aSLionel Sambuc // CHECK: ret i32 256f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr double @_ZZ11inline_funciENKUlvE1_clEv 257f4a2713aSLionel Sambuc // CHECK: ret double 258f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUliE_clEi 259f4a2713aSLionel Sambuc // CHECK: ret i32 260f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE2_clEv 261f4a2713aSLionel Sambuc // CHECK: ret i32 17 262