blob: 33f635c31ae19ffe56e0797173c354a1bea39017 [file] [log] [blame]
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00001// RUN: clang-cc -fblocks -triple i386-apple-darwin9 -emit-llvm -o %t %s
2// RUN: grep 'define signext i8 @f0()' %t
3// RUN: grep 'define signext i16 @f1()' %t
4// RUN: grep 'define i32 @f2()' %t
5// RUN: grep 'define float @f3()' %t
6// RUN: grep 'define double @f4()' %t
7// RUN: grep 'define x86_fp80 @f5()' %t
8// RUN: grep 'define void @f6(i8 signext %a0, i16 signext %a1, i32 %a2, i64 %a3, i8\* %a4)' %t
9// RUN: grep 'define void @f7(i32 %a0)' %t
10// RUN: grep 'define i64 @f8_1()' %t
11// RUN: grep 'define void @f8_2(i32 %a0.0, i32 %a0.1)' %t
Daniel Dunbare06a75f2009-03-11 22:05:26 +000012
Daniel Dunbare06a75f2009-03-11 22:05:26 +000013char f0(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000014 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000015}
16
17short f1(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000018 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000019}
20
21int f2(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000022 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000023}
24
25float f3(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000026 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000027}
28
29double f4(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000030 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000031}
32
33long double f5(void) {
Mike Stumpc36541e2009-07-21 20:52:43 +000034 return 0;
Daniel Dunbare06a75f2009-03-11 22:05:26 +000035}
36
Mike Stumpc36541e2009-07-21 20:52:43 +000037void f6(char a0, short a1, int a2, long long a3, void *a4) {}
Daniel Dunbare06a75f2009-03-11 22:05:26 +000038
39typedef enum { A, B, C } E;
40
Mike Stumpc36541e2009-07-21 20:52:43 +000041void f7(E a0) {}
Daniel Dunbare06a75f2009-03-11 22:05:26 +000042
43struct 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 Dunbar4fcfde42009-11-08 01:45:36 +000052// RUN: grep 'define i64 @f9_1()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +000056// RUN: grep 'define void @f9_2(%.truct.s9\* byval %a0)' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +000066// RUN: grep 'float @f10()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +000074// RUN: grep 'i32 @f11()' %t
75// RUN: grep -F 'void @f12(<2 x i32>* noalias sret %agg.result)' %t
76// RUN: grep 'i64 @f13()' %t
77// RUN: grep 'i64 @f14()' %t
78// RUN: grep '<2 x i64> @f15()' %t
79// RUN: grep '<2 x i64> @f16()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +000096// RUN: grep 'i32 @f17()' %t
97// RUN: grep -F 'void @f18(%2* noalias sret %agg.result)' %t
98// RUN: grep -F 'void @f19(%3* noalias sret %agg.result)' %t
99// RUN: grep -F 'void @f20(%4* noalias sret %agg.result)' %t
100// RUN: grep -F 'void @f21(%5* noalias sret %agg.result)' %t
101// RUN: grep -F 'void @f22(%6* noalias sret %agg.result)' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000111// RUN: grep -F 'float @f23()' %t
112// RUN: grep -F 'float @f24()' %t
113// RUN: grep -F 'float @f25()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000119// RUN: grep -F 'i32 @f26()' %t
120// RUN: grep 'void @f27(%.truct.s27\* noalias sret %agg.result)' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000124// RUN: grep 'void @f28(%.truct.s28\* noalias sret %agg.result)' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000127// RUN: grep 'define i16 @f29()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000130// RUN: grep 'define i16 @f30()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000133// RUN: grep 'define float @f31()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000136// RUN: grep 'define i32 @f32()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000139// RUN: grep 'define float @f33()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000142// RUN: grep 'define float @f34()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000145// RUN: grep 'define i16 @f35()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000148// RUN: grep 'define i16 @f36()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000151// RUN: grep 'define float @f37()' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000154// RUN: grep 'define void @f38(.struct.s38. noalias sret .agg.result)' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000157// RUN: grep 'define void @f39(.struct.s39. byval align 16 .x)' %t
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 Dunbar4fcfde42009-11-08 01:45:36 +0000163// RUN: grep 'define i32 @f40()' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000164enum e40 { ec0 = 0 };
165enum e40 f40(void) { }
166
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000167// RUN: grep 'define void ()\* @f41()' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000168typedef void (^vvbp)(void);
169vvbp f41(void) { }
170
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000171// RUN: grep 'define i32 @f42()' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000172struct s42 { enum e40 f0; } f42(void) { }
173
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000174// RUN: grep 'define i64 @f43()' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000175struct s43 { enum e40 f0; int f1; } f43(void) { }
176
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000177// RUN: grep 'define i32 @f44()' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000178struct s44 { vvbp f0; } f44(void) { }
179
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000180// RUN: grep 'define i64 @f45()' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000181struct s45 { vvbp f0; int f1; } f45(void) { }
182
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000183// RUN: grep 'define void @f46(i32 %a0)' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000184void f46(enum e40 a0) { }
185
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000186// RUN: grep 'define void @f47(void ()\* %a1)' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000187void f47(vvbp a1) { }
188
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000189// RUN: grep 'define void @f48(i32 %a0.0)' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000190struct s48 { enum e40 f0; };
191void f48(struct s48 a0) { }
192
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000193// RUN: grep 'define void @f49(i32 %a0.0, i32 %a0.1)' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000194struct s49 { enum e40 f0; int f1; };
195void f49(struct s49 a0) { }
196
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000197// RUN: grep 'define void @f50(void ()\* %a0.0)' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000198struct s50 { vvbp f0; };
199void f50(struct s50 a0) { }
200
Daniel Dunbar4fcfde42009-11-08 01:45:36 +0000201// RUN: grep 'define void @f51(void ()\* %a0.0, i32 %a0.1)' %t
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000202struct s51 { vvbp f0; int f1; };
203void f51(struct s51 a0) { }
204