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