508 lines · cpp
1// RUN: %clang_cc1 -fblocks -emit-llvm %s -o - -triple=i386-pc-win32 -std=c++98 | FileCheck %s2// RUN: %clang_cc1 -fblocks -emit-llvm %s -o - -triple=x86_64-pc-win32 -std=c++98| FileCheck -check-prefix X64 %s3// RUN: %clang_cc1 -fblocks -emit-llvm %s -o - -triple=x86_64-uefi -std=c++98| FileCheck -check-prefix X64 %s4// RUN: %clang_cc1 -fblocks -emit-llvm %s -o - -triple=aarch64-pc-win32 -std=c++98 -DARM | FileCheck -check-prefixes=X64,ARM %s5 6int a;7// CHECK-DAG: @"?a@@3HA"8 9extern "C++" {10static int __attribute__((used)) ignore_transparent_context;11// CHECK-DAG: @ignore_transparent_context12}13 14namespace N {15 int b;16// CHECK-DAG: @"?b@N@@3HA"17 18 namespace {19 int anonymous;20// CHECK-DAG: @"?anonymous@?A0x{{[^@]*}}@N@@3HA"21 }22}23 24static int c;25// CHECK-DAG: @c26 27int _c(void) {return N::anonymous + c;}28// CHECK-DAG: @"?_c@@YAHXZ"29// X64-DAG: @"?_c@@YAHXZ"30 31const int &NeedsReferenceTemporary = 2;32// CHECK-DAG: @"?NeedsReferenceTemporary@@3ABHB" = dso_local constant ptr @"?$RT1@NeedsReferenceTemporary@@3ABHB"33// X64-DAG: @"?NeedsReferenceTemporary@@3AEBHEB" = dso_local constant ptr @"?$RT1@NeedsReferenceTemporary@@3AEBHEB"34 35class foo {36 static const short d;37// CHECK-DAG: @"?d@foo@@0FB"38protected:39 static volatile long e;40// CHECK-DAG: @"?e@foo@@1JC"41public:42 static const volatile char f;43// CHECK-DAG: @"?f@foo@@2DD"44 int operator+(int a);45 foo(){}46// CHECK-DAG: @"??0foo@@QAE@XZ"47// X64-DAG: @"??0foo@@QEAA@XZ"48 49 ~foo(){}50// CHECK-DAG: @"??1foo@@QAE@XZ"51// X64-DAG: @"??1foo@@QEAA@XZ52 53 foo(int i){}54// CHECK-DAG: @"??0foo@@QAE@H@Z"55// X64-DAG: @"??0foo@@QEAA@H@Z"56 57 foo(char *q){}58// CHECK-DAG: @"??0foo@@QAE@PAD@Z"59// X64-DAG: @"??0foo@@QEAA@PEAD@Z"60 61 static foo* static_method() { return 0; }62 63}f,s1(1),s2((char*)0);64 65typedef foo (foo2);66 67struct bar {68 static int g;69};70 71union baz {72 int a;73 char b;74 double c;75};76 77enum quux {78 qone,79 qtwo,80 qthree81};82 83foo bar() { return foo(); }84// CHECK-DAG: @"?bar@@YA?AVfoo@@XZ"85// X64-DAG: @"?bar@@YA?AVfoo@@XZ"86 87int foo::operator+(int a) {88// CHECK-DAG: @"??Hfoo@@QAEHH@Z"89// X64-DAG: @"??Hfoo@@QEAAHH@Z"90 91 foo::static_method();92// CHECK-DAG: @"?static_method@foo@@SAPAV1@XZ"93// X64-DAG: @"?static_method@foo@@SAPEAV1@XZ"94 bar();95 return a;96}97 98const short foo::d = 0;99volatile long foo::e;100const volatile char foo::f = 'C';101 102int bar::g;103// CHECK-DAG: @"?g@bar@@2HA"104 105extern int * const h1 = &a;106// CHECK-DAG: @"?h1@@3QAHA"107extern const int * const h2 = &a;108// CHECK-DAG: @"?h2@@3QBHB"109extern int * const __restrict h3 = &a;110// CHECK-DAG: @"?h3@@3QIAHIA"111// X64-DAG: @"?h3@@3QEIAHEIA"112 113int i[10][20];114// CHECK-DAG: @"?i@@3PAY0BE@HA"115 116typedef int (*FunT)(int, int);117FunT FunArr[10][20];118// CHECK-DAG: @"?FunArr@@3PAY0BE@P6AHHH@ZA"119// X64-DAG: @"?FunArr@@3PAY0BE@P6AHHH@ZA"120 121int (__stdcall *j)(signed char, unsigned char);122// CHECK-DAG: @"?j@@3P6GHCE@ZA"123 124const char foo2::*m;125// CHECK-DAG: @"?m@@3PRfoo@@DR1@"126// X64-DAG: @"?m@@3PERfoo@@DER1@"127 128const volatile char foo2::*k;129// CHECK-DAG: @"?k@@3PTfoo@@DT1@"130// X64-DAG: @"?k@@3PETfoo@@DET1@"131 132int (foo2::*l)(int);133// CHECK-DAG: @"?l@@3P8foo@@AEHH@ZQ1@"134 135// Ensure typedef CV qualifiers are mangled correctly136typedef const int cInt;137typedef volatile int vInt;138typedef const volatile int cvInt;139 140extern cInt g_cInt = 1;141vInt g_vInt = 2;142cvInt g_cvInt = 3;143 144// CHECK-DAG: @"?g_cInt@@3HB"145// CHECK-DAG: @"?g_vInt@@3HC"146// CHECK-DAG: @"?g_cvInt@@3HD"147 148// Static functions are mangled, too.149// Also make sure calling conventions, arglists, and throw specs work.150static void __stdcall alpha(float a, double b) throw() {}151bool __fastcall beta(long long a, wchar_t b) throw(signed char, unsigned char) {152// CHECK-DAG: @"?beta@@YI_N_J_W@Z"153// X64-DAG: @"?beta@@YA_N_J_W@Z"154 alpha(0.f, 0.0);155 return false;156}157 158// CHECK-DAG: @"?alpha@@YGXMN@Z"159// X64-DAG: @"?alpha@@YAXMN@Z"160 161// Make sure tag-type mangling works.162void gamma(class foo, struct bar, union baz, enum quux) {}163// CHECK-DAG: @"?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z"164// X64-DAG: @"?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z"165 166// Make sure pointer/reference-type mangling works.167void delta(int * const a, const long &) {}168// CHECK-DAG: @"?delta@@YAXQAHABJ@Z"169// X64-DAG: @"?delta@@YAXQEAHAEBJ@Z"170 171// Array mangling.172void epsilon(int a[][10][20]) {}173// CHECK-DAG: @"?epsilon@@YAXQAY19BE@H@Z"174// X64-DAG: @"?epsilon@@YAXQEAY19BE@H@Z"175 176void zeta(int (*)(int, int)) {}177// CHECK-DAG: @"?zeta@@YAXP6AHHH@Z@Z"178// X64-DAG: @"?zeta@@YAXP6AHHH@Z@Z"179 180// Blocks mangling (Clang extension). A block should be mangled slightly181// differently from a similar function pointer.182void eta(int (^)(int, int)) {}183// CHECK-DAG: @"?eta@@YAXP_EAHHH@Z@Z"184 185typedef int theta_arg(int,int);186void theta(theta_arg^ block) {}187// CHECK-DAG: @"?theta@@YAXP_EAHHH@Z@Z"188 189void operator_new_delete() {190 char *ptr = new char;191// CHECK-DAG: @"??2@YAPAXI@Z"192 193 delete ptr;194// CHECK-DAG: @"??3@YAXPAX@Z"195 196 char *array = new char[42];197// CHECK-DAG: @"??_U@YAPAXI@Z"198 199 delete [] array;200// CHECK-DAG: @"??_V@YAXPAX@Z"201}202 203// PR13022204void (redundant_parens)();205void redundant_parens_use() { redundant_parens(); }206// CHECK-DAG: @"?redundant_parens@@YAXXZ"207// X64-DAG: @"?redundant_parens@@YAXXZ"208 209// PR13047210typedef double RGB[3];211RGB color1;212// CHECK-DAG: @"?color1@@3PANA"213extern const RGB color2 = {};214// CHECK-DAG: @"?color2@@3QBNB"215extern RGB const color3[5] = {};216// CHECK-DAG: @"?color3@@3QAY02$$CBNA"217extern RGB const ((color4)[5]) = {};218// CHECK-DAG: @"?color4@@3QAY02$$CBNA"219 220struct B;221volatile int B::* volatile memptr1;222// X64-DAG: @"?memptr1@@3RESB@@HES1@"223volatile int B::* memptr2;224// X64-DAG: @"?memptr2@@3PESB@@HES1@"225int B::* volatile memptr3;226// X64-DAG: @"?memptr3@@3REQB@@HEQ1@"227typedef int (*fun)();228volatile fun B::* volatile funmemptr1;229// X64-DAG: @"?funmemptr1@@3RESB@@R6AHXZES1@"230volatile fun B::* funmemptr2;231// X64-DAG: @"?funmemptr2@@3PESB@@R6AHXZES1@"232fun B::* volatile funmemptr3;233// X64-DAG: @"?funmemptr3@@3REQB@@P6AHXZEQ1@"234void (B::* volatile memptrtofun1)();235// X64-DAG: @"?memptrtofun1@@3R8B@@EAAXXZEQ1@"236const void (B::* memptrtofun2)();237// X64-DAG: @"?memptrtofun2@@3P8B@@EAAXXZEQ1@"238volatile void (B::* memptrtofun3)();239// X64-DAG: @"?memptrtofun3@@3P8B@@EAAXXZEQ1@"240int (B::* volatile memptrtofun4)();241// X64-DAG: @"?memptrtofun4@@3R8B@@EAAHXZEQ1@"242volatile int (B::* memptrtofun5)();243// X64-DAG: @"?memptrtofun5@@3P8B@@EAA?CHXZEQ1@"244const int (B::* memptrtofun6)();245// X64-DAG: @"?memptrtofun6@@3P8B@@EAA?BHXZEQ1@"246fun (B::* volatile memptrtofun7)();247// X64-DAG: @"?memptrtofun7@@3R8B@@EAAP6AHXZXZEQ1@"248volatile fun (B::* memptrtofun8)();249// X64-DAG: @"?memptrtofun8@@3P8B@@EAAR6AHXZXZEQ1@"250const fun (B::* memptrtofun9)();251// X64-DAG: @"?memptrtofun9@@3P8B@@EAAQ6AHXZXZEQ1@"252 253// PR12603254enum E {};255// CHECK-DAG: "?fooE@@YA?AW4E@@XZ"256// X64-DAG: "?fooE@@YA?AW4E@@XZ"257E fooE() { return E(); }258 259class X {};260// CHECK-DAG: "?fooX@@YA?AVX@@XZ"261// X64-DAG: "?fooX@@YA?AVX@@XZ"262X fooX() { return X(); }263 264namespace PR13182 {265 extern char s0[];266 // CHECK-DAG: @"?s0@PR13182@@3PADA"267 extern char s1[42];268 // CHECK-DAG: @"?s1@PR13182@@3PADA"269 extern const char s2[];270 // CHECK-DAG: @"?s2@PR13182@@3QBDB"271 extern const char s3[42];272 // CHECK-DAG: @"?s3@PR13182@@3QBDB"273 extern volatile char s4[];274 // CHECK-DAG: @"?s4@PR13182@@3RCDC"275 extern const volatile char s5[];276 // CHECK-DAG: @"?s5@PR13182@@3SDDD"277 extern const char* const* s6;278 // CHECK-DAG: @"?s6@PR13182@@3PBQBDB"279 280 char foo() {281 return s0[0] + s1[0] + s2[0] + s3[0] + s4[0] + s5[0] + s6[0][0];282 }283}284 285extern "C" inline void extern_c_func() {286 static int local;287// CHECK-DAG: @"?local@?1??extern_c_func@@9@4HA"288// X64-DAG: @"?local@?1??extern_c_func@@9@4HA"289}290 291void call_extern_c_func() {292 extern_c_func();293}294 295int main() { return 0; }296// CHECK-DAG: @main297// X64-DAG: @main298 299int wmain() { return 0; }300// CHECK-DAG: @wmain301// X64-DAG: @wmain302 303int WinMain() { return 0; }304// CHECK-DAG: @WinMain305// X64-DAG: @WinMain306 307int wWinMain() { return 0; }308// CHECK-DAG: @wWinMain309// X64-DAG: @wWinMain310 311int DllMain() { return 0; }312// CHECK-DAG: @DllMain313// X64-DAG: @DllMain314 315inline int inline_function_with_local_type() {316 static struct {317 int a_field;318 } static_variable_in_inline_function = { 20 }, second_static = { 40 };319 // CHECK: @"?static_variable_in_inline_function@?1??inline_function_with_local_type@@YAHXZ@4U<unnamed-type-static_variable_in_inline_function>@?1??1@YAHXZ@A"320 321 return static_variable_in_inline_function.a_field + second_static.a_field;322}323 324int call_inline_function_with_local_type() {325 return inline_function_with_local_type();326}327 328template <typename T>329inline int templated_inline_function_with_local_type() {330 static struct {331 int a_field;332 } static_variable_in_templated_inline_function = { 20 },333 second_static = { 40 };334 // CHECK: @"?static_variable_in_templated_inline_function@?1???$templated_inline_function_with_local_type@H@@YAHXZ@4U<unnamed-type-static_variable_in_templated_inline_function>@?1???$templated_inline_function_with_local_type@H@@YAHXZ@A"335 336 return static_variable_in_templated_inline_function.a_field +337 second_static.a_field;338}339 340int call_templated_inline_function_with_local_type() {341 return templated_inline_function_with_local_type<int>();342}343 344// PR17371345struct OverloadedNewDelete {346 // __cdecl347 void *operator new(__SIZE_TYPE__);348 void *operator new[](__SIZE_TYPE__);349 void operator delete(void *);350 void operator delete[](void *);351 // __thiscall352 int operator+(int);353};354 355void *OverloadedNewDelete::operator new(__SIZE_TYPE__ s) { return 0; }356void *OverloadedNewDelete::operator new[](__SIZE_TYPE__ s) { return 0; }357void OverloadedNewDelete::operator delete(void *) { }358void OverloadedNewDelete::operator delete[](void *) { }359int OverloadedNewDelete::operator+(int x) { return x; };360 361// CHECK-DAG: ??2OverloadedNewDelete@@SAPAXI@Z362// CHECK-DAG: ??_UOverloadedNewDelete@@SAPAXI@Z363// CHECK-DAG: ??3OverloadedNewDelete@@SAXPAX@Z364// CHECK-DAG: ??_VOverloadedNewDelete@@SAXPAX@Z365// CHECK-DAG: ??HOverloadedNewDelete@@QAEHH@Z366 367// X64-DAG: ??2OverloadedNewDelete@@SAPEAX_K@Z368// X64-DAG: ??_UOverloadedNewDelete@@SAPEAX_K@Z369// X64-DAG: ??3OverloadedNewDelete@@SAXPEAX@Z370// X64-DAG: ??_VOverloadedNewDelete@@SAXPEAX@Z371// X64-DAG: ??HOverloadedNewDelete@@QEAAHH@Z372 373// Indirecting the function type through a typedef will require a calling374// convention adjustment before building the method decl.375 376typedef void *__thiscall OperatorNewType(__SIZE_TYPE__);377typedef void __thiscall OperatorDeleteType(void *);378 379struct TypedefNewDelete {380 OperatorNewType operator new;381 OperatorNewType operator new[];382 OperatorDeleteType operator delete;383 OperatorDeleteType operator delete[];384};385 386void *TypedefNewDelete::operator new(__SIZE_TYPE__ s) { return 0; }387void *TypedefNewDelete::operator new[](__SIZE_TYPE__ s) { return 0; }388void TypedefNewDelete::operator delete(void *) { }389void TypedefNewDelete::operator delete[](void *) { }390 391// CHECK-DAG: ??2TypedefNewDelete@@SAPAXI@Z392// CHECK-DAG: ??_UTypedefNewDelete@@SAPAXI@Z393// CHECK-DAG: ??3TypedefNewDelete@@SAXPAX@Z394// CHECK-DAG: ??_VTypedefNewDelete@@SAXPAX@Z395 396void __vectorcall vector_func() { }397// CHECK-DAG: @"?vector_func@@YQXXZ"398 399template <void (*)(void)>400void fn_tmpl() {}401 402template void fn_tmpl<extern_c_func>();403// CHECK-DAG: @"??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ"404 405extern "C" void __attribute__((overloadable)) overloaded_fn() {}406// CHECK-DAG: @"?overloaded_fn@@$$J0YAXXZ"407 408extern "C" void overloaded_fn2() {}409// CHECK-DAG: @overloaded_fn2410//411extern "C" void __attribute__((overloadable)) overloaded_fn3();412extern "C" void overloaded_fn3() {}413// CHECK-DAG: @overloaded_fn3414 415namespace UnnamedType {416struct S {417 typedef struct {} *T1[1];418 typedef struct {} T2;419 typedef struct {} *T3, T4;420 using T5 = struct {};421 using T6 = struct {} *;422};423void f(S::T1) {}424void f(S::T2) {}425void f(S::T3) {}426void f(S::T4) {}427void f(S::T5) {}428void f(S::T6) {}429// CHECK-DAG: @"?f@UnnamedType@@YAXQAPAU<unnamed-type-T1>@S@1@@Z"430// CHECK-DAG: @"?f@UnnamedType@@YAXUT2@S@1@@Z"431// CHECK-DAG: @"?f@UnnamedType@@YAXPAUT4@S@1@@Z"432// CHECK-DAG: @"?f@UnnamedType@@YAXUT4@S@1@@Z"433// CHECK-DAG: @"?f@UnnamedType@@YAXUT5@S@1@@Z"434// CHECK-DAG: @"?f@UnnamedType@@YAXPAU<unnamed-type-T6>@S@1@@Z"435 436// X64-DAG: @"?f@UnnamedType@@YAXQEAPEAU<unnamed-type-T1>@S@1@@Z"437// X64-DAG: @"?f@UnnamedType@@YAXUT2@S@1@@Z"438// X64-DAG: @"?f@UnnamedType@@YAXPEAUT4@S@1@@Z"(ptr439// X64-DAG: @"?f@UnnamedType@@YAXUT4@S@1@@Z"440// X64-DAG: @"?f@UnnamedType@@YAXUT5@S@1@@Z"441// X64-DAG: @"?f@UnnamedType@@YAXPEAU<unnamed-type-T6>@S@1@@Z"442}443 444namespace PassObjectSize {445// NOTE: This mangling is subject to change.446// Reiterating from the comment in MicrosoftMangle, the scheme is pretend a447// parameter of type __clang::__pass_object_sizeN exists after each pass object448// size param P, where N is the Type of the pass_object_size attribute on P.449//450// e.g. we want to mangle:451// void foo(ptr const __attribute__((pass_object_size(0))));452// as if it were453// namespace __clang { enum __pass_object_size0 : size_t {}; }454// void foo(ptr const, __clang::__pass_object_size0);455// where __clang is a top-level namespace.456 457// CHECK-DAG: define dso_local noundef i32 @"?foo@PassObjectSize@@YAHQAHW4__pass_object_size0@__clang@@@Z"458int foo(int *const i __attribute__((pass_object_size(0)))) { return 0; }459// CHECK-DAG: define dso_local noundef i32 @"?bar@PassObjectSize@@YAHQAHW4__pass_object_size1@__clang@@@Z"460int bar(int *const i __attribute__((pass_object_size(1)))) { return 0; }461// CHECK-DAG: define dso_local noundef i32 @"?qux@PassObjectSize@@YAHQAHW4__pass_object_size1@__clang@@0W4__pass_object_size0@3@@Z"462int qux(int *const i __attribute__((pass_object_size(1))), int *const j __attribute__((pass_object_size(0)))) { return 0; }463// CHECK-DAG: define dso_local noundef i32 @"?zot@PassObjectSize@@YAHQAHW4__pass_object_size1@__clang@@01@Z"464int zot(int *const i __attribute__((pass_object_size(1))), int *const j __attribute__((pass_object_size(1)))) { return 0; }465// CHECK-DAG: define dso_local noundef i32 @"?silly_word@PassObjectSize@@YAHQAHW4__pass_dynamic_object_size1@__clang@@@Z"466int silly_word(int *const i __attribute__((pass_dynamic_object_size(1)))) { return 0; }467}468 469namespace Atomic {470// CHECK-DAG: define dso_local void @"?f@Atomic@@YAXU?$_Atomic@H@__clang@@@Z"(471void f(_Atomic(int)) {}472}473namespace Complex {474// CHECK-DAG: define dso_local void @"?f@Complex@@YAXU?$_Complex@H@__clang@@@Z"(475void f(_Complex int) {}476}477#ifdef ARM478namespace Float16 {479// ARM-DAG: define dso_local void @"?f@Float16@@YAXU_Float16@__clang@@@Z"(480void f(_Float16) {}481}482#endif // ARM483 484namespace PR26029 {485template <class>486struct L {487 L() {}488};489template <class>490class H;491struct M : L<H<int *> > {};492 493template <class>494struct H {};495 496template <class GT>497void m_fn3() {498 (H<GT *>());499 M();500}501 502void runOnFunction() {503 L<H<int *> > b;504 m_fn3<int>();505}506// CHECK-DAG: call {{.*}} @"??0?$L@V?$H@PAH@PR26029@@@PR26029@@QAE@XZ"507}508