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