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