xref: /llvm-project/clang/test/CodeGen/X86/x86_32-arguments-darwin.c (revision 158d72d728261c1e54dc77931372b2322c52849f)
1 // RUN: %clang_cc1 -w -fblocks -triple i386-apple-darwin9 -target-cpu yonah -emit-llvm -o - %s | FileCheck %s
2 
3 // CHECK-LABEL: define{{.*}} signext i8 @f0()
f0(void)4 char f0(void) {
5   return 0;
6 }
7 
8 // CHECK-LABEL: define{{.*}} signext i16 @f1()
f1(void)9 short f1(void) {
10   return 0;
11 }
12 
13 // CHECK-LABEL: define{{.*}} i32 @f2()
f2(void)14 int f2(void) {
15   return 0;
16 }
17 
18 // CHECK-LABEL: define{{.*}} float @f3()
f3(void)19 float f3(void) {
20   return 0;
21 }
22 
23 // CHECK-LABEL: define{{.*}} double @f4()
f4(void)24 double f4(void) {
25   return 0;
26 }
27 
28 // CHECK-LABEL: define{{.*}} x86_fp80 @f5()
f5(void)29 long double f5(void) {
30   return 0;
31 }
32 
33 // CHECK-LABEL: define{{.*}} void @f6(i8 noundef signext %a0, i16 noundef signext %a1, i32 noundef %a2, i64 noundef %a3, ptr noundef %a4)
f6(char a0,short a1,int a2,long long a3,void * a4)34 void f6(char a0, short a1, int a2, long long a3, void *a4) {}
35 
36 // CHECK-LABEL: define{{.*}} void @f7(i32 noundef %a0)
37 typedef enum { A, B, C } e7;
f7(e7 a0)38 void f7(e7 a0) {}
39 
40 // CHECK-LABEL: define{{.*}} i64 @f8_1()
41 // CHECK-LABEL: define{{.*}} void @f8_2(i32 %a0.0, i32 %a0.1)
42 struct s8 {
43   int a;
44   int b;
45 };
f8_1(void)46 struct s8 f8_1(void) { while (1) {} }
f8_2(struct s8 a0)47 void f8_2(struct s8 a0) {}
48 
49 // This should be passed just as s8.
50 
51 // CHECK-LABEL: define{{.*}} i64 @f9_1()
52 
53 // FIXME: llvm-gcc expands this, this may have some value for the
54 // backend in terms of optimization but doesn't change the ABI.
55 // CHECK-LABEL: define{{.*}} void @f9_2(ptr noundef byval(%struct.s9) align 4 %a0)
56 struct s9 {
57   int a : 17;
58   int b;
59 };
f9_1(void)60 struct s9 f9_1(void) { while (1) {} }
f9_2(struct s9 a0)61 void f9_2(struct s9 a0) {}
62 
63 // Return of small structures and unions
64 
65 // CHECK: float @f10()
66 struct s10 {
67   union { };
68   float f;
f10(void)69 } f10(void) { while (1) {} }
70 
71 // Small vectors and 1 x {i64,double} are returned in registers
72 
73 // CHECK: i32 @f11()
74 // CHECK: void @f12(ptr dead_on_unwind noalias writable sret(<2 x i32>) align 8 %agg.result)
75 // CHECK: i64 @f13()
76 // CHECK: i64 @f14()
77 // CHECK: <2 x i64> @f15()
78 // CHECK: <2 x i64> @f16()
79 typedef short T11 __attribute__ ((vector_size (4)));
f11(void)80 T11 f11(void) { while (1) {} }
81 typedef int T12 __attribute__ ((vector_size (8)));
f12(void)82 T12 f12(void) { while (1) {} }
83 typedef long long T13 __attribute__ ((vector_size (8)));
f13(void)84 T13 f13(void) { while (1) {} }
85 typedef double T14 __attribute__ ((vector_size (8)));
f14(void)86 T14 f14(void) { while (1) {} }
87 typedef long long T15 __attribute__ ((vector_size (16)));
f15(void)88 T15 f15(void) { while (1) {} }
89 typedef double T16 __attribute__ ((vector_size (16)));
f16(void)90 T16 f16(void) { while (1) {} }
91 
92 // And when the single element in a struct (but not for 64 and
93 // 128-bits).
94 
95 // CHECK: i32 @f17()
96 // CHECK: void @f18(ptr dead_on_unwind noalias writable sret(%struct.anon.{{[0-9]+}}) align 8 %agg.result)
97 // CHECK: void @f19(ptr dead_on_unwind noalias writable sret(%struct.anon.{{[0-9]+}}) align 8 %agg.result)
98 // CHECK: void @f20(ptr dead_on_unwind noalias writable sret(%struct.anon.{{[0-9]+}}) align 8 %agg.result)
99 // CHECK: void @f21(ptr dead_on_unwind noalias writable sret(%struct.anon.{{[0-9]+}}) align 16 %agg.result)
100 // CHECK: void @f22(ptr dead_on_unwind noalias writable sret(%struct.anon.{{[0-9]+}}) align 16 %agg.result)
f17(void)101 struct { T11 a; } f17(void) { while (1) {} }
f18(void)102 struct { T12 a; } f18(void) { while (1) {} }
f19(void)103 struct { T13 a; } f19(void) { while (1) {} }
f20(void)104 struct { T14 a; } f20(void) { while (1) {} }
f21(void)105 struct { T15 a; } f21(void) { while (1) {} }
f22(void)106 struct { T16 a; } f22(void) { while (1) {} }
107 
108 // Single element structures are handled specially
109 
110 // CHECK: float @f23()
111 // CHECK: float @f24()
112 // CHECK: float @f25()
f23(void)113 struct { float a; } f23(void) { while (1) {} }
f24(void)114 struct { float a[1]; } f24(void) { while (1) {} }
f25(void)115 struct { struct {} a; struct { float a[1]; } b; } f25(void) { while (1) {} }
116 
117 // Small structures are handled recursively
118 // CHECK: i32 @f26()
119 // CHECK: void @f27(ptr dead_on_unwind noalias writable sret(%struct.s27) align 1 %agg.result)
f26(void)120 struct s26 { struct { char a, b; } a; struct { char a, b; } b; } f26(void) { while (1) {} }
f27(void)121 struct s27 { struct { char a, b, c; } a; struct { char a; } b; } f27(void) { while (1) {} }
122 
123 // CHECK: void @f28(ptr dead_on_unwind noalias writable sret(%struct.s28) align 4 %agg.result)
f28(void)124 struct s28 { int a; int b[]; } f28(void) { while (1) {} }
125 
126 // CHECK-LABEL: define{{.*}} i16 @f29()
f29(void)127 struct s29 { struct { } a[1]; char b; char c; } f29(void) { while (1) {} }
128 
129 // CHECK-LABEL: define{{.*}} i16 @f30()
f30(void)130 struct s30 { char a; char b : 4; } f30(void) { while (1) {} }
131 
132 // CHECK-LABEL: define{{.*}} float @f31()
f31(void)133 struct s31 { char : 0; float b; char : 0; } f31(void) { while (1) {} }
134 
135 // CHECK-LABEL: define{{.*}} i32 @f32()
f32(void)136 struct s32 { char a; unsigned : 0; } f32(void) { while (1) {} }
137 
138 // CHECK-LABEL: define{{.*}} float @f33()
f33(void)139 struct s33 { float a; long long : 0; } f33(void) { while (1) {} }
140 
141 // CHECK-LABEL: define{{.*}} float @f34()
f34(void)142 struct s34 { struct { int : 0; } a; float b; } f34(void) { while (1) {} }
143 
144 // CHECK-LABEL: define{{.*}} i16 @f35()
f35(void)145 struct s35 { struct { int : 0; } a; char b; char c; } f35(void) { while (1) {} }
146 
147 // CHECK-LABEL: define{{.*}} i16 @f36()
f36(void)148 struct s36 { struct { int : 0; } a[2][10]; char b; char c; } f36(void) { while (1) {} }
149 
150 // CHECK-LABEL: define{{.*}} float @f37()
f37(void)151 struct s37 { float c[1][1]; } f37(void) { while (1) {} }
152 
153 // CHECK-LABEL: define{{.*}} void @f38(ptr dead_on_unwind noalias writable sret(%struct.s38) align 2 %agg.result)
f38(void)154 struct s38 { char a[3]; short b; } f38(void) { while (1) {} }
155 
156 // CHECK-LABEL: define{{.*}} void @f39(ptr noundef byval(%struct.s39) align 16 %x)
157 typedef int v39 __attribute((vector_size(16)));
158 struct s39 { v39 x; };
f39(struct s39 x)159 void f39(struct s39 x) {}
160 
161 // CHECK-LABEL: define{{.*}} i32 @f40()
162 enum e40 { ec0 = 0 };
f40(void)163 enum e40 f40(void) { }
164 
165 // CHECK-LABEL: define{{.*}} ptr @f41()
166 typedef void (^vvbp)(void);
f41(void)167 vvbp f41(void) { }
168 
169 // CHECK-LABEL: define{{.*}} i32 @f42()
f42(void)170 struct s42 { enum e40 f0; } f42(void) {  }
171 
172 // CHECK-LABEL: define{{.*}} i64 @f43()
f43(void)173 struct s43 { enum e40 f0; int f1; } f43(void) {  }
174 
175 // CHECK-LABEL: define{{.*}} ptr @f44()
f44(void)176 struct s44 { vvbp f0; } f44(void) {  }
177 
178 // CHECK-LABEL: define{{.*}} i64 @f45()
f45(void)179 struct s45 { vvbp f0; int f1; } f45(void) {  }
180 
181 // CHECK-LABEL: define{{.*}} void @f46(i32 noundef %a0)
f46(enum e40 a0)182 void f46(enum e40 a0) { }
183 
184 // CHECK-LABEL: define{{.*}} void @f47(ptr noundef %a1)
f47(vvbp a1)185 void f47(vvbp a1) { }
186 
187 // CHECK-LABEL: define{{.*}} void @f48(i32 %a0.0)
188 struct s48 { enum e40 f0; };
f48(struct s48 a0)189 void f48(struct s48 a0) { }
190 
191 // CHECK-LABEL: define{{.*}} void @f49(i32 %a0.0, i32 %a0.1)
192 struct s49 { enum e40 f0; int f1; };
f49(struct s49 a0)193 void f49(struct s49 a0) { }
194 
195 // CHECK-LABEL: define{{.*}} void @f50(ptr %a0.0)
196 struct s50 { vvbp f0; };
f50(struct s50 a0)197 void f50(struct s50 a0) { }
198 
199 // CHECK-LABEL: define{{.*}} void @f51(ptr %a0.0, i32 %a0.1)
200 struct s51 { vvbp f0; int f1; };
f51(struct s51 a0)201 void f51(struct s51 a0) { }
202 
203 // CHECK-LABEL: define{{.*}} void @f52(ptr noundef byval(%struct.s52) align 4 %0)
204 struct s52 {
205   long double a;
206 };
f52(struct s52 x)207 void f52(struct s52 x) {}
208 
209 // CHECK-LABEL: define{{.*}} void @f53(ptr noundef byval(%struct.s53) align 4 %0)
210 struct __attribute__((aligned(32))) s53 {
211   int x;
212   int y;
213 };
f53(struct s53 x)214 void f53(struct s53 x) {}
215 
216 typedef unsigned short v2i16 __attribute__((__vector_size__(4)));
217 
218 // CHECK-LABEL: define{{.*}} i32 @f54(i32 noundef %arg.coerce)
f54(v2i16 arg)219 v2i16 f54(v2i16 arg) { return arg+arg; }
220 
221 
222 typedef int v4i32 __attribute__((__vector_size__(16)));
223 
224 // CHECK-LABEL: define{{.*}} <2 x i64> @f55(<4 x i32> noundef %arg)
225 // PR8029
f55(v4i32 arg)226 v4i32 f55(v4i32 arg) { return arg+arg; }
227 
228 // CHECK-LABEL: define{{.*}} void @f56(
229 // CHECK: i8 noundef signext %a0, ptr noundef byval(%struct.s56_0) align 4 %a1,
230 // CHECK: i64 noundef %a2.coerce, ptr noundef byval(%struct.s56_1) align 4 %0,
231 // CHECK: i64 noundef %a4.coerce, ptr noundef byval(%struct.s56_2) align 4 %1,
232 // CHECK: <4 x i32> noundef %a6, ptr noundef byval(%struct.s56_3) align 16 %a7,
233 // CHECK: <2 x double> noundef %a8, ptr noundef byval(%struct.s56_4) align 16 %a9,
234 // CHECK: <8 x i32> noundef %a10, ptr noundef byval(%struct.s56_5) align 4 %2,
235 // CHECK: <4 x double> noundef %a12, ptr noundef byval(%struct.s56_6) align 4 %3)
236 
237 // CHECK:   call void (i32, ...) @f56_0(i32 noundef 1,
238 // CHECK: i32 noundef %{{[^ ]*}}, ptr noundef byval(%struct.s56_0) align 4 %{{[^ ]*}},
239 // CHECK: i64 noundef %{{[^ ]*}}, ptr noundef byval(%struct.s56_1) align 4 %{{[^ ]*}},
240 // CHECK: i64 noundef %{{[^ ]*}}, ptr noundef byval(%struct.s56_2) align 4 %{{[^ ]*}},
241 // CHECK: <4 x i32> noundef %{{[^ ]*}}, ptr noundef byval(%struct.s56_3) align 16 %{{[^ ]*}},
242 // CHECK: <2 x double> noundef %{{[^ ]*}}, ptr noundef byval(%struct.s56_4) align 16 %{{[^ ]*}},
243 // CHECK: <8 x i32> noundef {{[^ ]*}}, ptr noundef byval(%struct.s56_5) align 4 %{{[^ ]*}},
244 // CHECK: <4 x double> noundef {{[^ ]*}}, ptr noundef byval(%struct.s56_6) align 4 %{{[^ ]*}})
245 // CHECK: }
246 //
247 // [i386] clang misaligns long double in structures when passed byval
248 // clang misaligns parameters on stack
249 typedef int __attribute__((vector_size (8))) t56_v2i;
250 typedef double __attribute__((vector_size (8))) t56_v1d;
251 typedef int __attribute__((vector_size (16))) t56_v4i;
252 typedef double __attribute__((vector_size (16))) t56_v2d;
253 typedef int __attribute__((vector_size (32))) t56_v8i;
254 typedef double __attribute__((vector_size (32))) t56_v4d;
255 
256 struct s56_0 { char a; };
257 struct s56_1 { t56_v2i a; };
258 struct s56_2 { t56_v1d a; };
259 struct s56_3 { t56_v4i a; };
260 struct s56_4 { t56_v2d a; };
261 struct s56_5 { t56_v8i a; };
262 struct s56_6 { t56_v4d a; };
263 
f56(char a0,struct s56_0 a1,t56_v2i a2,struct s56_1 a3,t56_v1d a4,struct s56_2 a5,t56_v4i a6,struct s56_3 a7,t56_v2d a8,struct s56_4 a9,t56_v8i a10,struct s56_5 a11,t56_v4d a12,struct s56_6 a13)264 void f56(char a0, struct s56_0 a1,
265          t56_v2i a2, struct s56_1 a3,
266          t56_v1d a4, struct s56_2 a5,
267          t56_v4i a6, struct s56_3 a7,
268          t56_v2d a8, struct s56_4 a9,
269          t56_v8i a10, struct s56_5 a11,
270          t56_v4d a12, struct s56_6 a13) {
271   extern void f56_0(int x, ...);
272   f56_0(1, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,
273         a10, a11, a12, a13);
274 }
275 
276 // CHECK-LABEL: define{{.*}} void @f57(i32 %x.0, i32 %x.1)
277 // CHECK: call void @f57(
278 struct s57 { _Complex int x; };
f57a(void)279 void f57(struct s57 x) {} void f57a(void) { f57((struct s57){1}); }
280 
281 // CHECK-LABEL: define{{.*}} void @f58()
282 union u58 {};
f58(union u58 x)283 void f58(union u58 x) {}
284 
285 // CHECK-LABEL: define{{.*}} i64 @f59()
286 struct s59 { float x __attribute((aligned(8))); };
f59(void)287 struct s59 f59(void) { while (1) {} }
288 
289 // CHECK-LABEL: define{{.*}} void @f60(ptr noundef byval(%struct.s60) align 4 %0, i32 noundef %y)
290 struct s60 { int x __attribute((aligned(8))); };
f60(struct s60 x,int y)291 void f60(struct s60 x, int y) {}
292 
293 // CHECK-LABEL: define{{.*}} void @f61(i32 noundef %x, ptr noundef byval(%struct.s61) align 16 %y)
294 typedef int T61 __attribute((vector_size(16)));
295 struct s61 { T61 x; int y; };
f61(int x,struct s61 y)296 void f61(int x, struct s61 y) {}
297 
298 // CHECK-LABEL: define{{.*}} void @f62(i32 noundef %x, ptr noundef byval(%struct.s62) align 4 %0)
299 typedef int T62 __attribute((vector_size(16)));
300 struct s62 { T62 x; int y; } __attribute((packed, aligned(8)));
f62(int x,struct s62 y)301 void f62(int x, struct s62 y) {}
302 
303 // CHECK-LABEL: define{{.*}} i32 @f63
304 // CHECK: getelementptr inbounds i8, ptr {{.*}}, i32 15
305 // CHECK: call ptr @llvm.ptrmask.p0.i32(ptr {{.*}}, i32 -16)
306 typedef int T63 __attribute((vector_size(16)));
307 struct s63 { T63 x; int y; };
f63(int i,...)308 int f63(int i, ...) {
309   __builtin_va_list ap;
310   __builtin_va_start(ap, i);
311   struct s63 s = __builtin_va_arg(ap, struct s63);
312   __builtin_va_end(ap);
313   return s.y;
314 }
315 
316 // CHECK-LABEL: define{{.*}} void @f64(ptr noundef byval(%struct.s64) align 4 %x)
317 struct s64 { signed char a[0]; signed char b[]; };
f64(struct s64 x)318 void f64(struct s64 x) {}
319 
320 // CHECK-LABEL: define{{.*}} float @f65()
321 struct s65 { signed char a[0]; float b; };
f65(void)322 struct s65 f65(void) { return (struct s65){{},2}; }
323 
324 // CHECK-LABEL: define{{.*}} <2 x i64> @f66
325 // CHECK: getelementptr inbounds i8, ptr {{.*}}, i32 15
326 // CHECK: call ptr @llvm.ptrmask.p0.i32(ptr {{.*}}, i32 -16)
327 typedef int T66 __attribute((vector_size(16)));
f66(int i,...)328 T66 f66(int i, ...) {
329   __builtin_va_list ap;
330   __builtin_va_start(ap, i);
331   T66 v = __builtin_va_arg(ap, T66);
332   __builtin_va_end(ap);
333   return v;
334 }
335 
336 // PR14453
337 struct s67 { _Complex unsigned short int a; };
f67(struct s67 x)338 void f67(struct s67 x) {}
339 // CHECK-LABEL: define{{.*}} void @f67(ptr noundef byval(%struct.s67) align 4 %x)
340