1 // RUN: %clang_cc1 -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
2 // RUN: %clang_cc1 -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s
3 
4 // CHECK: @"\01?a@@3HA"
5 // CHECK: @"\01?b@N@@3HA"
6 // CHECK: @"\01?anonymous@?A@N@@3HA"
7 // CHECK: @c
8 // CHECK: @"\01?d@foo@@0FB"
9 // CHECK: @"\01?e@foo@@1JC"
10 // CHECK: @"\01?f@foo@@2DD"
11 // CHECK: @"\01?g@bar@@2HA"
12 // CHECK: @"\01?h1@@3QAHA"
13 // CHECK: @"\01?h2@@3QBHB"
14 // CHECK: @"\01?i@@3PAY0BE@HA"
15 // CHECK: @"\01?j@@3P6GHCE@ZA"
16 // CHECK: @"\01?k@@3PTfoo@@DT1@"
17 // X64: @"\01?k@@3PETfoo@@DET1@"
18 // CHECK: @"\01?l@@3P8foo@@AEHH@ZQ1@"
19 // CHECK: @"\01?color1@@3PANA"
20 // CHECK: @"\01?color2@@3QBNB"
21 // CHECK: @"\01?color3@@3QAY02$$CBNA"
22 // CHECK: @"\01?color4@@3QAY02$$CBNA"
23 // X64: @"\01?memptr1@@3RESB@@HES1@"
24 // X64: @"\01?memptr2@@3PESB@@HES1@"
25 // X64: @"\01?memptr3@@3REQB@@HEQ1@"
26 // X64: @"\01?funmemptr1@@3RESB@@R6AHXZES1@"
27 // X64: @"\01?funmemptr2@@3PESB@@R6AHXZES1@"
28 // X64: @"\01?funmemptr3@@3REQB@@P6AHXZEQ1@"
29 // X64: @"\01?memptrtofun1@@3R8B@@EAAXXZEQ1@"
30 // X64: @"\01?memptrtofun2@@3P8B@@EAAXXZEQ1@"
31 // X64: @"\01?memptrtofun3@@3P8B@@EAAXXZEQ1@"
32 // X64: @"\01?memptrtofun4@@3R8B@@EAAHXZEQ1@"
33 // X64: @"\01?memptrtofun5@@3P8B@@EAA?CHXZEQ1@"
34 // X64: @"\01?memptrtofun6@@3P8B@@EAA?BHXZEQ1@"
35 // X64: @"\01?memptrtofun7@@3R8B@@EAAP6AHXZXZEQ1@"
36 // X64: @"\01?memptrtofun8@@3P8B@@EAAR6AHXZXZEQ1@"
37 // X64: @"\01?memptrtofun9@@3P8B@@EAAQ6AHXZXZEQ1@"
38 
39 int a;
40 
41 namespace N {
42   int b;
43 
44   namespace {
45     int anonymous;
46   }
47 }
48 
49 static int c;
50 int _c(void) {return N::anonymous + c;}
51 // CHECK: @"\01?_c@@YAHXZ"
52 // X64: @"\01?_c@@YAHXZ"
53 
54 class foo {
55   static const short d;
56 protected:
57   static volatile long e;
58 public:
59   static const volatile char f;
60   int operator+(int a);
61   foo(){}
62 //CHECK: @"\01??0foo@@QAE@XZ"
63 //X64: @"\01??0foo@@QEAA@XZ"
64 
65   ~foo(){}
66 //CHECK: @"\01??1foo@@QAE@XZ"
67 //X64: @"\01??1foo@@QEAA@XZ
68 
69   foo(int i){}
70 //CHECK: @"\01??0foo@@QAE@H@Z"
71 //X64: @"\01??0foo@@QEAA@H@Z"
72 
73   foo(char *q){}
74 //CHECK: @"\01??0foo@@QAE@PAD@Z"
75 //X64: @"\01??0foo@@QEAA@PEAD@Z"
76 
77   static foo* static_method() { return 0; }
78 
79 }f,s1(1),s2((char*)0);
80 
81 typedef foo (foo2);
82 
83 struct bar {
84   static int g;
85 };
86 
87 union baz {
88   int a;
89   char b;
90   double c;
91 };
92 
93 enum quux {
94   qone,
95   qtwo,
96   qthree
97 };
98 
99 foo bar() { return foo(); }
100 //CHECK: @"\01?bar@@YA?AVfoo@@XZ"
101 //X64: @"\01?bar@@YA?AVfoo@@XZ"
102 
103 int foo::operator+(int a) {
104 //CHECK: @"\01??Hfoo@@QAEHH@Z"
105 //X64: @"\01??Hfoo@@QEAAHH@Z"
106 
107   foo::static_method();
108 //CHECK: @"\01?static_method@foo@@SAPAV1@XZ"
109 //X64: @"\01?static_method@foo@@SAPEAV1@XZ"
110   bar();
111   return a;
112 }
113 
114 const short foo::d = 0;
115 volatile long foo::e;
116 const volatile char foo::f = 'C';
117 
118 int bar::g;
119 
120 extern int * const h1 = &a;
121 extern const int * const h2 = &a;
122 
123 int i[10][20];
124 
125 int (__stdcall *j)(signed char, unsigned char);
126 
127 const volatile char foo2::*k;
128 
129 int (foo2::*l)(int);
130 
131 // Static functions are mangled, too.
132 // Also make sure calling conventions, arglists, and throw specs work.
133 static void __stdcall alpha(float a, double b) throw() {}
134 bool __fastcall beta(long long a, wchar_t b) throw(signed char, unsigned char) {
135 // CHECK: @"\01?beta@@YI_N_J_W@Z"
136 // X64: @"\01?beta@@YA_N_J_W@Z"
137   alpha(0.f, 0.0);
138   return false;
139 }
140 
141 // CHECK: @"\01?alpha@@YGXMN@Z"
142 // X64: @"\01?alpha@@YAXMN@Z"
143 
144 // Make sure tag-type mangling works.
145 void gamma(class foo, struct bar, union baz, enum quux) {}
146 // CHECK: @"\01?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z"
147 // X64: @"\01?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z"
148 
149 // Make sure pointer/reference-type mangling works.
150 void delta(int * const a, const long &) {}
151 // CHECK: @"\01?delta@@YAXQAHABJ@Z"
152 // X64: @"\01?delta@@YAXQEAHAEBJ@Z"
153 
154 // Array mangling.
155 void epsilon(int a[][10][20]) {}
156 // CHECK: @"\01?epsilon@@YAXQAY19BE@H@Z"
157 // X64: @"\01?epsilon@@YAXQEAY19BE@H@Z"
158 
159 void zeta(int (*)(int, int)) {}
160 // CHECK: @"\01?zeta@@YAXP6AHHH@Z@Z"
161 // X64: @"\01?zeta@@YAXP6AHHH@Z@Z"
162 
163 // Blocks mangling (Clang extension). A block should be mangled slightly
164 // differently from a similar function pointer.
165 void eta(int (^)(int, int)) {}
166 // CHECK: @"\01?eta@@YAXP_EAHHH@Z@Z"
167 
168 typedef int theta_arg(int,int);
169 void theta(theta_arg^ block) {}
170 // CHECK: @"\01?theta@@YAXP_EAHHH@Z@Z"
171 
172 void operator_new_delete() {
173   char *ptr = new char;
174 // CHECK: @"\01??2@YAPAXI@Z"
175 
176   delete ptr;
177 // CHECK: @"\01??3@YAXPAX@Z"
178 
179   char *array = new char[42];
180 // CHECK: @"\01??_U@YAPAXI@Z"
181 
182   delete [] array;
183 // CHECK: @"\01??_V@YAXPAX@Z"
184 }
185 
186 // PR13022
187 void (redundant_parens)();
188 void redundant_parens_use() { redundant_parens(); }
189 // CHECK: @"\01?redundant_parens@@YAXXZ"
190 // X64: @"\01?redundant_parens@@YAXXZ"
191 
192 // PR13047
193 typedef double RGB[3];
194 RGB color1;
195 extern const RGB color2 = {};
196 extern RGB const color3[5] = {};
197 extern RGB const ((color4)[5]) = {};
198 
199 struct B;
200 volatile int B::* volatile memptr1;
201 volatile int B::* memptr2;
202 int B::* volatile memptr3;
203 typedef int (*fun)();
204 volatile fun B::* volatile funmemptr1;
205 volatile fun B::* funmemptr2;
206 fun B::* volatile funmemptr3;
207 void (B::* volatile memptrtofun1)();
208 const void (B::* memptrtofun2)();
209 volatile void (B::* memptrtofun3)();
210 int (B::* volatile memptrtofun4)();
211 volatile int (B::* memptrtofun5)();
212 const int (B::* memptrtofun6)();
213 fun (B::* volatile memptrtofun7)();
214 volatile fun (B::* memptrtofun8)();
215 const fun (B::* memptrtofun9)();
216 
217 // PR12603
218 enum E {};
219 // CHECK: "\01?fooE@@YA?AW4E@@XZ"
220 // X64: "\01?fooE@@YA?AW4E@@XZ"
221 E fooE() { return E(); }
222 
223 class X {};
224 // CHECK: "\01?fooX@@YA?AVX@@XZ"
225 // X64: "\01?fooX@@YA?AVX@@XZ"
226 X fooX() { return X(); }
227 
228 namespace PR13182 {
229   extern char s0[];
230   // CHECK: @"\01?s0@PR13182@@3PADA"
231   extern char s1[42];
232   // CHECK: @"\01?s1@PR13182@@3PADA"
233   extern const char s2[];
234   // CHECK: @"\01?s2@PR13182@@3QBDB"
235   extern const char s3[42];
236   // CHECK: @"\01?s3@PR13182@@3QBDB"
237   extern volatile char s4[];
238   // CHECK: @"\01?s4@PR13182@@3RCDC"
239   extern const volatile char s5[];
240   // CHECK: @"\01?s5@PR13182@@3SDDD"
241   extern const char* const* s6;
242   // CHECK: @"\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