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
3 
4 void foo(const unsigned int) {}
5 // CHECK: "\01?foo@@YAXI@Z"
6 // X64: "\01?foo@@YAXI@Z"
7 
8 void foo(const double) {}
9 // CHECK: "\01?foo@@YAXN@Z"
10 // X64: "\01?foo@@YAXN@Z"
11 
12 void bar(const volatile double) {}
13 // CHECK: "\01?bar@@YAXN@Z"
14 // X64: "\01?bar@@YAXN@Z"
15 
16 void foo_pad(char * x) {}
17 // CHECK: "\01?foo_pad@@YAXPAD@Z"
18 // X64: "\01?foo_pad@@YAXPEAD@Z"
19 
20 void foo_pbd(const char * x) {}
21 // CHECK: "\01?foo_pbd@@YAXPBD@Z"
22 // X64: "\01?foo_pbd@@YAXPEBD@Z"
23 
24 void foo_pcd(volatile char * x) {}
25 // CHECK: "\01?foo_pcd@@YAXPCD@Z"
26 // X64: "\01?foo_pcd@@YAXPECD@Z"
27 
28 void foo_qad(char * const x) {}
29 // CHECK: "\01?foo_qad@@YAXQAD@Z"
30 // X64: "\01?foo_qad@@YAXQEAD@Z"
31 
32 void foo_rad(char * volatile x) {}
33 // CHECK: "\01?foo_rad@@YAXRAD@Z"
34 // X64: "\01?foo_rad@@YAXREAD@Z"
35 
36 void foo_sad(char * const volatile x) {}
37 // CHECK: "\01?foo_sad@@YAXSAD@Z"
38 // X64: "\01?foo_sad@@YAXSEAD@Z"
39 
40 void foo_piad(char * __restrict x) {}
41 // CHECK: "\01?foo_piad@@YAXPIAD@Z"
42 // X64: "\01?foo_piad@@YAXPEIAD@Z"
43 
44 void foo_qiad(char * const __restrict x) {}
45 // CHECK: "\01?foo_qiad@@YAXQIAD@Z"
46 // X64: "\01?foo_qiad@@YAXQEIAD@Z"
47 
48 void foo_riad(char * volatile __restrict x) {}
49 // CHECK: "\01?foo_riad@@YAXRIAD@Z"
50 // X64: "\01?foo_riad@@YAXREIAD@Z"
51 
52 void foo_siad(char * const volatile __restrict x) {}
53 // CHECK: "\01?foo_siad@@YAXSIAD@Z"
54 // X64: "\01?foo_siad@@YAXSEIAD@Z"
55 
56 void foo_papad(char ** x) {}
57 // CHECK: "\01?foo_papad@@YAXPAPAD@Z"
58 // X64: "\01?foo_papad@@YAXPEAPEAD@Z"
59 
60 void foo_papbd(char const ** x) {}
61 // CHECK: "\01?foo_papbd@@YAXPAPBD@Z"
62 // X64: "\01?foo_papbd@@YAXPEAPEBD@Z"
63 
64 void foo_papcd(char volatile ** x) {}
65 // CHECK: "\01?foo_papcd@@YAXPAPCD@Z"
66 // X64: "\01?foo_papcd@@YAXPEAPECD@Z"
67 
68 void foo_pbqad(char * const* x) {}
69 // CHECK: "\01?foo_pbqad@@YAXPBQAD@Z"
70 // X64: "\01?foo_pbqad@@YAXPEBQEAD@Z"
71 
72 void foo_pcrad(char * volatile* x) {}
73 // CHECK: "\01?foo_pcrad@@YAXPCRAD@Z"
74 // X64: "\01?foo_pcrad@@YAXPECREAD@Z"
75 
76 void foo_qapad(char ** const x) {}
77 // CHECK: "\01?foo_qapad@@YAXQAPAD@Z"
78 // X64: "\01?foo_qapad@@YAXQEAPEAD@Z"
79 
80 void foo_rapad(char ** volatile x) {}
81 // CHECK: "\01?foo_rapad@@YAXRAPAD@Z"
82 // X64: "\01?foo_rapad@@YAXREAPEAD@Z"
83 
84 void foo_pbqbd(const char * const* x) {}
85 // CHECK: "\01?foo_pbqbd@@YAXPBQBD@Z"
86 // X64: "\01?foo_pbqbd@@YAXPEBQEBD@Z"
87 
88 void foo_pbqcd(volatile char * const* x) {}
89 // CHECK: "\01?foo_pbqcd@@YAXPBQCD@Z"
90 // X64: "\01?foo_pbqcd@@YAXPEBQECD@Z"
91 
92 void foo_pcrbd(const char * volatile* x) {}
93 // CHECK: "\01?foo_pcrbd@@YAXPCRBD@Z"
94 // X64: "\01?foo_pcrbd@@YAXPECREBD@Z"
95 
96 void foo_pcrcd(volatile char * volatile* x) {}
97 // CHECK: "\01?foo_pcrcd@@YAXPCRCD@Z"
98 // X64: "\01?foo_pcrcd@@YAXPECRECD@Z"
99 
100 void foo_aad(char &x) {}
101 // CHECK: "\01?foo_aad@@YAXAAD@Z"
102 // X64: "\01?foo_aad@@YAXAEAD@Z"
103 
104 void foo_abd(const char &x) {}
105 // CHECK: "\01?foo_abd@@YAXABD@Z"
106 // X64: "\01?foo_abd@@YAXAEBD@Z"
107 
108 void foo_aapad(char *&x) {}
109 // CHECK: "\01?foo_aapad@@YAXAAPAD@Z"
110 // X64: "\01?foo_aapad@@YAXAEAPEAD@Z"
111 
112 void foo_aapbd(const char *&x) {}
113 // CHECK: "\01?foo_aapbd@@YAXAAPBD@Z"
114 // X64: "\01?foo_aapbd@@YAXAEAPEBD@Z"
115 
116 void foo_abqad(char * const &x) {}
117 // CHECK: "\01?foo_abqad@@YAXABQAD@Z"
118 // X64: "\01?foo_abqad@@YAXAEBQEAD@Z"
119 
120 void foo_abqbd(const char * const &x) {}
121 // CHECK: "\01?foo_abqbd@@YAXABQBD@Z"
122 // X64: "\01?foo_abqbd@@YAXAEBQEBD@Z"
123 
124 void foo_aay144h(int (&x)[5][5]) {}
125 // CHECK: "\01?foo_aay144h@@YAXAAY144H@Z"
126 // X64: "\01?foo_aay144h@@YAXAEAY144H@Z"
127 
128 void foo_aay144cbh(const int (&x)[5][5]) {}
129 // CHECK: "\01?foo_aay144cbh@@YAXAAY144$$CBH@Z"
130 // X64: "\01?foo_aay144cbh@@YAXAEAY144$$CBH@Z"
131 
132 void foo_qay144h(int (&&x)[5][5]) {}
133 // CHECK: "\01?foo_qay144h@@YAX$$QAY144H@Z"
134 // X64: "\01?foo_qay144h@@YAX$$QEAY144H@Z"
135 
136 void foo_qay144cbh(const int (&&x)[5][5]) {}
137 // CHECK: "\01?foo_qay144cbh@@YAX$$QAY144$$CBH@Z"
138 // X64: "\01?foo_qay144cbh@@YAX$$QEAY144$$CBH@Z"
139 
140 void foo_p6ahxz(int x()) {}
141 // CHECK: "\01?foo_p6ahxz@@YAXP6AHXZ@Z"
142 // X64: "\01?foo_p6ahxz@@YAXP6AHXZ@Z"
143 
144 void foo_a6ahxz(int (&x)()) {}
145 // CHECK: "\01?foo_a6ahxz@@YAXA6AHXZ@Z"
146 // X64: "\01?foo_a6ahxz@@YAXA6AHXZ@Z"
147 
148 void foo_q6ahxz(int (&&x)()) {}
149 // CHECK: "\01?foo_q6ahxz@@YAX$$Q6AHXZ@Z"
150 // X64: "\01?foo_q6ahxz@@YAX$$Q6AHXZ@Z"
151 
152 void foo_qay04h(int x[5][5]) {}
153 // CHECK: "\01?foo_qay04h@@YAXQAY04H@Z"
154 // X64: "\01?foo_qay04h@@YAXQEAY04H@Z"
155 
156 void foo_qay04cbh(const int x[5][5]) {}
157 // CHECK: "\01?foo_qay04cbh@@YAXQAY04$$CBH@Z"
158 // X64: "\01?foo_qay04cbh@@YAXQEAY04$$CBH@Z"
159 
160 typedef double Vector[3];
161 
162 void foo(Vector*) {}
163 // CHECK: "\01?foo@@YAXPAY02N@Z"
164 // X64: "\01?foo@@YAXPEAY02N@Z"
165 
166 void foo(Vector) {}
167 // CHECK: "\01?foo@@YAXQAN@Z"
168 // X64: "\01?foo@@YAXQEAN@Z"
169 
170 void foo_const(const Vector) {}
171 // CHECK: "\01?foo_const@@YAXQBN@Z"
172 // X64: "\01?foo_const@@YAXQEBN@Z"
173 
174 void foo_volatile(volatile Vector) {}
175 // CHECK: "\01?foo_volatile@@YAXQCN@Z"
176 // X64: "\01?foo_volatile@@YAXQECN@Z"
177 
178 void foo(Vector*, const Vector, const double) {}
179 // CHECK: "\01?foo@@YAXPAY02NQBNN@Z"
180 // X64: "\01?foo@@YAXPEAY02NQEBNN@Z"
181 
182 typedef void (*ConstFunPtr)(int *const d);
183 void foo_fnptrconst(ConstFunPtr f) {  }
184 // CHECK: "\01?foo_fnptrconst@@YAXP6AXQAH@Z@Z"
185 // X64:   "\01?foo_fnptrconst@@YAXP6AXQEAH@Z@Z"
186 
187 typedef void (*ArrayFunPtr)(int d[1]);
188 void foo_fnptrarray(ArrayFunPtr f) {  }
189 // CHECK: "\01?foo_fnptrarray@@YAXP6AXQAH@Z@Z"
190 // X64:   "\01?foo_fnptrarray@@YAXP6AXQEAH@Z@Z"
191 
192 void foo_fnptrbackref1(ArrayFunPtr f1, ArrayFunPtr f2) {  }
193 // CHECK: "\01?foo_fnptrbackref1@@YAXP6AXQAH@Z1@Z"
194 // X64:   "\01?foo_fnptrbackref1@@YAXP6AXQEAH@Z1@Z"
195 
196 void foo_fnptrbackref2(ArrayFunPtr f1, ConstFunPtr f2) {  }
197 // CHECK: "\01?foo_fnptrbackref2@@YAXP6AXQAH@Z1@Z"
198 // X64:   "\01?foo_fnptrbackref2@@YAXP6AXQEAH@Z1@Z"
199 
200 typedef void (*NormalFunPtr)(int *d);
201 void foo_fnptrbackref3(ArrayFunPtr f1, NormalFunPtr f2) {  }
202 // CHECK: "\01?foo_fnptrbackref3@@YAXP6AXQAH@Z1@Z"
203 // X64:   "\01?foo_fnptrbackref3@@YAXP6AXQEAH@Z1@Z"
204 
205 void foo_fnptrbackref4(NormalFunPtr f1, ArrayFunPtr f2) {  }
206 // CHECK: "\01?foo_fnptrbackref4@@YAXP6AXPAH@Z1@Z"
207 // X64:   "\01?foo_fnptrbackref4@@YAXP6AXPEAH@Z1@Z"
208 
209 ArrayFunPtr ret_fnptrarray() { return 0; }
210 // CHECK: "\01?ret_fnptrarray@@YAP6AXQAH@ZXZ"
211 // X64:   "\01?ret_fnptrarray@@YAP6AXQEAH@ZXZ"
212 
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: "\01?mangle_fwd@@YAXQAD@Z"
218 // X64:   "\01?mangle_fwd@@YAXQEAD@Z"
219 
220 void mangle_no_fwd(char * x) {}
221 // CHECK: "\01?mangle_no_fwd@@YAXPAD@Z"
222 // X64:   "\01?mangle_no_fwd@@YAXPEAD@Z"
223 
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: "\01?mangle_no_backref0@@YAXQAHPAH@Z"
228 // X64:   "\01?mangle_no_backref0@@YAXQEAHPEAH@Z"
229 
230 void mangle_no_backref1(int[], int *const) {}
231 // CHECK: "\01?mangle_no_backref1@@YAXQAHQAH@Z"
232 // X64:   "\01?mangle_no_backref1@@YAXQEAHQEAH@Z"
233 
234 typedef void fun_type(void);
235 typedef void (*ptr_to_fun_type)(void);
236 
237 // Pointer to function types don't backref with function types
238 void mangle_no_backref2(fun_type, ptr_to_fun_type) {}
239 // CHECK: "\01?mangle_no_backref2@@YAXP6AXXZP6AXXZ@Z"
240 // X64:   "\01?mangle_no_backref2@@YAXP6AXXZP6AXXZ@Z"
241 
242 void mangle_yes_backref0(int[], int []) {}
243 // CHECK: "\01?mangle_yes_backref0@@YAXQAH0@Z"
244 // X64:   "\01?mangle_yes_backref0@@YAXQEAH0@Z"
245 
246 void mangle_yes_backref1(int *const, int *const) {}
247 // CHECK: "\01?mangle_yes_backref1@@YAXQAH0@Z"
248 // X64:   "\01?mangle_yes_backref1@@YAXQEAH0@Z"
249 
250 void mangle_yes_backref2(fun_type *const[], ptr_to_fun_type const[]) {}
251 // CHECK: "\01?mangle_yes_backref2@@YAXQBQ6AXXZ0@Z"
252 // X64:   "\01?mangle_yes_backref2@@YAXQEBQ6AXXZ0@Z"
253 
254 void mangle_yes_backref3(ptr_to_fun_type *const, void (**const)(void)) {}
255 // CHECK: "\01?mangle_yes_backref3@@YAXQAP6AXXZ0@Z"
256 // X64:   "\01?mangle_yes_backref3@@YAXQEAP6AXXZ0@Z"
257 
258 void mangle_yes_backref4(int *const __restrict, int *const __restrict) {}
259 // CHECK: "\01?mangle_yes_backref4@@YAXQIAH0@Z"
260 // X64:   "\01?mangle_yes_backref4@@YAXQEIAH0@Z"
261 
262 struct S {};
263 void pr23325(const S[1], const S[]) {}
264 // CHECK: "\01?pr23325@@YAXQBUS@@0@Z"
265 // X64:   "\01?pr23325@@YAXQEBUS@@0@Z"
266 
267 void vla_arg(int i, int a[][i]) {}
268 // CHECK: "\01?vla_arg@@YAXHQAY0A@H@Z"
269 // X64:   "\01?vla_arg@@YAXHQEAY0A@H@Z"
270