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: @"?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: @"?b@N@@3HA"
15 
16   namespace {
17     int anonymous;
18 // CHECK-DAG: @"?anonymous@?A@N@@3HA"
19   }
20 }
21 
22 static int c;
23 // CHECK-DAG: @c
24 
25 int _c(void) {return N::anonymous + c;}
26 // CHECK-DAG: @"?_c@@YAHXZ"
27 // X64-DAG:   @"?_c@@YAHXZ"
28 
29 const int &NeedsReferenceTemporary = 2;
30 // CHECK-DAG: @"?NeedsReferenceTemporary@@3ABHB" = dso_local constant i32* @"?$RT1@NeedsReferenceTemporary@@3ABHB"
31 // X64-DAG: @"?NeedsReferenceTemporary@@3AEBHEB" = dso_local constant i32* @"?$RT1@NeedsReferenceTemporary@@3AEBHEB"
32 
33 class foo {
34   static const short d;
35 // CHECK-DAG: @"?d@foo@@0FB"
36 protected:
37   static volatile long e;
38 // CHECK-DAG: @"?e@foo@@1JC"
39 public:
40   static const volatile char f;
41 // CHECK-DAG: @"?f@foo@@2DD"
42   int operator+(int a);
43   foo(){}
44 // CHECK-DAG: @"??0foo@@QAE@XZ"
45 // X64-DAG:   @"??0foo@@QEAA@XZ"
46 
47   ~foo(){}
48 // CHECK-DAG: @"??1foo@@QAE@XZ"
49 // X64-DAG:   @"??1foo@@QEAA@XZ
50 
51   foo(int i){}
52 // CHECK-DAG: @"??0foo@@QAE@H@Z"
53 // X64-DAG:   @"??0foo@@QEAA@H@Z"
54 
55   foo(char *q){}
56 // CHECK-DAG: @"??0foo@@QAE@PAD@Z"
57 // X64-DAG:   @"??0foo@@QEAA@PEAD@Z"
58 
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 
81 foo bar() { return foo(); }
82 // CHECK-DAG: @"?bar@@YA?AVfoo@@XZ"
83 // X64-DAG:   @"?bar@@YA?AVfoo@@XZ"
84 
85 int foo::operator+(int a) {
86 // CHECK-DAG: @"??Hfoo@@QAEHH@Z"
87 // X64-DAG:   @"??Hfoo@@QEAAHH@Z"
88 
89   foo::static_method();
90 // CHECK-DAG: @"?static_method@foo@@SAPAV1@XZ"
91 // X64-DAG:   @"?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: @"?g@bar@@2HA"
102 
103 extern int * const h1 = &a;
104 // CHECK-DAG: @"?h1@@3QAHA"
105 extern const int * const h2 = &a;
106 // CHECK-DAG: @"?h2@@3QBHB"
107 extern int * const __restrict h3 = &a;
108 // CHECK-DAG: @"?h3@@3QIAHIA"
109 // X64-DAG: @"?h3@@3QEIAHEIA"
110 
111 int i[10][20];
112 // CHECK-DAG: @"?i@@3PAY0BE@HA"
113 
114 typedef int (*FunT)(int, int);
115 FunT FunArr[10][20];
116 // CHECK-DAG: @"?FunArr@@3PAY0BE@P6AHHH@ZA"
117 // X64-DAG: @"?FunArr@@3PAY0BE@P6AHHH@ZA"
118 
119 int (__stdcall *j)(signed char, unsigned char);
120 // CHECK-DAG: @"?j@@3P6GHCE@ZA"
121 
122 const volatile char foo2::*k;
123 // CHECK-DAG: @"?k@@3PTfoo@@DT1@"
124 // X64-DAG:   @"?k@@3PETfoo@@DET1@"
125 
126 int (foo2::*l)(int);
127 // CHECK-DAG: @"?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: @"?g_cInt@@3HB"
139 // CHECK-DAG: @"?g_vInt@@3HC"
140 // CHECK-DAG: @"?g_cvInt@@3HD"
141 
142 // Static functions are mangled, too.
143 // Also make sure calling conventions, arglists, and throw specs work.
144 static void __stdcall alpha(float a, double b) throw() {}
145 bool __fastcall beta(long long a, wchar_t b) throw(signed char, unsigned char) {
146 // CHECK-DAG: @"?beta@@YI_N_J_W@Z"
147 // X64-DAG:   @"?beta@@YA_N_J_W@Z"
148   alpha(0.f, 0.0);
149   return false;
150 }
151 
152 // CHECK-DAG: @"?alpha@@YGXMN@Z"
153 // X64-DAG:   @"?alpha@@YAXMN@Z"
154 
155 // Make sure tag-type mangling works.
156 void gamma(class foo, struct bar, union baz, enum quux) {}
157 // CHECK-DAG: @"?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z"
158 // X64-DAG:   @"?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z"
159 
160 // Make sure pointer/reference-type mangling works.
161 void delta(int * const a, const long &) {}
162 // CHECK-DAG: @"?delta@@YAXQAHABJ@Z"
163 // X64-DAG:   @"?delta@@YAXQEAHAEBJ@Z"
164 
165 // Array mangling.
166 void epsilon(int a[][10][20]) {}
167 // CHECK-DAG: @"?epsilon@@YAXQAY19BE@H@Z"
168 // X64-DAG:   @"?epsilon@@YAXQEAY19BE@H@Z"
169 
170 void zeta(int (*)(int, int)) {}
171 // CHECK-DAG: @"?zeta@@YAXP6AHHH@Z@Z"
172 // X64-DAG:   @"?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: @"?eta@@YAXP_EAHHH@Z@Z"
178 
179 typedef int theta_arg(int,int);
180 void theta(theta_arg^ block) {}
181 // CHECK-DAG: @"?theta@@YAXP_EAHHH@Z@Z"
182 
183 void operator_new_delete() {
184   char *ptr = new char;
185 // CHECK-DAG: @"??2@YAPAXI@Z"
186 
187   delete ptr;
188 // CHECK-DAG: @"??3@YAXPAX@Z"
189 
190   char *array = new char[42];
191 // CHECK-DAG: @"??_U@YAPAXI@Z"
192 
193   delete [] array;
194 // CHECK-DAG: @"??_V@YAXPAX@Z"
195 }
196 
197 // PR13022
198 void (redundant_parens)();
199 void redundant_parens_use() { redundant_parens(); }
200 // CHECK-DAG: @"?redundant_parens@@YAXXZ"
201 // X64-DAG:   @"?redundant_parens@@YAXXZ"
202 
203 // PR13047
204 typedef double RGB[3];
205 RGB color1;
206 // CHECK-DAG: @"?color1@@3PANA"
207 extern const RGB color2 = {};
208 // CHECK-DAG: @"?color2@@3QBNB"
209 extern RGB const color3[5] = {};
210 // CHECK-DAG: @"?color3@@3QAY02$$CBNA"
211 extern RGB const ((color4)[5]) = {};
212 // CHECK-DAG: @"?color4@@3QAY02$$CBNA"
213 
214 struct B;
215 volatile int B::* volatile memptr1;
216 // X64-DAG: @"?memptr1@@3RESB@@HES1@"
217 volatile int B::* memptr2;
218 // X64-DAG: @"?memptr2@@3PESB@@HES1@"
219 int B::* volatile memptr3;
220 // X64-DAG: @"?memptr3@@3REQB@@HEQ1@"
221 typedef int (*fun)();
222 volatile fun B::* volatile funmemptr1;
223 // X64-DAG: @"?funmemptr1@@3RESB@@R6AHXZES1@"
224 volatile fun B::* funmemptr2;
225 // X64-DAG: @"?funmemptr2@@3PESB@@R6AHXZES1@"
226 fun B::* volatile funmemptr3;
227 // X64-DAG: @"?funmemptr3@@3REQB@@P6AHXZEQ1@"
228 void (B::* volatile memptrtofun1)();
229 // X64-DAG: @"?memptrtofun1@@3R8B@@EAAXXZEQ1@"
230 const void (B::* memptrtofun2)();
231 // X64-DAG: @"?memptrtofun2@@3P8B@@EAAXXZEQ1@"
232 volatile void (B::* memptrtofun3)();
233 // X64-DAG: @"?memptrtofun3@@3P8B@@EAAXXZEQ1@"
234 int (B::* volatile memptrtofun4)();
235 // X64-DAG: @"?memptrtofun4@@3R8B@@EAAHXZEQ1@"
236 volatile int (B::* memptrtofun5)();
237 // X64-DAG: @"?memptrtofun5@@3P8B@@EAA?CHXZEQ1@"
238 const int (B::* memptrtofun6)();
239 // X64-DAG: @"?memptrtofun6@@3P8B@@EAA?BHXZEQ1@"
240 fun (B::* volatile memptrtofun7)();
241 // X64-DAG: @"?memptrtofun7@@3R8B@@EAAP6AHXZXZEQ1@"
242 volatile fun (B::* memptrtofun8)();
243 // X64-DAG: @"?memptrtofun8@@3P8B@@EAAR6AHXZXZEQ1@"
244 const fun (B::* memptrtofun9)();
245 // X64-DAG: @"?memptrtofun9@@3P8B@@EAAQ6AHXZXZEQ1@"
246 
247 // PR12603
248 enum E {};
249 // CHECK-DAG: "?fooE@@YA?AW4E@@XZ"
250 // X64-DAG:   "?fooE@@YA?AW4E@@XZ"
251 E fooE() { return E(); }
252 
253 class X {};
254 // CHECK-DAG: "?fooX@@YA?AVX@@XZ"
255 // X64-DAG:   "?fooX@@YA?AVX@@XZ"
256 X fooX() { return X(); }
257 
258 namespace PR13182 {
259   extern char s0[];
260   // CHECK-DAG: @"?s0@PR13182@@3PADA"
261   extern char s1[42];
262   // CHECK-DAG: @"?s1@PR13182@@3PADA"
263   extern const char s2[];
264   // CHECK-DAG: @"?s2@PR13182@@3QBDB"
265   extern const char s3[42];
266   // CHECK-DAG: @"?s3@PR13182@@3QBDB"
267   extern volatile char s4[];
268   // CHECK-DAG: @"?s4@PR13182@@3RCDC"
269   extern const volatile char s5[];
270   // CHECK-DAG: @"?s5@PR13182@@3SDDD"
271   extern const char* const* s6;
272   // CHECK-DAG: @"?s6@PR13182@@3PBQBDB"
273 
274   char foo() {
275     return s0[0] + s1[0] + s2[0] + s3[0] + s4[0] + s5[0] + s6[0][0];
276   }
277 }
278 
279 extern "C" inline void extern_c_func() {
280   static int local;
281 // CHECK-DAG: @"?local@?1??extern_c_func@@9@4HA"
282 // X64-DAG:   @"?local@?1??extern_c_func@@9@4HA"
283 }
284 
285 void call_extern_c_func() {
286   extern_c_func();
287 }
288 
289 int main() { return 0; }
290 // CHECK-DAG: @main
291 // X64-DAG:   @main
292 
293 int wmain() { return 0; }
294 // CHECK-DAG: @wmain
295 // X64-DAG:   @wmain
296 
297 int WinMain() { return 0; }
298 // CHECK-DAG: @WinMain
299 // X64-DAG:   @WinMain
300 
301 int wWinMain() { return 0; }
302 // CHECK-DAG: @wWinMain
303 // X64-DAG:   @wWinMain
304 
305 int DllMain() { return 0; }
306 // CHECK-DAG: @DllMain
307 // X64-DAG:   @DllMain
308 
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: @"?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 
318 int call_inline_function_with_local_type() {
319   return inline_function_with_local_type();
320 }
321 
322 template <typename T>
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: @"?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 
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 
349 void *OverloadedNewDelete::operator new(__SIZE_TYPE__ s) { return 0; }
350 void *OverloadedNewDelete::operator new[](__SIZE_TYPE__ s) { return 0; }
351 void OverloadedNewDelete::operator delete(void *) { }
352 void OverloadedNewDelete::operator delete[](void *) { }
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 
380 void *TypedefNewDelete::operator new(__SIZE_TYPE__ s) { return 0; }
381 void *TypedefNewDelete::operator new[](__SIZE_TYPE__ s) { return 0; }
382 void TypedefNewDelete::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 
390 void __vectorcall vector_func() { }
391 // CHECK-DAG: @"?vector_func@@YQXXZ"
392 
393 template <void (*)(void)>
394 void fn_tmpl() {}
395 
396 template void fn_tmpl<extern_c_func>();
397 // CHECK-DAG: @"??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ"
398 
399 extern "C" void __attribute__((overloadable)) overloaded_fn() {}
400 // CHECK-DAG: @"?overloaded_fn@@$$J0YAXXZ"
401 
402 extern "C" void overloaded_fn2() {}
403 // CHECK-DAG: @overloaded_fn2
404 //
405 extern "C" void __attribute__((overloadable)) overloaded_fn3();
406 extern "C" void overloaded_fn3() {}
407 // CHECK-DAG: @overloaded_fn3
408 
409 namespace UnnamedType {
410 struct S {
411   typedef struct {} *T1[1];
412   typedef struct {} T2;
413   typedef struct {} *T3, T4;
414   using T5 = struct {};
415   using T6 = struct {} *;
416 };
417 void f(S::T1) {}
418 void f(S::T2) {}
419 void f(S::T3) {}
420 void f(S::T4) {}
421 void f(S::T5) {}
422 void f(S::T6) {}
423 // CHECK-DAG: @"?f@UnnamedType@@YAXQAPAU<unnamed-type-T1>@S@1@@Z"
424 // CHECK-DAG: @"?f@UnnamedType@@YAXUT2@S@1@@Z"
425 // CHECK-DAG: @"?f@UnnamedType@@YAXPAUT4@S@1@@Z"
426 // CHECK-DAG: @"?f@UnnamedType@@YAXUT4@S@1@@Z"
427 // CHECK-DAG: @"?f@UnnamedType@@YAXUT5@S@1@@Z"
428 // CHECK-DAG: @"?f@UnnamedType@@YAXPAU<unnamed-type-T6>@S@1@@Z"
429 
430 // X64-DAG: @"?f@UnnamedType@@YAXQEAPEAU<unnamed-type-T1>@S@1@@Z"
431 // X64-DAG: @"?f@UnnamedType@@YAXUT2@S@1@@Z"
432 // X64-DAG: @"?f@UnnamedType@@YAXPEAUT4@S@1@@Z"(%"struct.UnnamedType::S::T4"
433 // X64-DAG: @"?f@UnnamedType@@YAXUT4@S@1@@Z"
434 // X64-DAG: @"?f@UnnamedType@@YAXUT5@S@1@@Z"
435 // X64-DAG: @"?f@UnnamedType@@YAXPEAU<unnamed-type-T6>@S@1@@Z"
436 }
437 
438 namespace PassObjectSize {
439 // NOTE: This mangling is subject to change.
440 // Reiterating from the comment in MicrosoftMangle, the scheme is pretend a
441 // parameter of type __clang::__pass_object_sizeN exists after each pass object
442 // size param P, where N is the Type of the pass_object_size attribute on P.
443 //
444 // e.g. we want to mangle:
445 //   void foo(void *const __attribute__((pass_object_size(0))));
446 // as if it were
447 //   namespace __clang { enum __pass_object_size0 : size_t {}; }
448 //   void foo(void *const, __clang::__pass_object_size0);
449 // where __clang is a top-level namespace.
450 
451 // CHECK-DAG: define dso_local i32 @"?foo@PassObjectSize@@YAHQAHW4__pass_object_size0@__clang@@@Z"
452 int foo(int *const i __attribute__((pass_object_size(0)))) { return 0; }
453 // CHECK-DAG: define dso_local i32 @"?bar@PassObjectSize@@YAHQAHW4__pass_object_size1@__clang@@@Z"
454 int bar(int *const i __attribute__((pass_object_size(1)))) { return 0; }
455 // CHECK-DAG: define dso_local i32 @"?qux@PassObjectSize@@YAHQAHW4__pass_object_size1@__clang@@0W4__pass_object_size0@3@@Z"
456 int qux(int *const i __attribute__((pass_object_size(1))), int *const j __attribute__((pass_object_size(0)))) { return 0; }
457 // CHECK-DAG: define dso_local i32 @"?zot@PassObjectSize@@YAHQAHW4__pass_object_size1@__clang@@01@Z"
458 int zot(int *const i __attribute__((pass_object_size(1))), int *const j __attribute__((pass_object_size(1)))) { return 0; }
459 }
460 
461 namespace Atomic {
462 // CHECK-DAG: define dso_local void @"?f@Atomic@@YAXU?$_Atomic@H@__clang@@@Z"(
463 void f(_Atomic(int)) {}
464 }
465 namespace Complex {
466 // CHECK-DAG: define dso_local void @"?f@Complex@@YAXU?$_Complex@H@__clang@@@Z"(
467 void f(_Complex int) {}
468 }
469 
470 namespace PR26029 {
471 template <class>
472 struct L {
473   L() {}
474 };
475 template <class>
476 class H;
477 struct M : L<H<int *> > {};
478 
479 template <class>
480 struct H {};
481 
482 template <class GT>
483 void m_fn3() {
484   (H<GT *>());
485   M();
486 }
487 
488 void runOnFunction() {
489   L<H<int *> > b;
490   m_fn3<int>();
491 }
492 // CHECK-DAG: call {{.*}} @"??0?$L@V?$H@PAH@PR26029@@@PR26029@@QAE@XZ"
493 }
494