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