blob: 6441d67a758a095aeebe84974d3bb9e67c842667 [file] [log] [blame]
Charles Davisee743f92010-11-09 18:04:24 +00001// RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
Aaron Ballman82bfa192012-10-02 14:26:08 +00002// RUN: %clang_cc1 -fms-compatibility -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s
Charles Davise60cea82010-06-11 03:07:32 +00003
Charles Davisb021f8b2010-06-14 05:29:01 +00004// CHECK: @"\01?a@@3HA"
5// CHECK: @"\01?b@N@@3HA"
Timur Iskhodzhanov79b7cc52012-11-26 08:55:48 +00006// CHECK: @"\01?anonymous@?A@N@@3HA"
Charles Davis570d2762010-06-12 08:11:16 +00007// CHECK: @c
Charles Davisb021f8b2010-06-14 05:29:01 +00008// CHECK: @"\01?d@foo@@0FB"
9// CHECK: @"\01?e@foo@@1JC"
10// CHECK: @"\01?f@foo@@2DD"
Charles Davisc62458f2010-06-18 07:51:00 +000011// CHECK: @"\01?g@bar@@2HA"
Timur Iskhodzhanova04ca5c2012-09-03 09:08:10 +000012// CHECK: @"\01?h1@@3QAHA"
13// CHECK: @"\01?h2@@3QBHB"
Charles Davis08778262010-07-03 08:15:16 +000014// CHECK: @"\01?i@@3PAY0BE@HA"
Charles Davis1139da12010-07-03 05:53:41 +000015// CHECK: @"\01?j@@3P6GHCE@ZA"
Charles Daviscd712cb2010-07-03 08:01:32 +000016// CHECK: @"\01?k@@3PTfoo@@DA"
Charles Davisee743f92010-11-09 18:04:24 +000017// CHECK: @"\01?l@@3P8foo@@AEHH@ZA"
Richard Smithc0838d22012-06-08 00:37:04 +000018// CHECK: @"\01?color1@@3PANA"
Timur Iskhodzhanova04ca5c2012-09-03 09:08:10 +000019// CHECK: @"\01?color2@@3QBNB"
Timur Iskhodzhanova5427442012-07-23 09:32:54 +000020
Timur Iskhodzhanova04ca5c2012-09-03 09:08:10 +000021// FIXME: The following three tests currently fail, see http://llvm.org/PR13182
Timur Iskhodzhanova5427442012-07-23 09:32:54 +000022// Replace "CHECK-NOT" with "CHECK" when it is fixed.
Timur Iskhodzhanov1cc9be02012-07-23 09:43:03 +000023// CHECK-NOT: @"\01?color3@@3QAY02$$CBNA"
24// CHECK-NOT: @"\01?color4@@3QAY02$$CBNA"
Charles Davis570d2762010-06-12 08:11:16 +000025
26int a;
Charles Davise60cea82010-06-11 03:07:32 +000027
Timur Iskhodzhanov79b7cc52012-11-26 08:55:48 +000028namespace N {
29 int b;
30
31 namespace {
32 int anonymous;
33 }
34}
Charles Davis570d2762010-06-12 08:11:16 +000035
36static int c;
Timur Iskhodzhanov79b7cc52012-11-26 08:55:48 +000037int _c(void) {return N::anonymous + c;}
Charles Davis65161d12010-06-16 05:33:16 +000038// CHECK: @"\01?_c@@YAHXZ"
Charles Davis570d2762010-06-12 08:11:16 +000039
Charles Davisb021f8b2010-06-14 05:29:01 +000040class foo {
41 static const short d;
42protected:
43 static volatile long e;
44public:
45 static const volatile char f;
Charles Davis21e2a7e2010-06-17 06:47:31 +000046 int operator+(int a);
Michael J. Spencer50118da2011-12-01 09:55:00 +000047 foo(){}
48//CHECK: @"\01??0foo@@QAE@XZ"
49
50 ~foo(){}
51//CHECK: @"\01??1foo@@QAE@XZ"
52
53 foo(int i){}
54//CHECK: @"\01??0foo@@QAE@H@Z"
55
56 foo(char *q){}
57//CHECK: @"\01??0foo@@QAE@PAD@Z"
Timur Iskhodzhanovdf438042012-06-27 01:38:25 +000058
59 static foo* static_method() { return 0; }
60
Michael J. Spencer50118da2011-12-01 09:55:00 +000061}f,s1(1),s2((char*)0);
Charles Davisb021f8b2010-06-14 05:29:01 +000062
Richard Smithc0838d22012-06-08 00:37:04 +000063typedef foo (foo2);
64
Charles Davisc62458f2010-06-18 07:51:00 +000065struct bar {
66 static int g;
67};
68
69union baz {
70 int a;
71 char b;
72 double c;
73};
74
75enum quux {
76 qone,
77 qtwo,
78 qthree
79};
80
Timur Iskhodzhanovdf438042012-06-27 01:38:25 +000081foo bar() { return foo(); }
82//CHECK: @"\01?bar@@YA?AVfoo@@XZ"
83
84int foo::operator+(int a) {
85//CHECK: @"\01??Hfoo@@QAEHH@Z"
86
87 foo::static_method();
88//CHECK: @"\01?static_method@foo@@SAPAV1@XZ"
89 bar();
90 return a;
91}
Charles Davis21e2a7e2010-06-17 06:47:31 +000092
Charles Davisb021f8b2010-06-14 05:29:01 +000093const short foo::d = 0;
94volatile long foo::e;
95const volatile char foo::f = 'C';
96
Charles Davisc62458f2010-06-18 07:51:00 +000097int bar::g;
98
Timur Iskhodzhanova04ca5c2012-09-03 09:08:10 +000099extern int * const h1 = &a;
100extern const int * const h2 = &a;
Charles Davis3a0d41d2010-06-26 03:50:05 +0000101
Charles Davis0b8fe8c2010-06-30 08:09:57 +0000102int i[10][20];
103
Charles Davis1139da12010-07-03 05:53:41 +0000104int (__stdcall *j)(signed char, unsigned char);
105
Richard Smithc0838d22012-06-08 00:37:04 +0000106const volatile char foo2::*k;
Charles Daviscd712cb2010-07-03 08:01:32 +0000107
Richard Smithc0838d22012-06-08 00:37:04 +0000108int (foo2::*l)(int);
Charles Daviscd712cb2010-07-03 08:01:32 +0000109
Charles Davis65161d12010-06-16 05:33:16 +0000110// Static functions are mangled, too.
111// Also make sure calling conventions, arglists, and throw specs work.
112static void __stdcall alpha(float a, double b) throw() {}
113bool __fastcall beta(long long a, wchar_t b) throw(signed char, unsigned char) {
Charles Davis3a0d41d2010-06-26 03:50:05 +0000114// CHECK: @"\01?beta@@YI_N_J_W@Z"
Charles Davis65161d12010-06-16 05:33:16 +0000115 alpha(0.f, 0.0);
116 return false;
117}
118
Charles Davis3a0d41d2010-06-26 03:50:05 +0000119// CHECK: @"\01?alpha@@YGXMN@Z"
Aaron Ballman82bfa192012-10-02 14:26:08 +0000120// X64: @"\01?alpha@@YAXMN@Z"
Charles Davis65161d12010-06-16 05:33:16 +0000121
Charles Davisc62458f2010-06-18 07:51:00 +0000122// Make sure tag-type mangling works.
123void gamma(class foo, struct bar, union baz, enum quux) {}
124// CHECK: @"\01?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z"
125
Charles Davis3a0d41d2010-06-26 03:50:05 +0000126// Make sure pointer/reference-type mangling works.
127void delta(int * const a, const long &) {}
128// CHECK: @"\01?delta@@YAXQAHABJ@Z"
Charles Davis0b8fe8c2010-06-30 08:09:57 +0000129
Charles Davis4d254832010-07-03 16:56:59 +0000130// Array mangling.
Charles Davis0b8fe8c2010-06-30 08:09:57 +0000131void epsilon(int a[][10][20]) {}
Charles Davis08778262010-07-03 08:15:16 +0000132// CHECK: @"\01?epsilon@@YAXQAY19BE@H@Z"
Charles Davis4d254832010-07-03 16:56:59 +0000133
Timur Iskhodzhanovbae11d82012-07-26 13:41:30 +0000134void zeta(int (*)(int, int)) {}
135// CHECK: @"\01?zeta@@YAXP6AHHH@Z@Z"
136
137// Blocks mangling (Clang extension). A block should be mangled slightly
138// differently from a similar function pointer.
139void eta(int (^)(int, int)) {}
140// CHECK: @"\01?eta@@YAXP_EAHHH@Z@Z"
Charles Davis4d254832010-07-03 16:56:59 +0000141
John McCall2612e9f2012-08-25 01:12:56 +0000142typedef int theta_arg(int,int);
143void theta(theta_arg^ block) {}
144// CHECK: @"\01?theta@@YAXP_EAHHH@Z@Z"
145
John McCall3a8ac072012-05-01 02:33:44 +0000146void operator_new_delete() {
147 char *ptr = new char;
148// CHECK: @"\01??2@YAPAXI@Z"
149
150 delete ptr;
151// CHECK: @"\01??3@YAXPAX@Z"
152
153 char *array = new char[42];
154// CHECK: @"\01??_U@YAPAXI@Z"
155
John McCalle2b45e22012-05-01 05:23:51 +0000156 delete [] array;
157// CHECK: @"\01??_V@YAXPAX@Z"
John McCall3a8ac072012-05-01 02:33:44 +0000158}
Richard Smithbd1d18e2012-06-04 22:46:59 +0000159
160// PR13022
161void (redundant_parens)();
162void redundant_parens_use() { redundant_parens(); }
163// CHECK: @"\01?redundant_parens@@YAXXZ"
Richard Smithc0838d22012-06-08 00:37:04 +0000164
Timur Iskhodzhanova04ca5c2012-09-03 09:08:10 +0000165// PR13047
Richard Smithc0838d22012-06-08 00:37:04 +0000166typedef double RGB[3];
167RGB color1;
168extern const RGB color2 = {};
Timur Iskhodzhanova5427442012-07-23 09:32:54 +0000169extern RGB const color3[5] = {};
170extern RGB const ((color4)[5]) = {};
Richard Smith06e767d2012-06-21 02:52:27 +0000171
172// PR12603
173enum E {};
174// CHECK: "\01?fooE@@YA?AW4E@@XZ"
175E fooE() { return E(); }
176
177class X {};
178// CHECK: "\01?fooX@@YA?AVX@@XZ"
179X fooX() { return X(); }
Timur Iskhodzhanova04ca5c2012-09-03 09:08:10 +0000180
181namespace PR13182 {
182 extern char s0[];
183 // CHECK: @"\01?s0@PR13182@@3PADA"
184 extern char s1[42];
185 // CHECK: @"\01?s1@PR13182@@3PADA"
186 extern const char s2[];
187 // CHECK: @"\01?s2@PR13182@@3QBDB"
188 extern const char s3[42];
189 // CHECK: @"\01?s3@PR13182@@3QBDB"
190 extern volatile char s4[];
191 // CHECK: @"\01?s4@PR13182@@3RCDC"
192 extern const volatile char s5[];
193 // CHECK: @"\01?s5@PR13182@@3SDDD"
194 extern const char* const* s6;
195 // CHECK: @"\01?s6@PR13182@@3PBQBDB"
196
197 char foo() {
198 return s0[0] + s1[0] + s2[0] + s3[0] + s4[0] + s5[0] + s6[0][0];
199 }
200}