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