Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fblocks -triple i386-apple-darwin9 -emit-llvm -o %t %s |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 2 | // RUN: FileCheck < %t %s |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 3 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 4 | // CHECK: define signext i8 @f0() |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 5 | char f0(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 6 | return 0; |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 7 | } |
| 8 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 9 | // CHECK: define signext i16 @f1() |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 10 | short f1(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 11 | return 0; |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 12 | } |
| 13 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 14 | // CHECK: define i32 @f2() |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 15 | int f2(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 16 | return 0; |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 17 | } |
| 18 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 19 | // CHECK: define float @f3() |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 20 | float f3(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 21 | return 0; |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 24 | // CHECK: define double @f4() |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 25 | double f4(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 26 | return 0; |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 29 | // CHECK: define x86_fp80 @f5() |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 30 | long double f5(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 31 | return 0; |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 34 | // CHECK: define void @f6(i8 signext %a0, i16 signext %a1, i32 %a2, i64 %a3, i8* %a4) |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 35 | void f6(char a0, short a1, int a2, long long a3, void *a4) {} |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 36 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 37 | // CHECK: define void @f7(i32 %a0) |
| 38 | typedef enum { A, B, C } e7; |
| 39 | void f7(e7 a0) {} |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 40 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 41 | // CHECK: define i64 @f8_1() |
| 42 | // CHECK: define void @f8_2(i32 %a0.0, i32 %a0.1) |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 43 | struct s8 { |
| 44 | int a; |
| 45 | int b; |
| 46 | }; |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 47 | struct s8 f8_1(void) { while (1) {} } |
| 48 | void f8_2(struct s8 a0) {} |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 49 | |
| 50 | // This should be passed just as s8. |
| 51 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 52 | // CHECK: define i64 @f9_1() |
Daniel Dunbar | cf6bde3 | 2009-04-01 07:45:00 +0000 | [diff] [blame] | 53 | |
Daniel Dunbar | eedd292 | 2009-05-08 20:55:49 +0000 | [diff] [blame] | 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. |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 56 | // CHECK: define void @f9_2(%struct.s9* byval %a0) |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 57 | struct s9 { |
| 58 | int a : 17; |
| 59 | int b; |
| 60 | }; |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 61 | struct s9 f9_1(void) { while (1) {} } |
| 62 | void f9_2(struct s9 a0) {} |
Daniel Dunbar | e06a75f | 2009-03-11 22:05:26 +0000 | [diff] [blame] | 63 | |
Daniel Dunbar | dfc6b80 | 2009-04-01 07:08:38 +0000 | [diff] [blame] | 64 | // Return of small structures and unions |
Daniel Dunbar | 5bde6f4 | 2009-03-31 19:01:39 +0000 | [diff] [blame] | 65 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 66 | // CHECK: float @f10() |
Daniel Dunbar | 5bde6f4 | 2009-03-31 19:01:39 +0000 | [diff] [blame] | 67 | struct s10 { |
| 68 | union { }; |
| 69 | float f; |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 70 | } f10(void) { while (1) {} } |
Daniel Dunbar | 5bde6f4 | 2009-03-31 19:01:39 +0000 | [diff] [blame] | 71 | |
Daniel Dunbar | dfc6b80 | 2009-04-01 07:08:38 +0000 | [diff] [blame] | 72 | // Small vectors and 1 x {i64,double} are returned in registers |
Daniel Dunbar | 5bde6f4 | 2009-03-31 19:01:39 +0000 | [diff] [blame] | 73 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 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() |
Daniel Dunbar | 3604316 | 2009-04-01 06:13:08 +0000 | [diff] [blame] | 80 | typedef short T11 __attribute__ ((vector_size (4))); |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 81 | T11 f11(void) { while (1) {} } |
Daniel Dunbar | 3604316 | 2009-04-01 06:13:08 +0000 | [diff] [blame] | 82 | typedef int T12 __attribute__ ((vector_size (8))); |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 83 | T12 f12(void) { while (1) {} } |
Daniel Dunbar | 3604316 | 2009-04-01 06:13:08 +0000 | [diff] [blame] | 84 | typedef long long T13 __attribute__ ((vector_size (8))); |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 85 | T13 f13(void) { while (1) {} } |
Daniel Dunbar | 3604316 | 2009-04-01 06:13:08 +0000 | [diff] [blame] | 86 | typedef double T14 __attribute__ ((vector_size (8))); |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 87 | T14 f14(void) { while (1) {} } |
Daniel Dunbar | dfc6b80 | 2009-04-01 07:08:38 +0000 | [diff] [blame] | 88 | typedef long long T15 __attribute__ ((vector_size (16))); |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 89 | T15 f15(void) { while (1) {} } |
Daniel Dunbar | dfc6b80 | 2009-04-01 07:08:38 +0000 | [diff] [blame] | 90 | typedef double T16 __attribute__ ((vector_size (16))); |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 91 | T16 f16(void) { while (1) {} } |
Daniel Dunbar | dfc6b80 | 2009-04-01 07:08:38 +0000 | [diff] [blame] | 92 | |
| 93 | // And when the single element in a struct (but not for 64 and |
| 94 | // 128-bits). |
| 95 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 96 | // 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 Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 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) {} } |
Daniel Dunbar | dfc6b80 | 2009-04-01 07:08:38 +0000 | [diff] [blame] | 108 | |
| 109 | // Single element structures are handled specially |
| 110 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 111 | // CHECK: float @f23() |
| 112 | // CHECK: float @f24() |
| 113 | // CHECK: float @f25() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 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) {} } |
Daniel Dunbar | 3604316 | 2009-04-01 06:13:08 +0000 | [diff] [blame] | 117 | |
Daniel Dunbar | cf6bde3 | 2009-04-01 07:45:00 +0000 | [diff] [blame] | 118 | // Small structures are handled recursively |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 119 | // CHECK: i32 @f26() |
| 120 | // CHECK: void @f27(%struct.s27* sret %agg.result) |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 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) {} } |
Daniel Dunbar | cf6bde3 | 2009-04-01 07:45:00 +0000 | [diff] [blame] | 123 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 124 | // CHECK: void @f28(%struct.s28* sret %agg.result) |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 125 | struct s28 { int a; int b[]; } f28(void) { while (1) {} } |
Daniel Dunbar | f7fff32 | 2009-05-08 20:21:04 +0000 | [diff] [blame] | 126 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 127 | // CHECK: define i16 @f29() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 128 | struct s29 { struct { } a[1]; char b; char c; } f29(void) { while (1) {} } |
Daniel Dunbar | 8e03444 | 2009-04-27 18:31:32 +0000 | [diff] [blame] | 129 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 130 | // CHECK: define i16 @f30() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 131 | struct s30 { char a; char b : 4; } f30(void) { while (1) {} } |
Daniel Dunbar | eedd292 | 2009-05-08 20:55:49 +0000 | [diff] [blame] | 132 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 133 | // CHECK: define float @f31() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 134 | struct s31 { char : 0; float b; char : 0; } f31(void) { while (1) {} } |
Daniel Dunbar | fcab2ca | 2009-05-08 21:04:47 +0000 | [diff] [blame] | 135 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 136 | // CHECK: define i32 @f32() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 137 | struct s32 { char a; unsigned : 0; } f32(void) { while (1) {} } |
Daniel Dunbar | 2e00116 | 2009-05-08 21:30:11 +0000 | [diff] [blame] | 138 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 139 | // CHECK: define float @f33() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 140 | struct s33 { float a; long long : 0; } f33(void) { while (1) {} } |
Daniel Dunbar | 2e00116 | 2009-05-08 21:30:11 +0000 | [diff] [blame] | 141 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 142 | // CHECK: define float @f34() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 143 | struct s34 { struct { int : 0; } a; float b; } f34(void) { while (1) {} } |
Daniel Dunbar | 573b907 | 2009-05-11 18:58:49 +0000 | [diff] [blame] | 144 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 145 | // CHECK: define i16 @f35() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 146 | struct s35 { struct { int : 0; } a; char b; char c; } f35(void) { while (1) {} } |
Daniel Dunbar | 573b907 | 2009-05-11 18:58:49 +0000 | [diff] [blame] | 147 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 148 | // CHECK: define i16 @f36() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 149 | struct s36 { struct { int : 0; } a[2][10]; char b; char c; } f36(void) { while (1) {} } |
Daniel Dunbar | cc401dc | 2009-05-11 23:01:34 +0000 | [diff] [blame] | 150 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 151 | // CHECK: define float @f37() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 152 | struct s37 { float c[1][1]; } f37(void) { while (1) {} } |
Daniel Dunbar | cc401dc | 2009-05-11 23:01:34 +0000 | [diff] [blame] | 153 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 154 | // CHECK: define void @f38(%struct.s38* sret %agg.result) |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 155 | struct s38 { char a[3]; short b; } f38(void) { while (1) {} } |
Daniel Dunbar | 836a064 | 2009-05-12 17:00:20 +0000 | [diff] [blame] | 156 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 157 | // CHECK: define void @f39(%struct.s39* byval align 16 %x) |
Eli Friedman | a1e6de9 | 2009-06-13 21:37:10 +0000 | [diff] [blame] | 158 | typedef int v39 __attribute((vector_size(16))); |
| 159 | struct s39 { v39 x; }; |
| 160 | void f39(struct s39 x) {} |
| 161 | |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 162 | // <rdar://problem/7247671> |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 163 | // CHECK: define i32 @f40() |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 164 | enum e40 { ec0 = 0 }; |
| 165 | enum e40 f40(void) { } |
| 166 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 167 | // CHECK: define void ()* @f41() |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 168 | typedef void (^vvbp)(void); |
| 169 | vvbp f41(void) { } |
| 170 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 171 | // CHECK: define i32 @f42() |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 172 | struct s42 { enum e40 f0; } f42(void) { } |
| 173 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 174 | // CHECK: define i64 @f43() |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 175 | struct s43 { enum e40 f0; int f1; } f43(void) { } |
| 176 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 177 | // CHECK: define i32 @f44() |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 178 | struct s44 { vvbp f0; } f44(void) { } |
| 179 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 180 | // CHECK: define i64 @f45() |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 181 | struct s45 { vvbp f0; int f1; } f45(void) { } |
| 182 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 183 | // CHECK: define void @f46(i32 %a0) |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 184 | void f46(enum e40 a0) { } |
| 185 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 186 | // CHECK: define void @f47(void ()* %a1) |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 187 | void f47(vvbp a1) { } |
| 188 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 189 | // CHECK: define void @f48(i32 %a0.0) |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 190 | struct s48 { enum e40 f0; }; |
| 191 | void f48(struct s48 a0) { } |
| 192 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 193 | // CHECK: define void @f49(i32 %a0.0, i32 %a0.1) |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 194 | struct s49 { enum e40 f0; int f1; }; |
| 195 | void f49(struct s49 a0) { } |
| 196 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 197 | // CHECK: define void @f50(void ()* %a0.0) |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 198 | struct s50 { vvbp f0; }; |
| 199 | void f50(struct s50 a0) { } |
| 200 | |
Daniel Dunbar | d0ef54c | 2010-04-21 19:34:17 +0000 | [diff] [blame] | 201 | // CHECK: define void @f51(void ()* %a0.0, i32 %a0.1) |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 202 | struct s51 { vvbp f0; int f1; }; |
| 203 | void f51(struct s51 a0) { } |
| 204 | |
Daniel Dunbar | 46c54fb | 2010-04-21 19:49:55 +0000 | [diff] [blame] | 205 | // CHECK: define void @f52(%struct.s52* byval align 16 %x) |
| 206 | struct s52 { |
| 207 | long double a; |
| 208 | }; |
| 209 | void f52(struct s52 x) {} |
| 210 | |
| 211 | // CHECK: define void @f53(%struct.s53* byval align 32 %x) |
| 212 | struct __attribute__((aligned(32))) s53 { |
| 213 | int x; |
| 214 | int y; |
| 215 | }; |
| 216 | void f53(struct s53 x) {} |