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