Chris Lattner | 22fd4ba | 2010-08-25 23:39:14 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s| FileCheck %s |
Chris Lattner | a8b7a7d | 2010-08-26 06:28:35 +0000 | [diff] [blame] | 2 | #include <stdarg.h> |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 3 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 4 | // CHECK: %0 = type { i64, double } |
| 5 | |
| 6 | // CHECK: define signext i8 @f0() |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 7 | char f0(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 8 | return 0; |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 9 | } |
| 10 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 11 | // CHECK: define signext i16 @f1() |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 12 | short f1(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 13 | return 0; |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 14 | } |
| 15 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 16 | // CHECK: define i32 @f2() |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 17 | int f2(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 18 | return 0; |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 21 | // CHECK: define float @f3() |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 22 | float f3(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 23 | return 0; |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 26 | // CHECK: define double @f4() |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 27 | double f4(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 28 | return 0; |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 31 | // CHECK: define x86_fp80 @f5() |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 32 | long double f5(void) { |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 33 | return 0; |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 36 | // CHECK: define void @f6(i8 signext %a0, i16 signext %a1, i32 %a2, i64 %a3, i8* %a4) |
Daniel Dunbar | 644f4c3 | 2009-02-14 02:09:24 +0000 | [diff] [blame] | 37 | void f6(char a0, short a1, int a2, long long a3, void *a4) { |
| 38 | } |
Anders Carlsson | 730f909 | 2009-02-26 17:38:19 +0000 | [diff] [blame] | 39 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 40 | // CHECK: define void @f7(i32 %a0) |
| 41 | typedef enum { A, B, C } e7; |
| 42 | void f7(e7 a0) { |
Mike Stump | 4b87142 | 2009-02-26 19:00:14 +0000 | [diff] [blame] | 43 | } |
Daniel Dunbar | 100f402 | 2009-03-06 17:50:25 +0000 | [diff] [blame] | 44 | |
| 45 | // Test merging/passing of upper eightbyte with X87 class. |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 46 | // |
| 47 | // CHECK: define %0 @f8_1() |
Chris Lattner | 225e286 | 2010-06-29 00:14:52 +0000 | [diff] [blame] | 48 | // CHECK: define void @f8_2(i64 %a0.coerce0, double %a0.coerce1) |
Daniel Dunbar | 100f402 | 2009-03-06 17:50:25 +0000 | [diff] [blame] | 49 | union u8 { |
| 50 | long double a; |
| 51 | int b; |
| 52 | }; |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 53 | union u8 f8_1() { while (1) {} } |
Daniel Dunbar | 100f402 | 2009-03-06 17:50:25 +0000 | [diff] [blame] | 54 | void f8_2(union u8 a0) {} |
Daniel Dunbar | 8236bf1 | 2009-05-08 22:26:44 +0000 | [diff] [blame] | 55 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 56 | // CHECK: define i64 @f9() |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 57 | struct s9 { int a; int b; int : 0; } f9(void) { while (1) {} } |
Daniel Dunbar | 8236bf1 | 2009-05-08 22:26:44 +0000 | [diff] [blame] | 58 | |
Chris Lattner | 225e286 | 2010-06-29 00:14:52 +0000 | [diff] [blame] | 59 | // CHECK: define void @f10(i64 %a0.coerce) |
Daniel Dunbar | 8236bf1 | 2009-05-08 22:26:44 +0000 | [diff] [blame] | 60 | struct s10 { int a; int b; int : 0; }; |
| 61 | void f10(struct s10 a0) {} |
| 62 | |
Daniel Dunbar | 46c54fb | 2010-04-21 19:49:55 +0000 | [diff] [blame] | 63 | // CHECK: define void @f11(%struct.s19* sret %agg.result) |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 64 | union { long double a; float b; } f11() { while (1) {} } |
Daniel Dunbar | 20e95c5 | 2009-05-12 15:22:40 +0000 | [diff] [blame] | 65 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 66 | // CHECK: define i32 @f12_0() |
| 67 | // CHECK: define void @f12_1(i32 %a0.coerce) |
Daniel Dunbar | 7ef455b | 2009-05-13 18:54:26 +0000 | [diff] [blame] | 68 | struct s12 { int a __attribute__((aligned(16))); }; |
Mike Stump | c36541e | 2009-07-21 20:52:43 +0000 | [diff] [blame] | 69 | struct s12 f12_0(void) { while (1) {} } |
Daniel Dunbar | 7ef455b | 2009-05-13 18:54:26 +0000 | [diff] [blame] | 70 | void f12_1(struct s12 a0) {} |
| 71 | |
Daniel Dunbar | 3a5f5c5 | 2009-05-22 17:33:44 +0000 | [diff] [blame] | 72 | // Check that sret parameter is accounted for when checking available integer |
| 73 | // registers. |
Chris Lattner | 121b3fa | 2010-07-05 20:21:00 +0000 | [diff] [blame] | 74 | // CHECK: define void @f13(%struct.s13_0* sret %agg.result, i32 %a, i32 %b, i32 %c, i32 %d, {{.*}}* byval %e, i32 %f) |
Daniel Dunbar | 3a5f5c5 | 2009-05-22 17:33:44 +0000 | [diff] [blame] | 75 | |
| 76 | struct s13_0 { long long f0[3]; }; |
Daniel Dunbar | 55a759b | 2009-08-23 19:28:59 +0000 | [diff] [blame] | 77 | struct s13_1 { long long f0[2]; }; |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 78 | struct s13_0 f13(int a, int b, int c, int d, |
Daniel Dunbar | 55a759b | 2009-08-23 19:28:59 +0000 | [diff] [blame] | 79 | struct s13_1 e, int f) { while (1) {} } |
Daniel Dunbar | 3a5f5c5 | 2009-05-22 17:33:44 +0000 | [diff] [blame] | 80 | |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 81 | // CHECK: define void @f14({{.*}}, i8 signext %X) |
| 82 | void f14(int a, int b, int c, int d, int e, int f, char X) {} |
| 83 | |
| 84 | // CHECK: define void @f15({{.*}}, i8* %X) |
| 85 | void f15(int a, int b, int c, int d, int e, int f, void *X) {} |
| 86 | |
| 87 | // CHECK: define void @f16({{.*}}, float %X) |
Daniel Dunbar | 86e13ee | 2009-05-26 16:37:37 +0000 | [diff] [blame] | 88 | void f16(float a, float b, float c, float d, float e, float f, float g, float h, |
| 89 | float X) {} |
Daniel Dunbar | 0aa1cba | 2010-04-21 19:10:54 +0000 | [diff] [blame] | 90 | |
| 91 | // CHECK: define void @f17({{.*}}, x86_fp80 %X) |
Daniel Dunbar | 86e13ee | 2009-05-26 16:37:37 +0000 | [diff] [blame] | 92 | void f17(float a, float b, float c, float d, float e, float f, float g, float h, |
| 93 | long double X) {} |
| 94 | |
Chris Lattner | faf23b7 | 2010-06-28 19:56:59 +0000 | [diff] [blame] | 95 | // Check for valid coercion. The struct should be passed/returned as i32, not |
| 96 | // as i64 for better code quality. |
| 97 | // rdar://8135035 |
Chris Lattner | 225e286 | 2010-06-29 00:14:52 +0000 | [diff] [blame] | 98 | // CHECK: define void @f18(i32 %a, i32 %f18_arg1.coerce) |
Daniel Dunbar | 55a759b | 2009-08-23 19:28:59 +0000 | [diff] [blame] | 99 | struct f18_s0 { int f0; }; |
| 100 | void f18(int a, struct f18_s0 f18_arg1) { while (1) {} } |
Daniel Dunbar | fdf4986 | 2009-06-05 07:58:54 +0000 | [diff] [blame] | 101 | |
Daniel Dunbar | 46c54fb | 2010-04-21 19:49:55 +0000 | [diff] [blame] | 102 | // Check byval alignment. |
| 103 | |
| 104 | // CHECK: define void @f19(%struct.s19* byval align 16 %x) |
| 105 | struct s19 { |
| 106 | long double a; |
| 107 | }; |
| 108 | void f19(struct s19 x) {} |
| 109 | |
| 110 | // CHECK: define void @f20(%struct.s20* byval align 32 %x) |
| 111 | struct __attribute__((aligned(32))) s20 { |
| 112 | int x; |
| 113 | int y; |
| 114 | }; |
| 115 | void f20(struct s20 x) {} |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 116 | |
| 117 | struct StringRef { |
| 118 | long x; |
| 119 | const char *Ptr; |
| 120 | }; |
| 121 | |
| 122 | // rdar://7375902 |
| 123 | // CHECK: define i8* @f21(i64 %S.coerce0, i8* %S.coerce1) |
| 124 | const char *f21(struct StringRef S) { return S.x+S.Ptr; } |
| 125 | |
Chris Lattner | 121b3fa | 2010-07-05 20:21:00 +0000 | [diff] [blame] | 126 | // PR7567 |
| 127 | typedef __attribute__ ((aligned(16))) struct f22s { unsigned long long x[2]; } L; |
| 128 | void f22(L x, L y) { } |
| 129 | // CHECK: @f22 |
| 130 | // CHECK: %x = alloca{{.*}}, align 16 |
| 131 | // CHECK: %y = alloca{{.*}}, align 16 |
| 132 | |
| 133 | |
Chris Lattner | 1daf808 | 2010-07-28 22:15:08 +0000 | [diff] [blame] | 134 | |
| 135 | // PR7714 |
| 136 | struct f23S { |
| 137 | short f0; |
| 138 | unsigned f1; |
| 139 | int f2; |
| 140 | }; |
| 141 | |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 142 | |
Chris Lattner | 1daf808 | 2010-07-28 22:15:08 +0000 | [diff] [blame] | 143 | void f23(int A, struct f23S B) { |
| 144 | // CHECK: define void @f23(i32 %A, i64 %B.coerce0, i32 %B.coerce1) |
| 145 | } |
| 146 | |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 147 | struct f24s { long a; int b; }; |
Chris Lattner | 1daf808 | 2010-07-28 22:15:08 +0000 | [diff] [blame] | 148 | |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 149 | struct f23S f24(struct f23S *X, struct f24s *P2) { |
| 150 | return *X; |
| 151 | |
| 152 | // CHECK: define %struct.f24s @f24(%struct.f23S* %X, %struct.f24s* %P2) |
| 153 | } |
Chris Lattner | 1daf808 | 2010-07-28 22:15:08 +0000 | [diff] [blame] | 154 | |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 155 | // rdar://8248065 |
Chris Lattner | ab5722e | 2010-07-28 23:47:21 +0000 | [diff] [blame] | 156 | typedef float v4f32 __attribute__((__vector_size__(16))); |
Chris Lattner | ab5722e | 2010-07-28 23:47:21 +0000 | [diff] [blame] | 157 | v4f32 f25(v4f32 X) { |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 158 | // CHECK: define <4 x float> @f25(<4 x float> %X) |
| 159 | // CHECK-NOT: alloca |
Chris Lattner | c10ab19 | 2010-07-29 17:14:05 +0000 | [diff] [blame] | 160 | // CHECK: alloca <4 x float> |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 161 | // CHECK-NOT: alloca |
Chris Lattner | c10ab19 | 2010-07-29 17:14:05 +0000 | [diff] [blame] | 162 | // CHECK: store <4 x float> %X, <4 x float>* |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 163 | // CHECK-NOT: store |
| 164 | // CHECK: ret <4 x float> |
Chris Lattner | ab5722e | 2010-07-28 23:47:21 +0000 | [diff] [blame] | 165 | return X+X; |
| 166 | } |
| 167 | |
Chris Lattner | 4711cb0 | 2010-07-29 04:46:19 +0000 | [diff] [blame] | 168 | struct foo26 { |
| 169 | int *X; |
| 170 | float *Y; |
| 171 | }; |
Chris Lattner | ab5722e | 2010-07-28 23:47:21 +0000 | [diff] [blame] | 172 | |
Chris Lattner | 4711cb0 | 2010-07-29 04:46:19 +0000 | [diff] [blame] | 173 | struct foo26 f26(struct foo26 *P) { |
| 174 | // CHECK: define %struct.foo26 @f26(%struct.foo26* %P) |
| 175 | return *P; |
| 176 | } |
Chris Lattner | 15842bd | 2010-07-29 05:02:29 +0000 | [diff] [blame] | 177 | |
| 178 | |
| 179 | struct v4f32wrapper { |
| 180 | v4f32 v; |
| 181 | }; |
| 182 | |
| 183 | struct v4f32wrapper f27(struct v4f32wrapper X) { |
| 184 | // CHECK: define <4 x float> @f27(<4 x float> %X.coerce) |
| 185 | return X; |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | // rdar://5711709 |
| 189 | struct f28c { |
| 190 | double x; |
| 191 | int y; |
| 192 | }; |
| 193 | void f28(struct f28c C) { |
| 194 | // CHECK: define void @f28(double %C.coerce0, i32 %C.coerce1) |
| 195 | } |
| 196 | |
Chris Lattner | 021c3a3 | 2010-07-29 07:43:55 +0000 | [diff] [blame] | 197 | struct f29a { |
| 198 | struct c { |
| 199 | double x; |
| 200 | int y; |
| 201 | } x[1]; |
| 202 | }; |
| 203 | |
| 204 | void f29a(struct f29a A) { |
| 205 | // CHECK: define void @f29a(double %A.coerce0, i32 %A.coerce1) |
| 206 | } |
Chris Lattner | 9e45a3d | 2010-07-29 17:34:39 +0000 | [diff] [blame] | 207 | |
| 208 | // rdar://8249586 |
| 209 | struct S0 { char f0[8]; char f2; char f3; char f4; }; |
| 210 | void f30(struct S0 p_4) { |
| 211 | // CHECK: define void @f30(i64 %p_4.coerce0, i24 %p_4.coerce1) |
| 212 | } |
Chris Lattner | f47c944 | 2010-07-29 18:13:09 +0000 | [diff] [blame] | 213 | |
| 214 | // Pass the third element as a float when followed by tail padding. |
| 215 | // rdar://8251384 |
| 216 | struct f31foo { float a, b, c; }; |
| 217 | float f31(struct f31foo X) { |
Chris Lattner | 22fd4ba | 2010-08-25 23:39:14 +0000 | [diff] [blame] | 218 | // CHECK: define float @f31(<2 x float> %X.coerce0, float %X.coerce1) |
Chris Lattner | f47c944 | 2010-07-29 18:13:09 +0000 | [diff] [blame] | 219 | return X.c; |
| 220 | } |
| 221 | |
Chris Lattner | 22fd4ba | 2010-08-25 23:39:14 +0000 | [diff] [blame] | 222 | _Complex float f32(_Complex float A, _Complex float B) { |
| 223 | // rdar://6379669 |
| 224 | // CHECK: define <2 x float> @f32(<2 x float> %A.coerce, <2 x float> %B.coerce) |
| 225 | return A+B; |
| 226 | } |
| 227 | |
Chris Lattner | f47c944 | 2010-07-29 18:13:09 +0000 | [diff] [blame] | 228 | |
Chris Lattner | a8b7a7d | 2010-08-26 06:28:35 +0000 | [diff] [blame] | 229 | // rdar://8357396 |
| 230 | struct f33s { long x; float c,d; }; |
| 231 | |
| 232 | void f33(va_list X) { |
| 233 | va_arg(X, struct f33s); |
| 234 | } |
| 235 | |
Chris Lattner | 473f8e7 | 2010-08-26 18:03:20 +0000 | [diff] [blame] | 236 | typedef unsigned long long v1i64 __attribute__((__vector_size__(8))); |
| 237 | |
| 238 | // rdar://8359248 |
| 239 | // CHECK: define i64 @f34(i64 %arg.coerce) |
| 240 | v1i64 f34(v1i64 arg) { return arg; } |
Chris Lattner | a8b7a7d | 2010-08-26 06:28:35 +0000 | [diff] [blame] | 241 | |
Chris Lattner | 0fefa41 | 2010-08-26 18:13:50 +0000 | [diff] [blame] | 242 | |
| 243 | // rdar://8358475 |
| 244 | // CHECK: define i64 @f35(i64 %arg.coerce) |
| 245 | typedef unsigned long v1i64_2 __attribute__((__vector_size__(8))); |
| 246 | v1i64_2 f35(v1i64_2 arg) { return arg+arg; } |
| 247 | |