1// RUN: %clang_cc1 -fblocks -emit-llvm %s -o - -triple=i386-pc-win32 -std=c++98 | FileCheck %s 2// RUN: %clang_cc1 -fblocks -emit-llvm %s -o - -triple=x86_64-pc-win32 -std=c++98| FileCheck -check-prefix X64 %s 3 4int a; 5// CHECK-DAG: @"\01?a@@3HA" 6 7namespace N { 8 int b; 9// CHECK-DAG: @"\01?b@N@@3HA" 10 11 namespace { 12 int anonymous; 13// CHECK-DAG: @"\01?anonymous@?A@N@@3HA" 14 } 15} 16 17static int c; 18// CHECK-DAG: @c 19 20int _c(void) {return N::anonymous + c;} 21// CHECK-DAG: @"\01?_c@@YAHXZ" 22// X64-DAG: @"\01?_c@@YAHXZ" 23 24class foo { 25 static const short d; 26// CHECK-DAG: @"\01?d@foo@@0FB" 27protected: 28 static volatile long e; 29// CHECK-DAG: @"\01?e@foo@@1JC" 30public: 31 static const volatile char f; 32// CHECK-DAG: @"\01?f@foo@@2DD" 33 int operator+(int a); 34 foo(){} 35// CHECK-DAG: @"\01??0foo@@QAE@XZ" 36// X64-DAG: @"\01??0foo@@QEAA@XZ" 37 38 ~foo(){} 39// CHECK-DAG: @"\01??1foo@@QAE@XZ" 40// X64-DAG: @"\01??1foo@@QEAA@XZ 41 42 foo(int i){} 43// CHECK-DAG: @"\01??0foo@@QAE@H@Z" 44// X64-DAG: @"\01??0foo@@QEAA@H@Z" 45 46 foo(char *q){} 47// CHECK-DAG: @"\01??0foo@@QAE@PAD@Z" 48// X64-DAG: @"\01??0foo@@QEAA@PEAD@Z" 49 50 static foo* static_method() { return 0; } 51 52}f,s1(1),s2((char*)0); 53 54typedef foo (foo2); 55 56struct bar { 57 static int g; 58}; 59 60union baz { 61 int a; 62 char b; 63 double c; 64}; 65 66enum quux { 67 qone, 68 qtwo, 69 qthree 70}; 71 72foo bar() { return foo(); } 73// CHECK-DAG: @"\01?bar@@YA?AVfoo@@XZ" 74// X64-DAG: @"\01?bar@@YA?AVfoo@@XZ" 75 76int foo::operator+(int a) { 77// CHECK-DAG: @"\01??Hfoo@@QAEHH@Z" 78// X64-DAG: @"\01??Hfoo@@QEAAHH@Z" 79 80 foo::static_method(); 81// CHECK-DAG: @"\01?static_method@foo@@SAPAV1@XZ" 82// X64-DAG: @"\01?static_method@foo@@SAPEAV1@XZ" 83 bar(); 84 return a; 85} 86 87const short foo::d = 0; 88volatile long foo::e; 89const volatile char foo::f = 'C'; 90 91int bar::g; 92// CHECK-DAG: @"\01?g@bar@@2HA" 93 94extern int * const h1 = &a; 95// CHECK-DAG: @"\01?h1@@3QAHA" 96extern const int * const h2 = &a; 97// CHECK-DAG: @"\01?h2@@3QBHB" 98extern int * const __restrict h3 = &a; 99// CHECK-DAG: @"\01?h3@@3QIAHIA" 100// X64-DAG: @"\01?h3@@3QEIAHEIA" 101 102int i[10][20]; 103// CHECK-DAG: @"\01?i@@3PAY0BE@HA" 104 105typedef int (*FunT)(int, int); 106FunT FunArr[10][20]; 107// CHECK-DAG: @"\01?FunArr@@3PAY0BE@P6AHHH@ZA" 108// X64-DAG: @"\01?FunArr@@3PAY0BE@P6AHHH@ZA" 109 110int (__stdcall *j)(signed char, unsigned char); 111// CHECK-DAG: @"\01?j@@3P6GHCE@ZA" 112 113const volatile char foo2::*k; 114// CHECK-DAG: @"\01?k@@3PTfoo@@DT1@" 115// X64-DAG: @"\01?k@@3PETfoo@@DET1@" 116 117int (foo2::*l)(int); 118// CHECK-DAG: @"\01?l@@3P8foo@@AEHH@ZQ1@" 119 120// Static functions are mangled, too. 121// Also make sure calling conventions, arglists, and throw specs work. 122static void __stdcall alpha(float a, double b) throw() {} 123bool __fastcall beta(long long a, wchar_t b) throw(signed char, unsigned char) { 124// CHECK-DAG: @"\01?beta@@YI_N_J_W@Z" 125// X64-DAG: @"\01?beta@@YA_N_J_W@Z" 126 alpha(0.f, 0.0); 127 return false; 128} 129 130// CHECK-DAG: @"\01?alpha@@YGXMN@Z" 131// X64-DAG: @"\01?alpha@@YAXMN@Z" 132 133// Make sure tag-type mangling works. 134void gamma(class foo, struct bar, union baz, enum quux) {} 135// CHECK-DAG: @"\01?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z" 136// X64-DAG: @"\01?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z" 137 138// Make sure pointer/reference-type mangling works. 139void delta(int * const a, const long &) {} 140// CHECK-DAG: @"\01?delta@@YAXQAHABJ@Z" 141// X64-DAG: @"\01?delta@@YAXQEAHAEBJ@Z" 142 143// Array mangling. 144void epsilon(int a[][10][20]) {} 145// CHECK-DAG: @"\01?epsilon@@YAXQAY19BE@H@Z" 146// X64-DAG: @"\01?epsilon@@YAXQEAY19BE@H@Z" 147 148void zeta(int (*)(int, int)) {} 149// CHECK-DAG: @"\01?zeta@@YAXP6AHHH@Z@Z" 150// X64-DAG: @"\01?zeta@@YAXP6AHHH@Z@Z" 151 152// Blocks mangling (Clang extension). A block should be mangled slightly 153// differently from a similar function pointer. 154void eta(int (^)(int, int)) {} 155// CHECK-DAG: @"\01?eta@@YAXP_EAHHH@Z@Z" 156 157typedef int theta_arg(int,int); 158void theta(theta_arg^ block) {} 159// CHECK-DAG: @"\01?theta@@YAXP_EAHHH@Z@Z" 160 161void operator_new_delete() { 162 char *ptr = new char; 163// CHECK-DAG: @"\01??2@YAPAXI@Z" 164 165 delete ptr; 166// CHECK-DAG: @"\01??3@YAXPAX@Z" 167 168 char *array = new char[42]; 169// CHECK-DAG: @"\01??_U@YAPAXI@Z" 170 171 delete [] array; 172// CHECK-DAG: @"\01??_V@YAXPAX@Z" 173} 174 175// PR13022 176void (redundant_parens)(); 177void redundant_parens_use() { redundant_parens(); } 178// CHECK-DAG: @"\01?redundant_parens@@YAXXZ" 179// X64-DAG: @"\01?redundant_parens@@YAXXZ" 180 181// PR13047 182typedef double RGB[3]; 183RGB color1; 184// CHECK-DAG: @"\01?color1@@3PANA" 185extern const RGB color2 = {}; 186// CHECK-DAG: @"\01?color2@@3QBNB" 187extern RGB const color3[5] = {}; 188// CHECK-DAG: @"\01?color3@@3QAY02$$CBNA" 189extern RGB const ((color4)[5]) = {}; 190// CHECK-DAG: @"\01?color4@@3QAY02$$CBNA" 191 192struct B; 193volatile int B::* volatile memptr1; 194// X64-DAG: @"\01?memptr1@@3RESB@@HES1@" 195volatile int B::* memptr2; 196// X64-DAG: @"\01?memptr2@@3PESB@@HES1@" 197int B::* volatile memptr3; 198// X64-DAG: @"\01?memptr3@@3REQB@@HEQ1@" 199typedef int (*fun)(); 200volatile fun B::* volatile funmemptr1; 201// X64-DAG: @"\01?funmemptr1@@3RESB@@R6AHXZES1@" 202volatile fun B::* funmemptr2; 203// X64-DAG: @"\01?funmemptr2@@3PESB@@R6AHXZES1@" 204fun B::* volatile funmemptr3; 205// X64-DAG: @"\01?funmemptr3@@3REQB@@P6AHXZEQ1@" 206void (B::* volatile memptrtofun1)(); 207// X64-DAG: @"\01?memptrtofun1@@3R8B@@EAAXXZEQ1@" 208const void (B::* memptrtofun2)(); 209// X64-DAG: @"\01?memptrtofun2@@3P8B@@EAAXXZEQ1@" 210volatile void (B::* memptrtofun3)(); 211// X64-DAG: @"\01?memptrtofun3@@3P8B@@EAAXXZEQ1@" 212int (B::* volatile memptrtofun4)(); 213// X64-DAG: @"\01?memptrtofun4@@3R8B@@EAAHXZEQ1@" 214volatile int (B::* memptrtofun5)(); 215// X64-DAG: @"\01?memptrtofun5@@3P8B@@EAA?CHXZEQ1@" 216const int (B::* memptrtofun6)(); 217// X64-DAG: @"\01?memptrtofun6@@3P8B@@EAA?BHXZEQ1@" 218fun (B::* volatile memptrtofun7)(); 219// X64-DAG: @"\01?memptrtofun7@@3R8B@@EAAP6AHXZXZEQ1@" 220volatile fun (B::* memptrtofun8)(); 221// X64-DAG: @"\01?memptrtofun8@@3P8B@@EAAR6AHXZXZEQ1@" 222const fun (B::* memptrtofun9)(); 223// X64-DAG: @"\01?memptrtofun9@@3P8B@@EAAQ6AHXZXZEQ1@" 224 225// PR12603 226enum E {}; 227// CHECK-DAG: "\01?fooE@@YA?AW4E@@XZ" 228// X64-DAG: "\01?fooE@@YA?AW4E@@XZ" 229E fooE() { return E(); } 230 231class X {}; 232// CHECK-DAG: "\01?fooX@@YA?AVX@@XZ" 233// X64-DAG: "\01?fooX@@YA?AVX@@XZ" 234X fooX() { return X(); } 235 236namespace PR13182 { 237 extern char s0[]; 238 // CHECK-DAG: @"\01?s0@PR13182@@3PADA" 239 extern char s1[42]; 240 // CHECK-DAG: @"\01?s1@PR13182@@3PADA" 241 extern const char s2[]; 242 // CHECK-DAG: @"\01?s2@PR13182@@3QBDB" 243 extern const char s3[42]; 244 // CHECK-DAG: @"\01?s3@PR13182@@3QBDB" 245 extern volatile char s4[]; 246 // CHECK-DAG: @"\01?s4@PR13182@@3RCDC" 247 extern const volatile char s5[]; 248 // CHECK-DAG: @"\01?s5@PR13182@@3SDDD" 249 extern const char* const* s6; 250 // CHECK-DAG: @"\01?s6@PR13182@@3PBQBDB" 251 252 char foo() { 253 return s0[0] + s1[0] + s2[0] + s3[0] + s4[0] + s5[0] + s6[0][0]; 254 } 255} 256 257extern "C" inline void extern_c_func() { 258 static int local; 259// CHECK-DAG: @"\01?local@?1??extern_c_func@@9@4HA" 260// X64-DAG: @"\01?local@?1??extern_c_func@@9@4HA" 261} 262 263void call_extern_c_func() { 264 extern_c_func(); 265} 266 267int main() { return 0; } 268// CHECK-DAG: @main 269// X64-DAG: @main 270 271int wmain() { return 0; } 272// CHECK-DAG: @wmain 273// X64-DAG: @wmain 274 275int WinMain() { return 0; } 276// CHECK-DAG: @WinMain 277// X64-DAG: @WinMain 278 279int wWinMain() { return 0; } 280// CHECK-DAG: @wWinMain 281// X64-DAG: @wWinMain 282 283int DllMain() { return 0; } 284// CHECK-DAG: @DllMain 285// X64-DAG: @DllMain 286 287inline int inline_function_with_local_type() { 288 static struct { 289 int a_field; 290 } static_variable_in_inline_function = { 20 }, second_static = { 40 }; 291 // CHECK: @"\01?static_variable_in_inline_function@?1??inline_function_with_local_type@@YAHXZ@4U<unnamed-type-static_variable_in_inline_function>@?1??1@YAHXZ@A" 292 293 return static_variable_in_inline_function.a_field + second_static.a_field; 294} 295 296int call_inline_function_with_local_type() { 297 return inline_function_with_local_type(); 298} 299 300template <typename T> 301inline int templated_inline_function_with_local_type() { 302 static struct { 303 int a_field; 304 } static_variable_in_templated_inline_function = { 20 }, 305 second_static = { 40 }; 306 // CHECK: @"\01?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" 307 308 return static_variable_in_templated_inline_function.a_field + 309 second_static.a_field; 310} 311 312int call_templated_inline_function_with_local_type() { 313 return templated_inline_function_with_local_type<int>(); 314} 315 316// PR17371 317struct OverloadedNewDelete { 318 // __cdecl 319 void *operator new(__SIZE_TYPE__); 320 void *operator new[](__SIZE_TYPE__); 321 void operator delete(void *); 322 void operator delete[](void *); 323 // __thiscall 324 int operator+(int); 325}; 326 327void *OverloadedNewDelete::operator new(__SIZE_TYPE__ s) { return 0; } 328void *OverloadedNewDelete::operator new[](__SIZE_TYPE__ s) { return 0; } 329void OverloadedNewDelete::operator delete(void *) { } 330void OverloadedNewDelete::operator delete[](void *) { } 331int OverloadedNewDelete::operator+(int x) { return x; }; 332 333// CHECK-DAG: ??2OverloadedNewDelete@@SAPAXI@Z 334// CHECK-DAG: ??_UOverloadedNewDelete@@SAPAXI@Z 335// CHECK-DAG: ??3OverloadedNewDelete@@SAXPAX@Z 336// CHECK-DAG: ??_VOverloadedNewDelete@@SAXPAX@Z 337// CHECK-DAG: ??HOverloadedNewDelete@@QAEHH@Z 338 339// X64-DAG: ??2OverloadedNewDelete@@SAPEAX_K@Z 340// X64-DAG: ??_UOverloadedNewDelete@@SAPEAX_K@Z 341// X64-DAG: ??3OverloadedNewDelete@@SAXPEAX@Z 342// X64-DAG: ??_VOverloadedNewDelete@@SAXPEAX@Z 343// X64-DAG: ??HOverloadedNewDelete@@QEAAHH@Z 344 345// Indirecting the function type through a typedef will require a calling 346// convention adjustment before building the method decl. 347 348typedef void *__thiscall OperatorNewType(__SIZE_TYPE__); 349typedef void __thiscall OperatorDeleteType(void *); 350 351struct TypedefNewDelete { 352 OperatorNewType operator new; 353 OperatorNewType operator new[]; 354 OperatorDeleteType operator delete; 355 OperatorDeleteType operator delete[]; 356}; 357 358void *TypedefNewDelete::operator new(__SIZE_TYPE__ s) { return 0; } 359void *TypedefNewDelete::operator new[](__SIZE_TYPE__ s) { return 0; } 360void TypedefNewDelete::operator delete(void *) { } 361void TypedefNewDelete::operator delete[](void *) { } 362 363// CHECK-DAG: ??2TypedefNewDelete@@SAPAXI@Z 364// CHECK-DAG: ??_UTypedefNewDelete@@SAPAXI@Z 365// CHECK-DAG: ??3TypedefNewDelete@@SAXPAX@Z 366// CHECK-DAG: ??_VTypedefNewDelete@@SAXPAX@Z 367 368