1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks -std=c++11 | FileCheck %s 2 struct X { }; 3 struct Y { }; 4 5 // CHECK: @unmangled_variable ={{.*}} global 6 // CHECK: @_ZN1N1iE ={{.*}} global 7 // CHECK: @_ZZN1N1fEiiE1b = internal global 8 // CHECK: @_ZZN1N1gEvE1a = internal global 9 // CHECK: @_ZGVZN1N1gEvE1a = internal global 10 11 //CHECK: @pr5966_i = external global 12 //CHECK: @_ZL8pr5966_j = internal global 13 14 // CHECK-LABEL: define{{.*}} zeroext i1 @_ZplRK1YRA100_P1X 15 bool operator+(const Y&, X* (&xs)[100]) { return false; } 16 17 // CHECK-LABEL: define{{.*}} void @_Z1f1s 18 typedef struct { int a; } s; 19 void f(s) { } 20 21 // CHECK-LABEL: define{{.*}} void @_Z1f1e 22 typedef enum { foo } e; 23 void f(e) { } 24 25 // CHECK-LABEL: define{{.*}} void @_Z1f1u 26 typedef union { int a; } u; 27 void f(u) { } 28 29 // CHECK-LABEL: define{{.*}} void @_Z1f1x 30 typedef struct { int a; } x,y; 31 void f(y) { } 32 33 // CHECK-LABEL: define{{.*}} void @_Z1fv 34 void f() { } 35 36 // CHECK-LABEL: define{{.*}} void @_ZN1N1fEv 37 namespace N { void f() { } } 38 39 // CHECK-LABEL: define{{.*}} void @_ZN1N1N1fEv 40 namespace N { namespace N { void f() { } } } 41 42 // CHECK-LABEL: define{{.*}} void @unmangled_function 43 extern "C" { namespace N { void unmangled_function() { } } } 44 45 extern "C" { namespace N { int unmangled_variable = 10; } } 46 47 namespace N { int i; } 48 49 namespace N { int f(int, int) { static int b; return b; } } 50 51 namespace N { int h(); void g() { static int a = h(); } } 52 53 // CHECK-LABEL: define{{.*}} void @_Z1fno 54 void f(__int128_t, __uint128_t) {} 55 56 template <typename T> struct S1 {}; 57 58 // CHECK-LABEL: define{{.*}} void @_Z1f2S1IiE 59 void f(S1<int>) {} 60 61 // CHECK-LABEL: define{{.*}} void @_Z1f2S1IdE 62 void f(S1<double>) {} 63 64 template <int N> struct S2 {}; 65 // CHECK-LABEL: define{{.*}} void @_Z1f2S2ILi100EE 66 void f(S2<100>) {} 67 68 // CHECK-LABEL: define{{.*}} void @_Z1f2S2ILin100EE 69 void f(S2<-100>) {} 70 71 template <bool B> struct S3 {}; 72 73 // CHECK-LABEL: define{{.*}} void @_Z1f2S3ILb1EE 74 void f(S3<true>) {} 75 76 // CHECK-LABEL: define{{.*}} void @_Z1f2S3ILb0EE 77 void f(S3<false>) {} 78 79 struct S; 80 81 // CHECK-LABEL: define{{.*}} void @_Z1fM1SKFvvE 82 void f(void (S::*)() const) {} 83 84 // CHECK-LABEL: define{{.*}} void @_Z1fM1SFvvE 85 void f(void (S::*)()) {} 86 87 // CHECK-LABEL: define{{.*}} void @_Z1fi 88 void f(const int) { } 89 90 template<typename T, typename U> void ft1(U u, T t) { } 91 92 template<typename T> void ft2(T t, void (*)(T), void (*)(T)) { } 93 94 template<typename T, typename U = S1<T> > struct S4 { }; 95 template<typename T> void ft3(S4<T>*) { } 96 97 namespace NS { 98 template<typename T> void ft1(T) { } 99 } 100 101 void g1() { 102 // CHECK: @_Z3ft1IidEvT0_T_ 103 ft1<int, double>(1, 0); 104 105 // CHECK: @_Z3ft2IcEvT_PFvS0_ES2_ 106 ft2<char>(1, 0, 0); 107 108 // CHECK: @_Z3ft3IiEvP2S4IT_2S1IS1_EE 109 ft3<int>(0); 110 111 // CHECK: @_ZN2NS3ft1IiEEvT_ 112 NS::ft1<int>(1); 113 } 114 115 // Expressions 116 template<int I> struct S5 { }; 117 118 template<int I> void ft4(S5<I>) { } 119 void g2() { 120 // CHECK: @_Z3ft4ILi10EEv2S5IXT_EE 121 ft4(S5<10>()); 122 123 // CHECK: @_Z3ft4ILi20EEv2S5IXT_EE 124 ft4(S5<20>()); 125 } 126 127 extern "C++" { 128 // CHECK: @_Z1hv 129 void h() {} 130 } 131 132 // PR5019 133 extern "C" { struct a { int b; }; } 134 135 // CHECK: @_Z1fP1a 136 int f(struct a *x) { 137 return x->b; 138 } 139 140 // PR5017 141 extern "C" { 142 struct Debug { 143 const Debug& operator<< (unsigned a) const { return *this; } 144 }; 145 Debug dbg; 146 // CHECK: @_ZNK5DebuglsEj 147 int main(void) { dbg << 32 ;} 148 } 149 150 template<typename T> struct S6 { 151 typedef int B; 152 }; 153 154 template<typename T> void ft5(typename S6<T>::B) { } 155 // CHECK: @_Z3ft5IiEvN2S6IT_E1BE 156 template void ft5<int>(int); 157 158 template<typename T> class A {}; 159 160 namespace NS { 161 template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; } 162 } 163 164 // CHECK: @_ZN2NSeqIcEEbRK1AIT_ES5_ 165 template bool NS::operator==(const ::A<char>&, const ::A<char>&); 166 167 namespace std { 168 template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; } 169 } 170 171 // CHECK: @_ZSteqIcEbRK1AIT_ES4_ 172 template bool std::operator==(const ::A<char>&, const ::A<char>&); 173 174 struct S { 175 typedef int U; 176 }; 177 178 template <typename T> typename T::U ft6(const T&) { return 0; } 179 180 // CHECK: @_Z3ft6I1SENT_1UERKS1_ 181 template int ft6<S>(const S&); 182 183 template<typename> struct __is_scalar_type { 184 enum { __value = 1 }; 185 }; 186 187 template<bool, typename> struct __enable_if { }; 188 189 template<typename T> struct __enable_if<true, T> { 190 typedef T __type; 191 }; 192 193 // PR5063 194 template<typename T> typename __enable_if<__is_scalar_type<T>::__value, void>::__type ft7() { } 195 196 // CHECK: @_Z3ft7IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 197 template void ft7<int>(); 198 // CHECK: @_Z3ft7IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 199 template void ft7<void*>(); 200 201 // PR5144 202 extern "C" { 203 void extern_f(void); 204 }; 205 206 // CHECK: @extern_f 207 void extern_f(void) { } 208 209 struct S7 { 210 S7(); 211 212 struct S { S(); }; 213 struct { 214 S s; 215 } a; 216 }; 217 218 // PR5139 219 // CHECK: @_ZN2S7C2Ev 220 // CHECK: @_ZN2S7Ut_C1Ev 221 // CHECK: @_ZN2S7C1Ev 222 S7::S7() {} 223 224 // PR5063 225 template<typename T> typename __enable_if<(__is_scalar_type<T>::__value), void>::__type ft8() { } 226 // CHECK: @_Z3ft8IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 227 template void ft8<int>(); 228 // CHECK: @_Z3ft8IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 229 template void ft8<void*>(); 230 231 // PR5796 232 namespace PR5796 { 233 template<typename> struct __is_scalar_type { 234 enum { __value = 0 }; 235 }; 236 237 template<bool, typename> struct __enable_if {}; 238 template<typename T> struct __enable_if<true, T> { typedef T __type; }; 239 template<typename T> 240 241 // CHECK-LABEL: define linkonce_odr void @_ZN6PR57968__fill_aIiEENS_11__enable_ifIXntsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 242 typename __enable_if<!__is_scalar_type<T>::__value, void>::__type __fill_a() { }; 243 244 void f() { __fill_a<int>(); } 245 } 246 247 namespace Expressions { 248 // Unary operators. 249 250 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i 251 template <int i> void f1(int (*)[(-i) + 2]) { }; 252 template void f1<1>(int (*)[1]); 253 254 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f2ILi1EEEvPApsT__i 255 template <int i> void f2(int (*)[+i]) { }; 256 template void f2<1>(int (*)[1]); 257 258 // Binary operators. 259 260 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i 261 template <int i> void f3(int (*)[i+i]) { }; 262 template void f3<1>(int (*)[2]); 263 264 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i 265 template <int i> void f4(int (*)[2 + i+i]) { }; 266 template void f4<1>(int (*)[4]); 267 268 // The ternary operator. 269 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i 270 template <bool b> void f4(int (*)[b ? 1 : 2]) { }; 271 template void f4<true>(int (*)[1]); 272 } 273 274 struct Ops { 275 Ops& operator+(const Ops&); 276 Ops& operator-(const Ops&); 277 Ops& operator&(const Ops&); 278 Ops& operator*(const Ops&); 279 280 void *v; 281 }; 282 283 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN3OpsplERKS_ 284 Ops& Ops::operator+(const Ops&) { return *this; } 285 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN3OpsmiERKS_ 286 Ops& Ops::operator-(const Ops&) { return *this; } 287 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN3OpsanERKS_ 288 Ops& Ops::operator&(const Ops&) { return *this; } 289 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN3OpsmlERKS_ 290 Ops& Ops::operator*(const Ops&) { return *this; } 291 292 // PR5861 293 namespace PR5861 { 294 template<bool> class P; 295 template<> class P<true> {}; 296 297 template<template <bool> class, bool> 298 struct Policy { }; 299 300 template<typename T, typename = Policy<P, true> > class Alloc 301 { 302 T *allocate(int, const void*) { return 0; } 303 }; 304 305 // CHECK-LABEL: define weak_odr noundef ptr @_ZN6PR58615AllocIcNS_6PolicyINS_1PELb1EEEE8allocateEiPKv 306 template class Alloc<char>; 307 } 308 309 // CHECK-LABEL: define{{.*}} void @_Z1fU13block_pointerFiiiE 310 void f(int (^)(int, int)) { } 311 312 void pr5966_foo() { 313 extern int pr5966_i; 314 pr5966_i = 0; 315 } 316 317 static int pr5966_j; 318 319 void pr5966_bar() { 320 pr5966_j = 0; 321 } 322 323 namespace test0 { 324 int ovl(int x); 325 char ovl(double x); 326 327 template <class T> void f(T, char (&buffer)[sizeof(ovl(T()))]) {} 328 329 void test0() { 330 char buffer[1]; 331 f(0.0, buffer); 332 } 333 // CHECK-LABEL: define{{.*}} void @_ZN5test05test0Ev() 334 // CHECK-LABEL: define linkonce_odr void @_ZN5test01fIdEEvT_RAszcl3ovlcvS1__EE_c( 335 336 void test1() { 337 char buffer[sizeof(int)]; 338 f(1, buffer); 339 } 340 // CHECK-LABEL: define{{.*}} void @_ZN5test05test1Ev() 341 // CHECK-LABEL: define linkonce_odr void @_ZN5test01fIiEEvT_RAszcl3ovlcvS1__EE_c( 342 343 template <class T> void g(char (&buffer)[sizeof(T() + 5.0f)]) {} 344 void test2() { 345 char buffer[sizeof(float)]; 346 g<float>(buffer); 347 } 348 // CHECK-LABEL: define linkonce_odr void @_ZN5test01gIfEEvRAszplcvT__ELf40a00000E_c( 349 350 template <class T> void h(char (&buffer)[sizeof(T() + 5.0)]) {} 351 void test3() { 352 char buffer[sizeof(double)]; 353 h<float>(buffer); 354 } 355 // CHECK-LABEL: define linkonce_odr void @_ZN5test01hIfEEvRAszplcvT__ELd4014000000000000E_c( 356 357 template <class T> void j(char (&buffer)[sizeof(T().buffer)]) {} 358 struct A { double buffer[128]; }; 359 void test4() { 360 char buffer[1024]; 361 j<A>(buffer); 362 } 363 // CHECK-LABEL: define linkonce_odr void @_ZN5test01jINS_1AEEEvRAszdtcvT__E6buffer_c( 364 365 template <class T> void k(char (&buffer)[sizeof(T() + 0.0f)]) {} 366 void test5() { 367 char buffer[sizeof(float)]; 368 k<float>(buffer); 369 } 370 // CHECK-LABEL: define linkonce_odr void @_ZN5test01kIfEEvRAszplcvT__ELf00000000E_c( 371 372 } 373 374 namespace test1 { 375 template<typename T> struct X { }; 376 template<template<class> class Y, typename T> void f(Y<T>) { } 377 // CHECK-LABEL: define weak_odr void @_ZN5test11fINS_1XEiEEvT_IT0_E 378 template void f(X<int>); 379 } 380 381 // CHECK-LABEL: define internal void @_ZL27functionWithInternalLinkagev() 382 static void functionWithInternalLinkage() { } 383 void g() { functionWithInternalLinkage(); } 384 385 namespace test2 { 386 template <class T> decltype(((T*) 0)->member) read_member(T& obj) { 387 return obj.member; 388 } 389 390 struct A { int member; } obj; 391 int test() { 392 return read_member(obj); 393 } 394 395 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN5test211read_memberINS_1AEEEDtptcvPT_Li0E6memberERS2_( 396 } 397 398 namespace test3 { 399 struct AmbiguousBase { int ab; }; 400 struct Path1 : AmbiguousBase { float p; }; 401 struct Path2 : AmbiguousBase { double p; }; 402 struct Derived : Path1, Path2 { }; 403 404 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN5test38get_ab_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E2abERS2_( 405 template <class T> decltype(((T*) 0)->Path1::ab) get_ab_1(T &ref) { return ref.Path1::ab; } 406 407 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN5test38get_ab_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E2abERS2_( 408 template <class T> decltype(((T*) 0)->Path2::ab) get_ab_2(T &ref) { return ref.Path2::ab; } 409 410 // CHECK-LABEL: define linkonce_odr noundef float @_ZN5test37get_p_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E1pERS2_( 411 template <class T> decltype(((T*) 0)->Path1::p) get_p_1(T &ref) { return ref.Path1::p; } 412 413 // CHECK-LABEL: define linkonce_odr noundef double @_ZN5test37get_p_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E1pERS2_( 414 template <class T> decltype(((T*) 0)->Path2::p) get_p_2(T &ref) { return ref.Path2::p; } 415 416 Derived obj; 417 void test() { 418 get_ab_1(obj); 419 get_ab_2(obj); 420 get_p_1(obj); 421 get_p_2(obj); 422 } 423 } 424 425 // CHECK-LABEL: define{{.*}} void @_ZN5test41gEPNS_3zedIXadL_ZNS_3foo3barEEEEE 426 namespace test4 { 427 struct foo { int bar; }; 428 template <int (foo::*)> 429 struct zed {}; 430 void g(zed<&foo::bar>*) 431 {} 432 } 433 // CHECK-LABEL: define{{.*}} void @_ZN5test51gEPNS_3zedIXadL_ZNS_3foo3barEEEEE 434 namespace test5 { 435 struct foo { static int bar; }; 436 template <int *> 437 struct zed {}; 438 void g(zed<&foo::bar>*) 439 {} 440 } 441 // CHECK-LABEL: define{{.*}} void @_ZN5test61gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE 442 namespace test6 { 443 struct foo { int bar(); }; 444 template <int (foo::*)()> 445 struct zed {}; 446 void g(zed<&foo::bar>*) 447 {} 448 } 449 // CHECK-LABEL: define{{.*}} void @_ZN5test71gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE 450 namespace test7 { 451 struct foo { static int bar(); }; 452 template <int (*f)()> 453 struct zed {}; 454 void g(zed<&foo::bar>*) 455 {} 456 } 457 // CHECK-LABEL: define weak_odr void @_ZN5test81AIL_ZNS_1B5valueEEE3incEv 458 namespace test8 { 459 template <int &counter> class A { void inc() { counter++; } }; 460 class B { public: static int value; }; 461 template class A<B::value>; 462 } 463 // CHECK: declare void @_ZN5test91fIiNS_3barEEEvRKNT0_3baz1XE 464 namespace test9 { 465 template<class T> 466 struct foo { 467 typedef T X; 468 }; 469 struct bar { 470 typedef foo<int> baz; 471 }; 472 template <class zaz, class zed> 473 void f(const typename zed::baz::X&); 474 void g() { 475 f<int, bar>( 0); 476 } 477 } 478 479 namespace test10 { 480 template <char P1> struct S {}; 481 template <char P2> void f(struct S<false ? 'a' : P2> ) {} 482 483 // CHECK-LABEL: define weak_odr void @_ZN6test101fILc3EEEvNS_1SIXquLb0ELc97ET_EEE( 484 template void f<(char) 3>(struct S<3>); 485 } 486 487 namespace test11 { 488 // CHECK: @_ZN6test111fEz 489 void f(...) { } 490 491 struct A { 492 void f(...); 493 }; 494 495 // CHECK: @_ZN6test111A1fEz 496 void A::f(...) { } 497 } 498 499 namespace test12 { 500 501 // CHECK: _ZN6test121fENS_1AILt33000EEE 502 template <unsigned short> struct A { }; 503 void f(A<33000>) { } 504 } 505 506 // PR7446 507 namespace test13 { 508 template <template <class> class T> class A {}; 509 template <class U> class B {}; 510 511 template <template<class> class T> void foo(const A<T> &a) {} 512 513 // CHECK-LABEL: define weak_odr void @_ZN6test133fooINS_1BEEEvRKNS_1AIT_EE( 514 template void foo(const A<B> &a); 515 } 516 517 namespace test14 { 518 extern "C" { 519 struct S { 520 static int a(), x; 521 }; 522 // CHECK-LABEL: define{{.*}} i32 @_ZN6test141S1aEv 523 // CHECK: load i32, ptr @_ZN6test141S1xE 524 int S::a() { return S::x; } 525 } 526 } 527 528 namespace test15 { 529 enum E { e = 3 }; 530 template <int I> struct S {}; 531 532 template <int I> void f(S<I + e>) {} 533 534 // CHECK-LABEL: define weak_odr void @_ZN6test151fILi7EEEvNS_1SIXplT_LNS_1EE3EEEE( 535 template void f<7>(S<7 + e>); 536 } 537 538 namespace test17 { 539 template <int N> struct A {}; 540 541 struct B { 542 static int foo(void); 543 }; 544 545 template <class T> A<sizeof(T::foo())> func(void); 546 547 // CHECK-LABEL: define{{.*}} void @_ZN6test174testEv() 548 // CHECK: call {{.*}} @_ZN6test174funcINS_1BEEENS_1AIXszclsrT_3fooEEEEv() 549 void test() { 550 func<B>(); 551 } 552 } 553 554 // PR7891 555 namespace test18 { 556 struct A { 557 int operator+(); 558 int operator-(); 559 int operator*(); 560 int operator&(); 561 }; 562 template <int (A::*)()> struct S {}; 563 564 template <typename T> void f(S<&T::operator+>) {} 565 template void f<A>(S<&A::operator+>); 566 567 template <typename T> void f(S<&T::operator- >) {} 568 template void f<A>(S<&A::operator- >); 569 570 template <typename T> void f(S<&T::operator*>) {} 571 template void f<A>(S<&A::operator*>); 572 573 template <typename T> void f(S<&T::operator&>) {} 574 template void f<A>(S<&A::operator&>); 575 576 // CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onplEEE 577 // CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onmiEEE 578 // CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onmlEEE 579 // CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onanEEE 580 } 581 582 namespace test19 { 583 struct A { 584 template <typename T> int f(); 585 int operator+(); 586 operator int(); 587 template <typename T> int operator-(); 588 }; 589 590 template <int (A::*)()> struct S {}; 591 592 template <typename T> void g (S<&T::template f<int> >) {} 593 template <typename T> void g (S<&T::operator+ >) {} 594 template <typename T> void g (S<&T::operator int>) {} 595 template <typename T> void g (S<&T::template operator- <double> >) {} 596 597 // CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_1fIiEEEE( 598 template void g<A>(S<&A::f<int> >); 599 // CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_onplEEE( 600 template void g<A>(S<&A::operator+>); 601 // CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_oncviEEE( 602 template void g<A>(S<&A::operator int>); 603 // CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_onmiIdEEEE( 604 template void g<A>(S<&A::operator-<double> >); 605 } 606 607 namespace test20 { 608 template <class T> T *f(const T&); 609 template <class T> T *f(T*); 610 611 // CHECK-LABEL: define weak_odr void @_ZN6test205test0IiEEvDTcl1fIPT_ELi0EEE( 612 template <class T> void test0(decltype(f<T*>(0))) {} 613 template void test0<int>(decltype(f<int*>(0))); 614 615 // CHECK-LABEL: define weak_odr void @_ZN6test205test1IiEEvDTcl1fIEcvT__EEE( 616 template <class T> void test1(decltype(f<>(T()))) {} 617 template void test1<int>(decltype(f<>(int()))); 618 } 619 620 namespace test21 { 621 // CHECK-LABEL: define{{.*}} void @_ZN6test2112vla_arg_funcEiPA_i( 622 void vla_arg_func(int X, int a[X][X]) {} 623 } 624 625 namespace test22 { 626 // CHECK-LABEL: define{{.*}} void @_ZN6test221fEDn( 627 void f(decltype(nullptr)) { } 628 } 629 630 namespace test23 { 631 typedef void * const vpc; 632 633 // CHECK-LABEL: define{{.*}} void @_ZN6test231fERA10_KPv( 634 void f(vpc (&)[10]) {} 635 636 typedef vpc vpca5[5]; 637 void f(vpca5 volatile (&)[10]) {} 638 // CHECK-LABEL: define{{.*}} void @_ZN6test231fERA10_A5_VKPv( 639 } 640 641 namespace test24 { 642 void test0() { 643 extern int foo(); 644 // CHECK: call noundef i32 @_ZN6test243fooEv() 645 foo(); 646 } 647 648 static char bar() { return 0; } 649 void test1() { 650 // CHECK: call noundef signext i8 @_ZN6test24L3barEv() 651 bar(); 652 } 653 } 654 655 namespace test25 { 656 template <void (*fn)()> struct A { 657 static void call() { fn(); } 658 }; 659 void foo(); 660 void test() { 661 // CHECK: call void @_ZN6test251AIXadL_ZNS_3fooEvEEE4callEv() 662 A<foo>::call(); 663 } 664 } 665 666 namespace test26 { 667 template <template <class> class T> void foo(decltype(T<float>::object) &object) {} 668 669 template <class T> struct holder { static T object; }; 670 671 void test() { 672 float f; 673 674 // CHECK: call void @_ZN6test263fooINS_6holderEEEvRDtsrT_IfE6objectE( 675 foo<holder>(f); 676 } 677 } 678 679 namespace test27 { 680 struct A { 681 struct inner { 682 float object; 683 }; 684 685 float meth(); 686 }; 687 typedef A Alias; 688 689 template <class T> void a(decltype(T::inner::object) &object) {} 690 template <class T> void b(decltype(T().Alias::meth()) &object) {} 691 692 void test() { 693 float f; 694 // CHECK: call void @_ZN6test271aINS_1AEEEvRDtsrNT_5innerE6objectE( 695 a<A>(f); 696 // CHECK: call void @_ZN6test271bINS_1AEEEvRDTcldtcvT__Esr5AliasE4methEE( 697 b<A>(f); 698 } 699 } 700 701 // An injected class name type in a unresolved-name. 702 namespace test28 { 703 template <class T> struct A { 704 enum { bit }; 705 }; 706 707 template <class T> void foo(decltype(A<T>::A::bit) x); 708 709 void test() { 710 foo<char>(A<char>::bit); 711 // CHECK: call void @_ZN6test283fooIcEEvDtsr1AIT_E1AE3bitE( 712 } 713 } 714 715 // An enclosing template type parameter in an unresolved-name. 716 namespace test29 { 717 template <class T> struct A { 718 template <class U> static void foo(decltype(T::fn(U())) x); 719 }; 720 struct B { static int fn(int); static long fn(long); }; 721 722 void test() { 723 A<B>::foo<int>(0); 724 // CHECK: call void @_ZN6test291AINS_1BEE3fooIiEEvDTclsrS1_2fncvT__EEE( 725 } 726 } 727 728 // An enclosing template template parameter in an unresolved-name. 729 namespace test30 { 730 template <template <class> class T> struct A { 731 template <class U> static void foo(decltype(T<U>::fn()) x); 732 }; 733 template <class T> struct B { static T fn(); }; 734 735 void test() { 736 A<B>::foo<int>(0); 737 // CHECK: call void @_ZN6test301AINS_1BEE3fooIiEEvDTclsrS1_IT_EE2fnEE( 738 } 739 } 740 741 namespace test31 { // instantiation-dependent mangling of decltype 742 int x; 743 template<class T> auto f1(T p)->decltype(x) { return 0; } 744 // The return type in the mangling of the template signature 745 // is encoded as "i". 746 template<class T> auto f2(T p)->decltype(p) { return 0; } 747 // The return type in the mangling of the template signature 748 // is encoded as "Dtfp_E". 749 void g(int); 750 template<class T> auto f3(T p)->decltype(g(p)) {} 751 752 // CHECK-LABEL: define weak_odr noundef i32 @_ZN6test312f1IiEEiT_( 753 template int f1(int); 754 // CHECK-LABEL: define weak_odr noundef i32 @_ZN6test312f2IiEEDtfp_ET_ 755 template int f2(int); 756 // CHECK-LABEL: define weak_odr void @_ZN6test312f3IiEEDTcl1gfp_EET_ 757 template void f3(int); 758 } 759 760 // PR10205 761 namespace test32 { 762 template<typename T, int=T::value> struct A { 763 typedef int type; 764 }; 765 struct B { enum { value = 4 }; }; 766 767 template <class T> typename A<T>::type foo() { return 0; } 768 void test() { 769 foo<B>(); 770 // CHECK: call noundef i32 @_ZN6test323fooINS_1BEEENS_1AIT_XsrS3_5valueEE4typeEv() 771 } 772 } 773 774 namespace test33 { 775 template <class T> struct X { 776 enum { value = T::value }; 777 }; 778 779 template<typename T, int=X<T>::value> struct A { 780 typedef int type; 781 }; 782 struct B { enum { value = 4 }; }; 783 784 template <class T> typename A<T>::type foo() { return 0; } 785 786 void test() { 787 foo<B>(); 788 // CHECK: call noundef i32 @_ZN6test333fooINS_1BEEENS_1AIT_Xsr1XIS3_EE5valueEE4typeEv() 789 } 790 } 791 792 namespace test34 { 793 // Mangling for instantiation-dependent decltype expressions. 794 template<typename T> 795 void f(decltype(sizeof(decltype(T() + T())))) {} 796 797 // CHECK-LABEL: define weak_odr void @_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE 798 template void f<int>(decltype(sizeof(1))); 799 800 // Mangling for non-instantiation-dependent sizeof expressions. 801 template<unsigned N> 802 void f2(int (&)[N + sizeof(int*)]) {} 803 804 // CHECK-LABEL: define weak_odr void @_ZN6test342f2ILj4EEEvRAplT_Lm8E_i 805 template void f2<4>(int (&)[4 + sizeof(int*)]); 806 807 // Mangling for non-instantiation-dependent sizeof expressions 808 // involving an implicit conversion of the result of the sizeof. 809 template<unsigned long long N> 810 void f3(int (&)[N + sizeof(int*)]) {} 811 812 // CHECK-LABEL: define weak_odr void @_ZN6test342f3ILy4EEEvRAplT_Ly8E_i 813 template void f3<4>(int (&)[4 + sizeof(int*)]); 814 815 // Mangling for instantiation-dependent sizeof() expressions as 816 // template arguments. 817 template<unsigned> struct A { }; 818 819 template<typename T> void f4(::test34::A<sizeof(sizeof(decltype(T() + T())))>) { } 820 821 // CHECK-LABEL: define weak_odr void @_ZN6test342f4IiEEvNS_1AIXszstDTplcvT__EcvS2__EEEEE 822 template void f4<int>(A<sizeof(sizeof(int))>); 823 } 824 825 namespace test35 { 826 // Dependent operator names of unknown arity. 827 struct A { 828 template <typename U> A operator+(U) const; 829 }; 830 831 template<typename T> 832 void f1(decltype(sizeof(&T::template operator+<int>))) {} 833 834 // CHECK-LABEL: define weak_odr void @_ZN6test352f1INS_1AEEEvDTszadsrT_onplIiEE 835 template void f1<A>(__SIZE_TYPE__); 836 } 837 838 namespace test36 { 839 template<unsigned> struct A { }; 840 841 template<typename ...Types> 842 auto f1(Types... values) -> A<sizeof...(values)> { return {}; } 843 844 // CHECK: define weak_odr {{.*}} @_ZN6test362f1IJifEEENS_1AIXsZfp_EEEDpT_ 845 template A<2> f1(int, float); 846 } 847 848 namespace test37 { 849 struct foo { 850 struct { 851 } a; 852 typedef struct { } b; 853 typedef struct { } *c; 854 struct { 855 } d; 856 }; 857 template<typename T> void func(T) { } 858 void test() { 859 // CHECK-LABEL: define linkonce_odr void @_ZN6test374funcINS_3fooUt_EEEvT_ 860 func(foo().a); 861 // CHECK-LABEL: define linkonce_odr void @_ZN6test374funcINS_3fooUt0_EEEvT_ 862 func(*foo::c()); 863 // CHECK-LABEL: define linkonce_odr void @_ZN6test374funcINS_3fooUt1_EEEvT_ 864 func(foo().d); 865 } 866 } 867 868 // CHECK-LABEL: define{{.*}} void @_Z6ASfuncPU3AS3i 869 void ASfunc(__attribute__((address_space(3))) int* x) {} 870 871 namespace test38 { 872 // CHECK-LABEL: define linkonce_odr void @_ZN6test384funcINS_3fooUt_EEEvT_ 873 typedef struct { 874 struct { 875 } a; 876 } foo; 877 878 template <typename T> void func(T) {} 879 void test() { func(foo().a); } 880 } 881 882 namespace test39 { 883 // CHECK-LABEL: define internal void @"_ZN6test394funcINS_3$_03$_1EEEvT_" 884 typedef struct { 885 struct {} a; 886 } *foo; 887 template<typename T> void func(T) {} 888 void test() { 889 foo x; 890 func(x->a); 891 } 892 } 893 894 namespace test40 { 895 // CHECK: ptr {{.*}} @_ZZN6test401fEvE1a_0 896 void h(int&); 897 inline void f() { 898 if (0) { 899 static int a; 900 } 901 static int a; 902 h(a); 903 }; 904 void g() { f(); } 905 } 906 907 namespace test41 { 908 // CHECK: define linkonce_odr void @_ZN6test414funcINS_1XEEEvNS_3fooILi20ES1_EE 909 template <int i, class T> struct foo { 910 template <class T2 = T> friend void func(foo x) {} 911 }; 912 913 struct X {}; 914 915 void g() { func(foo<20, X>()); } 916 } 917 918 namespace test42 { 919 // CHECK: define linkonce_odr void @_ZN6test424funcINS_1XEEEvNS_3fooILi20ES1_EE 920 template <int i, template <class> class T> struct foo { 921 template <template <class> class T2 = T> friend void func(foo x) {} 922 }; 923 924 template <class V> struct X { 925 }; 926 927 void g() { func(foo<20, X>()); } 928 } 929 930 namespace test43 { 931 // CHECK-LABEL: define{{.*}} void @_ZN6test431gEPNS_3zedIXadL_ZNS_3fooUt_3barEEEEE 932 struct foo { union { int bar; }; }; 933 template <int (foo::*)> 934 struct zed {}; 935 void g(zed<&foo::bar>*) 936 {} 937 } 938 939 namespace test44 { 940 struct foo { void bar() __restrict { }; } obj; 941 942 void f() { 943 obj.bar(); 944 } 945 // CHECK-LABEL: define linkonce_odr void @_ZN6test443foo3barEv(ptr {{[^,]*}} %this) 946 } 947 948 namespace test45 { 949 struct S { 950 enum e {}; 951 }; 952 template <typename T> 953 void f(enum T::e *) {} 954 template void f<S>(S::e *); 955 // CHECK-LABEL: define weak_odr void @_ZN6test451fINS_1SEEEvPTeNT_1eE(ptr noundef %0) 956 } 957 958 namespace test46 { 959 struct S { 960 struct s {}; 961 }; 962 template <typename T> 963 void f(struct T::s *) {} 964 template void f<S>(S::s *); 965 // CHECK-LABEL: define weak_odr void @_ZN6test461fINS_1SEEEvPTsNT_1sE(ptr noundef %0) 966 } 967 968 namespace test47 { 969 struct S { 970 class c {}; 971 }; 972 template <typename T> 973 void f(class T::c *) {} 974 template void f<S>(S::c *); 975 // CHECK-LABEL: define weak_odr void @_ZN6test471fINS_1SEEEvPTsNT_1cE(ptr noundef %0) 976 } 977 978 namespace test48 { 979 struct S { 980 union u {}; 981 }; 982 template <typename T> 983 void f(union T::u *) {} 984 template void f<S>(S::u *); 985 // CHECK-LABEL: define weak_odr void @_ZN6test481fINS_1SEEEvPTuNT_1uE(ptr noundef %0) 986 } 987 988 namespace test49 { 989 template <int> 990 struct S {}; 991 992 template <template <int> class T> 993 T<3> fin(T<3>); 994 995 auto v = fin<S>; 996 // CHECK-LABEL: declare void @_ZN6test493finINS_1SEEET_ILi3EES3_() 997 } 998 999 namespace test50 { 1000 template <int> 1001 struct S {}; 1002 1003 template <template <int> class T> 1004 T<3> fin(T<4>); 1005 1006 auto v = fin<S>; 1007 // CHECK-LABEL: declare void @_ZN6test503finINS_1SEEET_ILi3EES2_ILi4EE() 1008 } 1009 1010 namespace test51 { 1011 template <typename T> 1012 decltype(T().~T()) fun() {} 1013 template void fun<int>(); 1014 // CHECK-LABEL: @_ZN6test513funIiEEDTcldtcvT__EdnS1_EEv 1015 template void fun<X>(); 1016 // CHECK-LABEL: @_ZN6test513funI1XEEDTcldtcvT__EdnS2_EEv 1017 template void fun<S1<int> >(); 1018 // CHECK-LABEL: @_ZN6test513funI2S1IiEEEDTcldtcvT__EdnS3_EEv 1019 1020 enum E {}; 1021 template <typename T> 1022 struct X { 1023 struct Y {}; 1024 }; 1025 1026 template <typename T> 1027 decltype(S1<T>().~S1<T>()) fun1() {}; 1028 template <typename U, typename T> 1029 decltype(U().~S1<T>()) fun2() {} 1030 template <typename U, typename T> 1031 decltype(S1<T>().~U()) fun3() {} 1032 template <typename T> 1033 decltype(S1<T>().~S1<T>(), S1<T>().~S1<T>()) fun4() {}; 1034 template <typename T> 1035 decltype(E().E::~T()) fun7() {} 1036 template <template <typename> class U> 1037 decltype(X<int>::Y().U<int>::Y::~Y()) fun8() {} 1038 template void fun1<int>(); 1039 // CHECK-LABEL: @_ZN6test514fun1IiEEDTcldtcv2S1IT_E_Edn2S1IS2_EEEv 1040 template void fun2<S1<int>, int>(); 1041 // CHECK-LABEL: @_ZN6test514fun2I2S1IiEiEEDTcldtcvT__Edn2S1IT0_EEEv 1042 template void fun3<S1<int>, int>(); 1043 // CHECK-LABEL: @_ZN6test514fun3I2S1IiEiEEDTcldtcvS1_IT0_E_EdnT_EEv 1044 template void fun4<int>(); 1045 // CHECK-LABEL: @_ZN6test514fun4IiEEDTcmcldtcv2S1IT_E_Edn2S1IS2_EEcldtcvS3__Edn2S1IS2_EEEv 1046 template void fun7<E>(); 1047 // CHECK-LABEL: @_ZN6test514fun7INS_1EEEEDTcldtcvS1__Esr1EEdnT_EEv 1048 template void fun8<X>(); 1049 } 1050 1051 namespace test52 { 1052 struct X {}; 1053 void operator+(X); 1054 template <typename... T> 1055 auto f4(T... x) -> decltype(operator+(x...)); 1056 // CHECK-LABEL: @_ZN6test522f4IJNS_1XEEEEDTclonplspfp_EEDpT_ 1057 void use() { f4(X{}); } 1058 } 1059 1060 namespace test53 { 1061 struct c { 1062 using t1 = struct { int z; }; 1063 using t2 = struct { double z; }; 1064 using t3 = struct { float z; }; 1065 using t4 = struct { float z; }; 1066 1067 __attribute__((used)) c(t1) {} 1068 __attribute__((used)) c(t2) {} 1069 __attribute__((used)) c(t3) {} 1070 __attribute__((used)) c(t4) {} 1071 // CHECK-LABEL: @_ZN6test531cC2ENS0_2t1E 1072 // CHECK-LABEL: @_ZN6test531cC2ENS0_2t2E 1073 // CHECK-LABEL: @_ZN6test531cC2ENS0_2t3E 1074 // CHECK-LABEL: @_ZN6test531cC2ENS0_2t4E 1075 }; 1076 } 1077 1078 namespace test54 { 1079 struct c { 1080 using t1 = struct { int z; } *; 1081 using t2 = struct { double z; } *; 1082 1083 __attribute__((used)) c(t1) {} 1084 __attribute__((used)) c(t2) {} 1085 // CHECK-LABEL: @_ZN6test541cC2EPNS0_Ut_E 1086 // CHECK-LABEL: @_ZN6test541cC2EPNS0_Ut0_E 1087 }; 1088 } 1089 1090 namespace test55 { 1091 enum E { R }; 1092 1093 template <typename T> 1094 void f1(T, __underlying_type(T)) {} 1095 template void f1<E>(E, __underlying_type(E)); 1096 // CHECK-LABEL: @_ZN6test552f1INS_1EEEEvT_u17__underlying_typeIS2_E 1097 1098 template <typename T> void f2(T, __add_lvalue_reference(T)) {} 1099 template void f2<int>(int, __add_lvalue_reference(int)); 1100 // CHECK-LABEL: @_ZN6test552f2IiEEvT_u22__add_lvalue_referenceIS1_E 1101 1102 template <typename T> void f3(T, __add_pointer(T)) {} 1103 template void f3<int>(int, __add_pointer(int)); 1104 // CHECK-LABEL: @_ZN6test552f3IiEEvT_u13__add_pointerIS1_E 1105 1106 template <typename T> void f4(T, __add_rvalue_reference(T)) {} 1107 template void f4<int>(int, __add_rvalue_reference(int)); 1108 // CHECK-LABEL: @_ZN6test552f4IiEEvT_u22__add_rvalue_referenceIS1_E 1109 1110 template <typename T> void f5(T, __decay(T)) {} 1111 template void f5<int>(int, __decay(int)); 1112 // CHECK-LABEL: @_ZN6test552f5IiEEvT_u7__decayIS1_E 1113 1114 template <typename T> void f6(T, __make_signed(T)) {} 1115 template void f6<int>(int, __make_signed(int)); 1116 // CHECK-LABEL: @_ZN6test552f6IiEEvT_u13__make_signedIS1_E 1117 1118 template <typename T> void f7(T, __make_unsigned(T)) {} 1119 template void f7<int>(int, __make_unsigned(int)); 1120 // CHECK-LABEL: @_ZN6test552f7IiEEvT_u15__make_unsignedIS1_E 1121 1122 template <typename T> void f8(T, __remove_const(T)) {} 1123 template void f8<int>(int, __remove_const(int)); 1124 // CHECK-LABEL: @_ZN6test552f8IiEEvT_u14__remove_constIS1_E 1125 1126 template <typename T> void f9(T, __remove_cv(T)) {} 1127 template void f9<int>(int, __remove_cv(int)); 1128 // CHECK-LABEL: @_ZN6test552f9IiEEvT_u11__remove_cvIS1_E 1129 1130 template <typename T> void f10(T, __remove_cvref(T)) {} 1131 template void f10<int>(int, __remove_cvref(int)); 1132 // CHECK-LABEL: @_ZN6test553f10IiEEvT_u14__remove_cvrefIS1_E 1133 1134 template <typename T> void f11(T, __remove_volatile(T)) {} 1135 template void f11<int>(int, __remove_volatile(int)); 1136 // CHECK-LABEL: @_ZN6test553f11IiEEvT_u17__remove_volatileIS1_E 1137 1138 template <typename T> void f12(T, __remove_extent(T)) {} 1139 template void f12<int>(int, __remove_extent(int)); 1140 // CHECK-LABEL: @_ZN6test553f12IiEEvT_u15__remove_extentIS1_E 1141 1142 template <typename T> void f13(T, __remove_all_extents(T)) {} 1143 template void f13<int>(int, __remove_all_extents(int)); 1144 // CHECK-LABEL: @_ZN6test553f13IiEEvT_u20__remove_all_extentsIS1_E 1145 1146 template <typename T> void f14(T, __remove_pointer(T)) {} 1147 template void f14<int>(int, __remove_pointer(int)); 1148 // CHECK-LABEL: @_ZN6test553f14IiEEvT_u16__remove_pointerIS1_E 1149 1150 template <typename T> void f15(T, __remove_reference_t(T)) {} 1151 template void f15<int>(int, __remove_reference_t(int)); 1152 // CHECK-LABEL: @_ZN6test553f15IiEEvT_u20__remove_reference_tIS1_E 1153 1154 template <typename T> void f16(T, __remove_volatile(T)) {} 1155 template void f16<int>(int, __remove_volatile(int)); 1156 // CHECK-LABEL: @_ZN6test553f16IiEEvT_u17__remove_volatileIS1_E 1157 1158 template <typename T> void f17(T, __remove_restrict(T)) {} 1159 template void f17<int>(int, __remove_restrict(int)); 1160 // CHECK-LABEL: @_ZN6test553f17IiEEvT_u17__remove_restrictIS1_E 1161 } // namespace test55 1162 1163 namespace test56 { 1164 struct A { A *operator->(); int n; } a; 1165 template<int N> void f(decltype(a->n + N)) {} 1166 // CHECK-LABEL: @_ZN6test561fILi0EEEvDTplptL_ZNS_1aEE1nT_E 1167 template void f<0>(int); 1168 } 1169 1170 namespace test57 { 1171 struct X { template <int N> int f(); } x; 1172 template<int N> void f(decltype(x.f<0>() + N)) {} 1173 // CHECK-LABEL: @_ZN6test571fILi0EEEvDTplcldtL_ZNS_1xEE1fILi0EEET_E 1174 template void f<0>(int); 1175 } 1176 1177 namespace test58 { 1178 struct State { 1179 bool m_fn1(); 1180 } a; 1181 template <class T> struct identity { typedef T type; }; 1182 struct A { 1183 template <typename T> A(T, bool (identity<T>::type::*)()); 1184 }; 1185 // CHECK-LABEL: @_ZN6test581AC1INS_5StateEEET_MNS_8identityIS3_E4typeEFbvE 1186 void fn1() { A(a, &State::m_fn1); } 1187 } 1188 1189 namespace test59 { 1190 // verify no crash. 1191 template<typename T> 1192 void f(T g) { 1193 auto [e] = g; 1194 [](decltype(e)) {}; 1195 } 1196 } 1197 1198 namespace test60 { 1199 struct X { int i, j; }; 1200 auto [a,b] = X{1,2}; 1201 template<typename T> void f(decltype(a + T())) {} 1202 // CHECK-LABEL: @_ZN6test601fIiEEvDTplL_ZNS_1aEEcvT__EE 1203 template void f<int>(int); 1204 } 1205 1206 namespace test61 { 1207 struct X { 1208 struct Y { 1209 using a = int; 1210 using b = int; 1211 }; 1212 }; 1213 template <typename T> void f(typename T::Y::a, typename T::Y::b) {} 1214 // CHECK-LABEL: @_ZN6test611fINS_1XEEEvNT_1Y1aENS3_1bE 1215 template void f<X>(int, int); 1216 } 1217