Fix the clang-wpa example.
[clang.git] / test / CodeGen / x86_32-arguments-darwin.c
blobcf89de30a242c347cd8be9e0ed86eced741e052f
1 // RUN: %clang_cc1 -w -fblocks -triple i386-apple-darwin9 -emit-llvm -o %t %s
2 // RUN: FileCheck < %t %s
4 // CHECK: define signext i8 @f0()
5 char f0(void) {
6 return 0;
9 // CHECK: define signext i16 @f1()
10 short f1(void) {
11 return 0;
14 // CHECK: define i32 @f2()
15 int f2(void) {
16 return 0;
19 // CHECK: define float @f3()
20 float f3(void) {
21 return 0;
24 // CHECK: define double @f4()
25 double f4(void) {
26 return 0;
29 // CHECK: define x86_fp80 @f5()
30 long double f5(void) {
31 return 0;
34 // CHECK: define void @f6(i8 signext %a0, i16 signext %a1, i32 %a2, i64 %a3, i8* %a4)
35 void f6(char a0, short a1, int a2, long long a3, void *a4) {}
37 // CHECK: define void @f7(i32 %a0)
38 typedef enum { A, B, C } e7;
39 void f7(e7 a0) {}
41 // CHECK: define i64 @f8_1()
42 // CHECK: define void @f8_2(i32 %a0.0, i32 %a0.1)
43 struct s8 {
44 int a;
45 int b;
47 struct s8 f8_1(void) { while (1) {} }
48 void f8_2(struct s8 a0) {}
50 // This should be passed just as s8.
52 // CHECK: define i64 @f9_1()
54 // FIXME: llvm-gcc expands this, this may have some value for the
55 // backend in terms of optimization but doesn't change the ABI.
56 // CHECK: define void @f9_2(%struct.s9* byval %a0)
57 struct s9 {
58 int a : 17;
59 int b;
61 struct s9 f9_1(void) { while (1) {} }
62 void f9_2(struct s9 a0) {}
64 // Return of small structures and unions
66 // CHECK: float @f10()
67 struct s10 {
68 union { };
69 float f;
70 } f10(void) { while (1) {} }
72 // Small vectors and 1 x {i64,double} are returned in registers
74 // CHECK: i32 @f11()
75 // CHECK: void @f12(<2 x i32>* sret %agg.result)
76 // CHECK: i64 @f13()
77 // CHECK: i64 @f14()
78 // CHECK: <2 x i64> @f15()
79 // CHECK: <2 x i64> @f16()
80 typedef short T11 __attribute__ ((vector_size (4)));
81 T11 f11(void) { while (1) {} }
82 typedef int T12 __attribute__ ((vector_size (8)));
83 T12 f12(void) { while (1) {} }
84 typedef long long T13 __attribute__ ((vector_size (8)));
85 T13 f13(void) { while (1) {} }
86 typedef double T14 __attribute__ ((vector_size (8)));
87 T14 f14(void) { while (1) {} }
88 typedef long long T15 __attribute__ ((vector_size (16)));
89 T15 f15(void) { while (1) {} }
90 typedef double T16 __attribute__ ((vector_size (16)));
91 T16 f16(void) { while (1) {} }
93 // And when the single element in a struct (but not for 64 and
94 // 128-bits).
96 // CHECK: i32 @f17()
97 // CHECK: void @f18(%{{.*}}* sret %agg.result)
98 // CHECK: void @f19(%{{.*}}* sret %agg.result)
99 // CHECK: void @f20(%{{.*}}* sret %agg.result)
100 // CHECK: void @f21(%{{.*}}* sret %agg.result)
101 // CHECK: void @f22(%{{.*}}* sret %agg.result)
102 struct { T11 a; } f17(void) { while (1) {} }
103 struct { T12 a; } f18(void) { while (1) {} }
104 struct { T13 a; } f19(void) { while (1) {} }
105 struct { T14 a; } f20(void) { while (1) {} }
106 struct { T15 a; } f21(void) { while (1) {} }
107 struct { T16 a; } f22(void) { while (1) {} }
109 // Single element structures are handled specially
111 // CHECK: float @f23()
112 // CHECK: float @f24()
113 // CHECK: float @f25()
114 struct { float a; } f23(void) { while (1) {} }
115 struct { float a[1]; } f24(void) { while (1) {} }
116 struct { struct {} a; struct { float a[1]; } b; } f25(void) { while (1) {} }
118 // Small structures are handled recursively
119 // CHECK: i32 @f26()
120 // CHECK: void @f27(%struct.s27* sret %agg.result)
121 struct s26 { struct { char a, b; } a; struct { char a, b; } b; } f26(void) { while (1) {} }
122 struct s27 { struct { char a, b, c; } a; struct { char a; } b; } f27(void) { while (1) {} }
124 // CHECK: void @f28(%struct.s28* sret %agg.result)
125 struct s28 { int a; int b[]; } f28(void) { while (1) {} }
127 // CHECK: define i16 @f29()
128 struct s29 { struct { } a[1]; char b; char c; } f29(void) { while (1) {} }
130 // CHECK: define i16 @f30()
131 struct s30 { char a; char b : 4; } f30(void) { while (1) {} }
133 // CHECK: define float @f31()
134 struct s31 { char : 0; float b; char : 0; } f31(void) { while (1) {} }
136 // CHECK: define i32 @f32()
137 struct s32 { char a; unsigned : 0; } f32(void) { while (1) {} }
139 // CHECK: define float @f33()
140 struct s33 { float a; long long : 0; } f33(void) { while (1) {} }
142 // CHECK: define float @f34()
143 struct s34 { struct { int : 0; } a; float b; } f34(void) { while (1) {} }
145 // CHECK: define i16 @f35()
146 struct s35 { struct { int : 0; } a; char b; char c; } f35(void) { while (1) {} }
148 // CHECK: define i16 @f36()
149 struct s36 { struct { int : 0; } a[2][10]; char b; char c; } f36(void) { while (1) {} }
151 // CHECK: define float @f37()
152 struct s37 { float c[1][1]; } f37(void) { while (1) {} }
154 // CHECK: define void @f38(%struct.s38* sret %agg.result)
155 struct s38 { char a[3]; short b; } f38(void) { while (1) {} }
157 // CHECK: define void @f39(%struct.s39* byval align 16 %x)
158 typedef int v39 __attribute((vector_size(16)));
159 struct s39 { v39 x; };
160 void f39(struct s39 x) {}
162 // <rdar://problem/7247671>
163 // CHECK: define i32 @f40()
164 enum e40 { ec0 = 0 };
165 enum e40 f40(void) { }
167 // CHECK: define void ()* @f41()
168 typedef void (^vvbp)(void);
169 vvbp f41(void) { }
171 // CHECK: define i32 @f42()
172 struct s42 { enum e40 f0; } f42(void) { }
174 // CHECK: define i64 @f43()
175 struct s43 { enum e40 f0; int f1; } f43(void) { }
177 // CHECK: define i32 @f44()
178 struct s44 { vvbp f0; } f44(void) { }
180 // CHECK: define i64 @f45()
181 struct s45 { vvbp f0; int f1; } f45(void) { }
183 // CHECK: define void @f46(i32 %a0)
184 void f46(enum e40 a0) { }
186 // CHECK: define void @f47(void ()* %a1)
187 void f47(vvbp a1) { }
189 // CHECK: define void @f48(i32 %a0.0)
190 struct s48 { enum e40 f0; };
191 void f48(struct s48 a0) { }
193 // CHECK: define void @f49(i32 %a0.0, i32 %a0.1)
194 struct s49 { enum e40 f0; int f1; };
195 void f49(struct s49 a0) { }
197 // CHECK: define void @f50(void ()* %a0.0)
198 struct s50 { vvbp f0; };
199 void f50(struct s50 a0) { }
201 // CHECK: define void @f51(void ()* %a0.0, i32 %a0.1)
202 struct s51 { vvbp f0; int f1; };
203 void f51(struct s51 a0) { }
205 // CHECK: define void @f52(%struct.s52* byval align 4)
206 struct s52 {
207 long double a;
209 void f52(struct s52 x) {}
211 // CHECK: define void @f53(%struct.s53* byval align 4)
212 struct __attribute__((aligned(32))) s53 {
213 int x;
214 int y;
216 void f53(struct s53 x) {}
218 typedef unsigned short v2i16 __attribute__((__vector_size__(4)));
220 // CHECK: define i32 @f54(i32 %arg.coerce)
221 // rdar://8359483
222 v2i16 f54(v2i16 arg) { return arg+arg; }
225 typedef int v4i32 __attribute__((__vector_size__(16)));
227 // CHECK: define <2 x i64> @f55(<4 x i32> %arg)
228 // PR8029
229 v4i32 f55(v4i32 arg) { return arg+arg; }
231 // CHECK: define void @f56(
232 // CHECK: i8 signext %a0, %struct.s56_0* byval %a1,
233 // CHECK: x86_mmx %a2.coerce, %struct.s56_1* byval align 4,
234 // CHECK: i64 %a4.coerce, %struct.s56_2* byval align 4,
235 // CHECK: <4 x i32> %a6, %struct.s39* byval align 16 %a7,
236 // CHECK: <2 x double> %a8, %struct.s56_4* byval align 16 %a9,
237 // CHECK: <8 x i32> %a10, %struct.s56_5* byval align 4,
238 // CHECK: <4 x double> %a12, %struct.s56_6* byval align 4)
240 // CHECK: call void (i32, ...)* @f56_0(i32 1,
241 // CHECK: i32 %{{[^ ]*}}, %struct.s56_0* byval %{{[^ ]*}},
242 // CHECK: x86_mmx %{{[^ ]*}}, %struct.s56_1* byval align 4 %{{[^ ]*}},
243 // CHECK: i64 %{{[^ ]*}}, %struct.s56_2* byval align 4 %{{[^ ]*}},
244 // CHECK: <4 x i32> %{{[^ ]*}}, %struct.s39* byval align 16 %{{[^ ]*}},
245 // CHECK: <2 x double> %{{[^ ]*}}, %struct.s56_4* byval align 16 %{{[^ ]*}},
246 // CHECK: <8 x i32> {{[^ ]*}}, %struct.s56_5* byval align 4 %{{[^ ]*}},
247 // CHECK: <4 x double> {{[^ ]*}}, %struct.s56_6* byval align 4 %{{[^ ]*}})
248 // CHECK: }
250 // <rdar://problem/7964854> [i386] clang misaligns long double in structures
251 // when passed byval
252 // <rdar://problem/8431367> clang misaligns parameters on stack
253 typedef int __attribute__((vector_size (8))) t56_v2i;
254 typedef double __attribute__((vector_size (8))) t56_v1d;
255 typedef int __attribute__((vector_size (16))) t56_v4i;
256 typedef double __attribute__((vector_size (16))) t56_v2d;
257 typedef int __attribute__((vector_size (32))) t56_v8i;
258 typedef double __attribute__((vector_size (32))) t56_v4d;
260 struct s56_0 { char a; };
261 struct s56_1 { t56_v2i a; };
262 struct s56_2 { t56_v1d a; };
263 struct s56_3 { t56_v4i a; };
264 struct s56_4 { t56_v2d a; };
265 struct s56_5 { t56_v8i a; };
266 struct s56_6 { t56_v4d a; };
268 void f56(char a0, struct s56_0 a1,
269 t56_v2i a2, struct s56_1 a3,
270 t56_v1d a4, struct s56_2 a5,
271 t56_v4i a6, struct s56_3 a7,
272 t56_v2d a8, struct s56_4 a9,
273 t56_v8i a10, struct s56_5 a11,
274 t56_v4d a12, struct s56_6 a13) {
275 extern void f56_0(int x, ...);
276 f56_0(1, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,
277 a10, a11, a12, a13);