[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / mangle-ms-arg-qualifiers.cpp
blob23582c6c0316d40a9691ab31245817dadefe2b70
1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
2 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-win32 | FileCheck -check-prefix=X64 %s
4 void foo(const unsigned int) {}
5 // CHECK: "?foo@@YAXI@Z"
6 // X64: "?foo@@YAXI@Z"
8 void foo(const double) {}
9 // CHECK: "?foo@@YAXN@Z"
10 // X64: "?foo@@YAXN@Z"
12 void bar(const volatile double) {}
13 // CHECK: "?bar@@YAXN@Z"
14 // X64: "?bar@@YAXN@Z"
16 void foo_pad(char * x) {}
17 // CHECK: "?foo_pad@@YAXPAD@Z"
18 // X64: "?foo_pad@@YAXPEAD@Z"
20 void foo_pbd(const char * x) {}
21 // CHECK: "?foo_pbd@@YAXPBD@Z"
22 // X64: "?foo_pbd@@YAXPEBD@Z"
24 void foo_pcd(volatile char * x) {}
25 // CHECK: "?foo_pcd@@YAXPCD@Z"
26 // X64: "?foo_pcd@@YAXPECD@Z"
28 void foo_qad(char * const x) {}
29 // CHECK: "?foo_qad@@YAXQAD@Z"
30 // X64: "?foo_qad@@YAXQEAD@Z"
32 void foo_rad(char * volatile x) {}
33 // CHECK: "?foo_rad@@YAXRAD@Z"
34 // X64: "?foo_rad@@YAXREAD@Z"
36 void foo_sad(char * const volatile x) {}
37 // CHECK: "?foo_sad@@YAXSAD@Z"
38 // X64: "?foo_sad@@YAXSEAD@Z"
40 void foo_piad(char * __restrict x) {}
41 // CHECK: "?foo_piad@@YAXPIAD@Z"
42 // X64: "?foo_piad@@YAXPEIAD@Z"
44 void foo_qiad(char * const __restrict x) {}
45 // CHECK: "?foo_qiad@@YAXQIAD@Z"
46 // X64: "?foo_qiad@@YAXQEIAD@Z"
48 void foo_riad(char * volatile __restrict x) {}
49 // CHECK: "?foo_riad@@YAXRIAD@Z"
50 // X64: "?foo_riad@@YAXREIAD@Z"
52 void foo_siad(char * const volatile __restrict x) {}
53 // CHECK: "?foo_siad@@YAXSIAD@Z"
54 // X64: "?foo_siad@@YAXSEIAD@Z"
56 void foo_papad(char ** x) {}
57 // CHECK: "?foo_papad@@YAXPAPAD@Z"
58 // X64: "?foo_papad@@YAXPEAPEAD@Z"
60 void foo_papbd(char const ** x) {}
61 // CHECK: "?foo_papbd@@YAXPAPBD@Z"
62 // X64: "?foo_papbd@@YAXPEAPEBD@Z"
64 void foo_papcd(char volatile ** x) {}
65 // CHECK: "?foo_papcd@@YAXPAPCD@Z"
66 // X64: "?foo_papcd@@YAXPEAPECD@Z"
68 void foo_pbqad(char * const* x) {}
69 // CHECK: "?foo_pbqad@@YAXPBQAD@Z"
70 // X64: "?foo_pbqad@@YAXPEBQEAD@Z"
72 void foo_pcrad(char * volatile* x) {}
73 // CHECK: "?foo_pcrad@@YAXPCRAD@Z"
74 // X64: "?foo_pcrad@@YAXPECREAD@Z"
76 void foo_qapad(char ** const x) {}
77 // CHECK: "?foo_qapad@@YAXQAPAD@Z"
78 // X64: "?foo_qapad@@YAXQEAPEAD@Z"
80 void foo_rapad(char ** volatile x) {}
81 // CHECK: "?foo_rapad@@YAXRAPAD@Z"
82 // X64: "?foo_rapad@@YAXREAPEAD@Z"
84 void foo_pbqbd(const char * const* x) {}
85 // CHECK: "?foo_pbqbd@@YAXPBQBD@Z"
86 // X64: "?foo_pbqbd@@YAXPEBQEBD@Z"
88 void foo_pbqcd(volatile char * const* x) {}
89 // CHECK: "?foo_pbqcd@@YAXPBQCD@Z"
90 // X64: "?foo_pbqcd@@YAXPEBQECD@Z"
92 void foo_pcrbd(const char * volatile* x) {}
93 // CHECK: "?foo_pcrbd@@YAXPCRBD@Z"
94 // X64: "?foo_pcrbd@@YAXPECREBD@Z"
96 void foo_pcrcd(volatile char * volatile* x) {}
97 // CHECK: "?foo_pcrcd@@YAXPCRCD@Z"
98 // X64: "?foo_pcrcd@@YAXPECRECD@Z"
100 void foo_aad(char &x) {}
101 // CHECK: "?foo_aad@@YAXAAD@Z"
102 // X64: "?foo_aad@@YAXAEAD@Z"
104 void foo_abd(const char &x) {}
105 // CHECK: "?foo_abd@@YAXABD@Z"
106 // X64: "?foo_abd@@YAXAEBD@Z"
108 void foo_aapad(char *&x) {}
109 // CHECK: "?foo_aapad@@YAXAAPAD@Z"
110 // X64: "?foo_aapad@@YAXAEAPEAD@Z"
112 void foo_aapbd(const char *&x) {}
113 // CHECK: "?foo_aapbd@@YAXAAPBD@Z"
114 // X64: "?foo_aapbd@@YAXAEAPEBD@Z"
116 void foo_abqad(char * const &x) {}
117 // CHECK: "?foo_abqad@@YAXABQAD@Z"
118 // X64: "?foo_abqad@@YAXAEBQEAD@Z"
120 void foo_abqbd(const char * const &x) {}
121 // CHECK: "?foo_abqbd@@YAXABQBD@Z"
122 // X64: "?foo_abqbd@@YAXAEBQEBD@Z"
124 void foo_aay144h(int (&x)[5][5]) {}
125 // CHECK: "?foo_aay144h@@YAXAAY144H@Z"
126 // X64: "?foo_aay144h@@YAXAEAY144H@Z"
128 void foo_aay144cbh(const int (&x)[5][5]) {}
129 // CHECK: "?foo_aay144cbh@@YAXAAY144$$CBH@Z"
130 // X64: "?foo_aay144cbh@@YAXAEAY144$$CBH@Z"
132 void foo_qay144h(int (&&x)[5][5]) {}
133 // CHECK: "?foo_qay144h@@YAX$$QAY144H@Z"
134 // X64: "?foo_qay144h@@YAX$$QEAY144H@Z"
136 void foo_qay144cbh(const int (&&x)[5][5]) {}
137 // CHECK: "?foo_qay144cbh@@YAX$$QAY144$$CBH@Z"
138 // X64: "?foo_qay144cbh@@YAX$$QEAY144$$CBH@Z"
140 void foo_p6ahxz(int x()) {}
141 // CHECK: "?foo_p6ahxz@@YAXP6AHXZ@Z"
142 // X64: "?foo_p6ahxz@@YAXP6AHXZ@Z"
144 void foo_a6ahxz(int (&x)()) {}
145 // CHECK: "?foo_a6ahxz@@YAXA6AHXZ@Z"
146 // X64: "?foo_a6ahxz@@YAXA6AHXZ@Z"
148 void foo_q6ahxz(int (&&x)()) {}
149 // CHECK: "?foo_q6ahxz@@YAX$$Q6AHXZ@Z"
150 // X64: "?foo_q6ahxz@@YAX$$Q6AHXZ@Z"
152 void foo_qay04h(int x[5][5]) {}
153 // CHECK: "?foo_qay04h@@YAXQAY04H@Z"
154 // X64: "?foo_qay04h@@YAXQEAY04H@Z"
156 void foo_qay04cbh(const int x[5][5]) {}
157 // CHECK: "?foo_qay04cbh@@YAXQAY04$$CBH@Z"
158 // X64: "?foo_qay04cbh@@YAXQEAY04$$CBH@Z"
160 typedef double Vector[3];
162 void foo(Vector*) {}
163 // CHECK: "?foo@@YAXPAY02N@Z"
164 // X64: "?foo@@YAXPEAY02N@Z"
166 void foo(Vector) {}
167 // CHECK: "?foo@@YAXQAN@Z"
168 // X64: "?foo@@YAXQEAN@Z"
170 void foo_const(const Vector) {}
171 // CHECK: "?foo_const@@YAXQBN@Z"
172 // X64: "?foo_const@@YAXQEBN@Z"
174 void foo_volatile(volatile Vector) {}
175 // CHECK: "?foo_volatile@@YAXQCN@Z"
176 // X64: "?foo_volatile@@YAXQECN@Z"
178 void foo(Vector*, const Vector, const double) {}
179 // CHECK: "?foo@@YAXPAY02NQBNN@Z"
180 // X64: "?foo@@YAXPEAY02NQEBNN@Z"
182 typedef void (*ConstFunPtr)(int *const d);
183 void foo_fnptrconst(ConstFunPtr f) { }
184 // CHECK: "?foo_fnptrconst@@YAXP6AXQAH@Z@Z"
185 // X64: "?foo_fnptrconst@@YAXP6AXQEAH@Z@Z"
187 typedef void (*ArrayFunPtr)(int d[1]);
188 void foo_fnptrarray(ArrayFunPtr f) { }
189 // CHECK: "?foo_fnptrarray@@YAXP6AXQAH@Z@Z"
190 // X64: "?foo_fnptrarray@@YAXP6AXQEAH@Z@Z"
192 void foo_fnptrbackref1(ArrayFunPtr f1, ArrayFunPtr f2) { }
193 // CHECK: "?foo_fnptrbackref1@@YAXP6AXQAH@Z1@Z"
194 // X64: "?foo_fnptrbackref1@@YAXP6AXQEAH@Z1@Z"
196 void foo_fnptrbackref2(ArrayFunPtr f1, ConstFunPtr f2) { }
197 // CHECK: "?foo_fnptrbackref2@@YAXP6AXQAH@Z1@Z"
198 // X64: "?foo_fnptrbackref2@@YAXP6AXQEAH@Z1@Z"
200 typedef void (*NormalFunPtr)(int *d);
201 void foo_fnptrbackref3(ArrayFunPtr f1, NormalFunPtr f2) { }
202 // CHECK: "?foo_fnptrbackref3@@YAXP6AXQAH@Z1@Z"
203 // X64: "?foo_fnptrbackref3@@YAXP6AXQEAH@Z1@Z"
205 void foo_fnptrbackref4(NormalFunPtr f1, ArrayFunPtr f2) { }
206 // CHECK: "?foo_fnptrbackref4@@YAXP6AXPAH@Z1@Z"
207 // X64: "?foo_fnptrbackref4@@YAXP6AXPEAH@Z1@Z"
209 ArrayFunPtr ret_fnptrarray() { return 0; }
210 // CHECK: "?ret_fnptrarray@@YAP6AXQAH@ZXZ"
211 // X64: "?ret_fnptrarray@@YAP6AXQEAH@ZXZ"
213 // Test that we mangle the forward decl when we have a redeclaration with a
214 // slightly different type.
215 void mangle_fwd(char * const x);
216 void mangle_fwd(char * x) {}
217 // CHECK: "?mangle_fwd@@YAXQAD@Z"
218 // X64: "?mangle_fwd@@YAXQEAD@Z"
220 void mangle_no_fwd(char * x) {}
221 // CHECK: "?mangle_no_fwd@@YAXPAD@Z"
222 // X64: "?mangle_no_fwd@@YAXPEAD@Z"
224 // The first argument gets mangled as-if it were written "int *const"
225 // The second arg should not form a backref because it isn't qualified
226 void mangle_no_backref0(int[], int *) {}
227 // CHECK: "?mangle_no_backref0@@YAXQAHPAH@Z"
228 // X64: "?mangle_no_backref0@@YAXQEAHPEAH@Z"
230 void mangle_no_backref1(int[], int *const) {}
231 // CHECK: "?mangle_no_backref1@@YAXQAHQAH@Z"
232 // X64: "?mangle_no_backref1@@YAXQEAHQEAH@Z"
234 typedef void fun_type(void);
235 typedef void (*ptr_to_fun_type)(void);
237 // Pointer to function types don't backref with function types
238 void mangle_no_backref2(fun_type, ptr_to_fun_type) {}
239 // CHECK: "?mangle_no_backref2@@YAXP6AXXZP6AXXZ@Z"
240 // X64: "?mangle_no_backref2@@YAXP6AXXZP6AXXZ@Z"
242 void mangle_yes_backref0(int[], int []) {}
243 // CHECK: "?mangle_yes_backref0@@YAXQAH0@Z"
244 // X64: "?mangle_yes_backref0@@YAXQEAH0@Z"
246 void mangle_yes_backref1(int *const, int *const) {}
247 // CHECK: "?mangle_yes_backref1@@YAXQAH0@Z"
248 // X64: "?mangle_yes_backref1@@YAXQEAH0@Z"
250 void mangle_yes_backref2(fun_type *const[], ptr_to_fun_type const[]) {}
251 // CHECK: "?mangle_yes_backref2@@YAXQBQ6AXXZ0@Z"
252 // X64: "?mangle_yes_backref2@@YAXQEBQ6AXXZ0@Z"
254 void mangle_yes_backref3(ptr_to_fun_type *const, void (**const)(void)) {}
255 // CHECK: "?mangle_yes_backref3@@YAXQAP6AXXZ0@Z"
256 // X64: "?mangle_yes_backref3@@YAXQEAP6AXXZ0@Z"
258 void mangle_yes_backref4(int *const __restrict, int *const __restrict) {}
259 // CHECK: "?mangle_yes_backref4@@YAXQIAH0@Z"
260 // X64: "?mangle_yes_backref4@@YAXQEIAH0@Z"
262 struct S {};
263 void pr23325(const S[1], const S[]) {}
264 // CHECK: "?pr23325@@YAXQBUS@@0@Z"
265 // X64: "?pr23325@@YAXQEBUS@@0@Z"
267 void vla_arg(int i, int a[][i]) {}
268 // CHECK: "?vla_arg@@YAXHQAY0A@H@Z"
269 // X64: "?vla_arg@@YAXHQEAY0A@H@Z"