1 // RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
2 // RUN: %clang_cc1 -fms-compatibility -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@@DA"
17 // CHECK: @"\01?l@@3P8foo@@AEHH@ZA"
18 // CHECK: @"\01?color1@@3PANA"
19 // CHECK: @"\01?color2@@3QBNB"
20 // CHECK: @"\01?color3@@3QAY02$$CBNA"
21 // CHECK: @"\01?color4@@3QAY02$$CBNA"
22 
23 int a;
24 
25 namespace N {
26   int b;
27 
28   namespace {
29     int anonymous;
30   }
31 }
32 
33 static int c;
34 int _c(void) {return N::anonymous + c;}
35 // CHECK: @"\01?_c@@YAHXZ"
36 
37 class foo {
38   static const short d;
39 protected:
40   static volatile long e;
41 public:
42   static const volatile char f;
43   int operator+(int a);
44   foo(){}
45 //CHECK: @"\01??0foo@@QAE@XZ"
46 
47   ~foo(){}
48 //CHECK: @"\01??1foo@@QAE@XZ"
49 
50   foo(int i){}
51 //CHECK: @"\01??0foo@@QAE@H@Z"
52 
53   foo(char *q){}
54 //CHECK: @"\01??0foo@@QAE@PAD@Z"
55 
56   static foo* static_method() { return 0; }
57 
58 }f,s1(1),s2((char*)0);
59 
60 typedef foo (foo2);
61 
62 struct bar {
63   static int g;
64 };
65 
66 union baz {
67   int a;
68   char b;
69   double c;
70 };
71 
72 enum quux {
73   qone,
74   qtwo,
75   qthree
76 };
77 
78 foo bar() { return foo(); }
79 //CHECK: @"\01?bar@@YA?AVfoo@@XZ"
80 
81 int foo::operator+(int a) {
82 //CHECK: @"\01??Hfoo@@QAEHH@Z"
83 
84   foo::static_method();
85 //CHECK: @"\01?static_method@foo@@SAPAV1@XZ"
86   bar();
87   return a;
88 }
89 
90 const short foo::d = 0;
91 volatile long foo::e;
92 const volatile char foo::f = 'C';
93 
94 int bar::g;
95 
96 extern int * const h1 = &a;
97 extern const int * const h2 = &a;
98 
99 int i[10][20];
100 
101 int (__stdcall *j)(signed char, unsigned char);
102 
103 const volatile char foo2::*k;
104 
105 int (foo2::*l)(int);
106 
107 // Static functions are mangled, too.
108 // Also make sure calling conventions, arglists, and throw specs work.
109 static void __stdcall alpha(float a, double b) throw() {}
110 bool __fastcall beta(long long a, wchar_t b) throw(signed char, unsigned char) {
111 // CHECK: @"\01?beta@@YI_N_J_W@Z"
112   alpha(0.f, 0.0);
113   return false;
114 }
115 
116 // CHECK: @"\01?alpha@@YGXMN@Z"
117 // X64: @"\01?alpha@@YAXMN@Z"
118 
119 // Make sure tag-type mangling works.
120 void gamma(class foo, struct bar, union baz, enum quux) {}
121 // CHECK: @"\01?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z"
122 
123 // Make sure pointer/reference-type mangling works.
124 void delta(int * const a, const long &) {}
125 // CHECK: @"\01?delta@@YAXQAHABJ@Z"
126 
127 // Array mangling.
128 void epsilon(int a[][10][20]) {}
129 // CHECK: @"\01?epsilon@@YAXQAY19BE@H@Z"
130 
131 void zeta(int (*)(int, int)) {}
132 // CHECK: @"\01?zeta@@YAXP6AHHH@Z@Z"
133 
134 // Blocks mangling (Clang extension). A block should be mangled slightly
135 // differently from a similar function pointer.
136 void eta(int (^)(int, int)) {}
137 // CHECK: @"\01?eta@@YAXP_EAHHH@Z@Z"
138 
139 typedef int theta_arg(int,int);
140 void theta(theta_arg^ block) {}
141 // CHECK: @"\01?theta@@YAXP_EAHHH@Z@Z"
142 
143 void operator_new_delete() {
144   char *ptr = new char;
145 // CHECK: @"\01??2@YAPAXI@Z"
146 
147   delete ptr;
148 // CHECK: @"\01??3@YAXPAX@Z"
149 
150   char *array = new char[42];
151 // CHECK: @"\01??_U@YAPAXI@Z"
152 
153   delete [] array;
154 // CHECK: @"\01??_V@YAXPAX@Z"
155 }
156 
157 // PR13022
158 void (redundant_parens)();
159 void redundant_parens_use() { redundant_parens(); }
160 // CHECK: @"\01?redundant_parens@@YAXXZ"
161 
162 // PR13047
163 typedef double RGB[3];
164 RGB color1;
165 extern const RGB color2 = {};
166 extern RGB const color3[5] = {};
167 extern RGB const ((color4)[5]) = {};
168 
169 // PR12603
170 enum E {};
171 // CHECK: "\01?fooE@@YA?AW4E@@XZ"
172 E fooE() { return E(); }
173 
174 class X {};
175 // CHECK: "\01?fooX@@YA?AVX@@XZ"
176 X fooX() { return X(); }
177 
178 namespace PR13182 {
179   extern char s0[];
180   // CHECK: @"\01?s0@PR13182@@3PADA"
181   extern char s1[42];
182   // CHECK: @"\01?s1@PR13182@@3PADA"
183   extern const char s2[];
184   // CHECK: @"\01?s2@PR13182@@3QBDB"
185   extern const char s3[42];
186   // CHECK: @"\01?s3@PR13182@@3QBDB"
187   extern volatile char s4[];
188   // CHECK: @"\01?s4@PR13182@@3RCDC"
189   extern const volatile char s5[];
190   // CHECK: @"\01?s5@PR13182@@3SDDD"
191   extern const char* const* s6;
192   // CHECK: @"\01?s6@PR13182@@3PBQBDB"
193 
194   char foo() {
195     return s0[0] + s1[0] + s2[0] + s3[0] + s4[0] + s5[0] + s6[0][0];
196   }
197 }
198