blob: 01c3e236f3bdc7bcd98fdf59f24ed9faec51e557 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fblocks -triple i386-apple-darwin9 -emit-llvm -o %t %s
Daniel Dunbard0ef54c2010-04-21 19:34:17 +00002// RUN: FileCheck < %t %s
Daniel Dunbare06a75f2009-03-11 22:05:26 +00003
Daniel Dunbard0ef54c2010-04-21 19:34:17 +00004// CHECK: define signext i8 @f0()
Daniel Dunbare06a75f2009-03-11 22:05:26 +00005char f0(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +00006 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +00007}
8
Daniel Dunbard0ef54c2010-04-21 19:34:17 +00009// CHECK: define signext i16 @f1()
Daniel Dunbare06a75f2009-03-11 22:05:26 +000010short f1(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000011 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000012}
13
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000014// CHECK: define i32 @f2()
Daniel Dunbare06a75f2009-03-11 22:05:26 +000015int f2(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000016 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000017}
18
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000019// CHECK: define float @f3()
Daniel Dunbare06a75f2009-03-11 22:05:26 +000020float f3(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000021 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000022}
23
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000024// CHECK: define double @f4()
Daniel Dunbare06a75f2009-03-11 22:05:26 +000025double f4(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000026 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000027}
28
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000029// CHECK: define x86_fp80 @f5()
Daniel Dunbare06a75f2009-03-11 22:05:26 +000030long double f5(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000031 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000032}
33
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000034// CHECK: define void @f6(i8 signext %a0, i16 signext %a1, i32 %a2, i64 %a3, i8* %a4)
Mike Stumpc36541e2009-07-21 20:52:43 +000035void f6(char a0, short a1, int a2, long long a3, void *a4) {}
Daniel Dunbare06a75f2009-03-11 22:05:26 +000036
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000037// CHECK: define void @f7(i32 %a0)
38typedef enum { A, B, C } e7;
39void f7(e7 a0) {}
Daniel Dunbare06a75f2009-03-11 22:05:26 +000040
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000041// CHECK: define i64 @f8_1()
42// CHECK: define void @f8_2(i32 %a0.0, i32 %a0.1)
Daniel Dunbare06a75f2009-03-11 22:05:26 +000043struct s8 {
44 int a;
45 int b;
46};
Mike Stumpc36541e2009-07-21 20:52:43 +000047struct s8 f8_1(void) { while (1) {} }
48void f8_2(struct s8 a0) {}
Daniel Dunbare06a75f2009-03-11 22:05:26 +000049
50// This should be passed just as s8.
51
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000052// CHECK: define i64 @f9_1()
Daniel Dunbarcf6bde32009-04-01 07:45:00 +000053
Daniel Dunbareedd2922009-05-08 20:55:49 +000054// FIXME: llvm-gcc expands this, this may have some value for the
55// backend in terms of optimization but doesn't change the ABI.
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000056// CHECK: define void @f9_2(%struct.s9* byval %a0)
Daniel Dunbare06a75f2009-03-11 22:05:26 +000057struct s9 {
58 int a : 17;
59 int b;
60};
Mike Stumpc36541e2009-07-21 20:52:43 +000061struct s9 f9_1(void) { while (1) {} }
62void f9_2(struct s9 a0) {}
Daniel Dunbare06a75f2009-03-11 22:05:26 +000063
Daniel Dunbardfc6b802009-04-01 07:08:38 +000064// Return of small structures and unions
Daniel Dunbar5bde6f42009-03-31 19:01:39 +000065
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000066// CHECK: float @f10()
Daniel Dunbar5bde6f42009-03-31 19:01:39 +000067struct s10 {
68 union { };
69 float f;
Mike Stumpc36541e2009-07-21 20:52:43 +000070} f10(void) { while (1) {} }
Daniel Dunbar5bde6f42009-03-31 19:01:39 +000071
Daniel Dunbardfc6b802009-04-01 07:08:38 +000072// Small vectors and 1 x {i64,double} are returned in registers
Daniel Dunbar5bde6f42009-03-31 19:01:39 +000073
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000074// 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()
Daniel Dunbar36043162009-04-01 06:13:08 +000080typedef short T11 __attribute__ ((vector_size (4)));
Mike Stumpc36541e2009-07-21 20:52:43 +000081T11 f11(void) { while (1) {} }
Daniel Dunbar36043162009-04-01 06:13:08 +000082typedef int T12 __attribute__ ((vector_size (8)));
Mike Stumpc36541e2009-07-21 20:52:43 +000083T12 f12(void) { while (1) {} }
Daniel Dunbar36043162009-04-01 06:13:08 +000084typedef long long T13 __attribute__ ((vector_size (8)));
Mike Stumpc36541e2009-07-21 20:52:43 +000085T13 f13(void) { while (1) {} }
Daniel Dunbar36043162009-04-01 06:13:08 +000086typedef double T14 __attribute__ ((vector_size (8)));
Mike Stumpc36541e2009-07-21 20:52:43 +000087T14 f14(void) { while (1) {} }
Daniel Dunbardfc6b802009-04-01 07:08:38 +000088typedef long long T15 __attribute__ ((vector_size (16)));
Mike Stumpc36541e2009-07-21 20:52:43 +000089T15 f15(void) { while (1) {} }
Daniel Dunbardfc6b802009-04-01 07:08:38 +000090typedef double T16 __attribute__ ((vector_size (16)));
Mike Stumpc36541e2009-07-21 20:52:43 +000091T16 f16(void) { while (1) {} }
Daniel Dunbardfc6b802009-04-01 07:08:38 +000092
93// And when the single element in a struct (but not for 64 and
94// 128-bits).
95
Daniel Dunbard0ef54c2010-04-21 19:34:17 +000096// CHECK: i32 @f17()
97// CHECK: void @f18(%2* sret %agg.result)
98// CHECK: void @f19(%3* sret %agg.result)
99// CHECK: void @f20(%4* sret %agg.result)
100// CHECK: void @f21(%5* sret %agg.result)
101// CHECK: void @f22(%6* sret %agg.result)
Mike Stumpc36541e2009-07-21 20:52:43 +0000102struct { T11 a; } f17(void) { while (1) {} }
103struct { T12 a; } f18(void) { while (1) {} }
104struct { T13 a; } f19(void) { while (1) {} }
105struct { T14 a; } f20(void) { while (1) {} }
106struct { T15 a; } f21(void) { while (1) {} }
107struct { T16 a; } f22(void) { while (1) {} }
Daniel Dunbardfc6b802009-04-01 07:08:38 +0000108
109// Single element structures are handled specially
110
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000111// CHECK: float @f23()
112// CHECK: float @f24()
113// CHECK: float @f25()
Mike Stumpc36541e2009-07-21 20:52:43 +0000114struct { float a; } f23(void) { while (1) {} }
115struct { float a[1]; } f24(void) { while (1) {} }
116struct { struct {} a; struct { float a[1]; } b; } f25(void) { while (1) {} }
Daniel Dunbar36043162009-04-01 06:13:08 +0000117
Daniel Dunbarcf6bde32009-04-01 07:45:00 +0000118// Small structures are handled recursively
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000119// CHECK: i32 @f26()
120// CHECK: void @f27(%struct.s27* sret %agg.result)
Mike Stumpc36541e2009-07-21 20:52:43 +0000121struct s26 { struct { char a, b; } a; struct { char a, b; } b; } f26(void) { while (1) {} }
122struct s27 { struct { char a, b, c; } a; struct { char a; } b; } f27(void) { while (1) {} }
Daniel Dunbarcf6bde32009-04-01 07:45:00 +0000123
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000124// CHECK: void @f28(%struct.s28* sret %agg.result)
Mike Stumpc36541e2009-07-21 20:52:43 +0000125struct s28 { int a; int b[]; } f28(void) { while (1) {} }
Daniel Dunbarf7fff322009-05-08 20:21:04 +0000126
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000127// CHECK: define i16 @f29()
Mike Stumpc36541e2009-07-21 20:52:43 +0000128struct s29 { struct { } a[1]; char b; char c; } f29(void) { while (1) {} }
Daniel Dunbar8e034442009-04-27 18:31:32 +0000129
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000130// CHECK: define i16 @f30()
Mike Stumpc36541e2009-07-21 20:52:43 +0000131struct s30 { char a; char b : 4; } f30(void) { while (1) {} }
Daniel Dunbareedd2922009-05-08 20:55:49 +0000132
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000133// CHECK: define float @f31()
Mike Stumpc36541e2009-07-21 20:52:43 +0000134struct s31 { char : 0; float b; char : 0; } f31(void) { while (1) {} }
Daniel Dunbarfcab2ca2009-05-08 21:04:47 +0000135
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000136// CHECK: define i32 @f32()
Mike Stumpc36541e2009-07-21 20:52:43 +0000137struct s32 { char a; unsigned : 0; } f32(void) { while (1) {} }
Daniel Dunbar2e001162009-05-08 21:30:11 +0000138
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000139// CHECK: define float @f33()
Mike Stumpc36541e2009-07-21 20:52:43 +0000140struct s33 { float a; long long : 0; } f33(void) { while (1) {} }
Daniel Dunbar2e001162009-05-08 21:30:11 +0000141
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000142// CHECK: define float @f34()
Mike Stumpc36541e2009-07-21 20:52:43 +0000143struct s34 { struct { int : 0; } a; float b; } f34(void) { while (1) {} }
Daniel Dunbar573b9072009-05-11 18:58:49 +0000144
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000145// CHECK: define i16 @f35()
Mike Stumpc36541e2009-07-21 20:52:43 +0000146struct s35 { struct { int : 0; } a; char b; char c; } f35(void) { while (1) {} }
Daniel Dunbar573b9072009-05-11 18:58:49 +0000147
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000148// CHECK: define i16 @f36()
Mike Stumpc36541e2009-07-21 20:52:43 +0000149struct s36 { struct { int : 0; } a[2][10]; char b; char c; } f36(void) { while (1) {} }
Daniel Dunbarcc401dc2009-05-11 23:01:34 +0000150
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000151// CHECK: define float @f37()
Mike Stumpc36541e2009-07-21 20:52:43 +0000152struct s37 { float c[1][1]; } f37(void) { while (1) {} }
Daniel Dunbarcc401dc2009-05-11 23:01:34 +0000153
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000154// CHECK: define void @f38(%struct.s38* sret %agg.result)
Mike Stumpc36541e2009-07-21 20:52:43 +0000155struct s38 { char a[3]; short b; } f38(void) { while (1) {} }
Daniel Dunbar836a0642009-05-12 17:00:20 +0000156
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000157// CHECK: define void @f39(%struct.s39* byval align 16 %x)
Eli Friedmana1e6de92009-06-13 21:37:10 +0000158typedef int v39 __attribute((vector_size(16)));
159struct s39 { v39 x; };
160void f39(struct s39 x) {}
161
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000162// <rdar://problem/7247671>
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000163// CHECK: define i32 @f40()
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000164enum e40 { ec0 = 0 };
165enum e40 f40(void) { }
166
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000167// CHECK: define void ()* @f41()
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000168typedef void (^vvbp)(void);
169vvbp f41(void) { }
170
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000171// CHECK: define i32 @f42()
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000172struct s42 { enum e40 f0; } f42(void) { }
173
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000174// CHECK: define i64 @f43()
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000175struct s43 { enum e40 f0; int f1; } f43(void) { }
176
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000177// CHECK: define i32 @f44()
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000178struct s44 { vvbp f0; } f44(void) { }
179
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000180// CHECK: define i64 @f45()
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000181struct s45 { vvbp f0; int f1; } f45(void) { }
182
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000183// CHECK: define void @f46(i32 %a0)
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000184void f46(enum e40 a0) { }
185
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000186// CHECK: define void @f47(void ()* %a1)
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000187void f47(vvbp a1) { }
188
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000189// CHECK: define void @f48(i32 %a0.0)
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000190struct s48 { enum e40 f0; };
191void f48(struct s48 a0) { }
192
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000193// CHECK: define void @f49(i32 %a0.0, i32 %a0.1)
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000194struct s49 { enum e40 f0; int f1; };
195void f49(struct s49 a0) { }
196
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000197// CHECK: define void @f50(void ()* %a0.0)
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000198struct s50 { vvbp f0; };
199void f50(struct s50 a0) { }
200
Daniel Dunbard0ef54c2010-04-21 19:34:17 +0000201// CHECK: define void @f51(void ()* %a0.0, i32 %a0.1)
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000202struct s51 { vvbp f0; int f1; };
203void f51(struct s51 a0) { }
204
Daniel Dunbar46c54fb2010-04-21 19:49:55 +0000205// CHECK: define void @f52(%struct.s52* byval align 16 %x)
206struct s52 {
207 long double a;
208};
209void f52(struct s52 x) {}
210
211// CHECK: define void @f53(%struct.s53* byval align 32 %x)
212struct __attribute__((aligned(32))) s53 {
213 int x;
214 int y;
215};
216void f53(struct s53 x) {}