x86_32-arguments-darwin.c revision bb465d7d0489a6605bb1eb82dea87350066ac5e2
1// RUN: %clang_cc1 -w -fblocks -triple i386-apple-darwin9 -emit-llvm -o %t %s 2// RUN: FileCheck < %t %s 3 4// CHECK: define signext i8 @f0() 5char f0(void) { 6 return 0; 7} 8 9// CHECK: define signext i16 @f1() 10short f1(void) { 11 return 0; 12} 13 14// CHECK: define i32 @f2() 15int f2(void) { 16 return 0; 17} 18 19// CHECK: define float @f3() 20float f3(void) { 21 return 0; 22} 23 24// CHECK: define double @f4() 25double f4(void) { 26 return 0; 27} 28 29// CHECK: define x86_fp80 @f5() 30long double f5(void) { 31 return 0; 32} 33 34// CHECK: define void @f6(i8 signext %a0, i16 signext %a1, i32 %a2, i64 %a3, i8* %a4) 35void f6(char a0, short a1, int a2, long long a3, void *a4) {} 36 37// CHECK: define void @f7(i32 %a0) 38typedef enum { A, B, C } e7; 39void f7(e7 a0) {} 40 41// CHECK: define i64 @f8_1() 42// CHECK: define void @f8_2(i32 %a0.0, i32 %a0.1) 43struct s8 { 44 int a; 45 int b; 46}; 47struct s8 f8_1(void) { while (1) {} } 48void f8_2(struct s8 a0) {} 49 50// This should be passed just as s8. 51 52// CHECK: define i64 @f9_1() 53 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) 57struct s9 { 58 int a : 17; 59 int b; 60}; 61struct s9 f9_1(void) { while (1) {} } 62void f9_2(struct s9 a0) {} 63 64// Return of small structures and unions 65 66// CHECK: float @f10() 67struct s10 { 68 union { }; 69 float f; 70} f10(void) { while (1) {} } 71 72// Small vectors and 1 x {i64,double} are returned in registers 73 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() 80typedef short T11 __attribute__ ((vector_size (4))); 81T11 f11(void) { while (1) {} } 82typedef int T12 __attribute__ ((vector_size (8))); 83T12 f12(void) { while (1) {} } 84typedef long long T13 __attribute__ ((vector_size (8))); 85T13 f13(void) { while (1) {} } 86typedef double T14 __attribute__ ((vector_size (8))); 87T14 f14(void) { while (1) {} } 88typedef long long T15 __attribute__ ((vector_size (16))); 89T15 f15(void) { while (1) {} } 90typedef double T16 __attribute__ ((vector_size (16))); 91T16 f16(void) { while (1) {} } 92 93// And when the single element in a struct (but not for 64 and 94// 128-bits). 95 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) 102struct { 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) {} } 108 109// Single element structures are handled specially 110 111// CHECK: float @f23() 112// CHECK: float @f24() 113// CHECK: float @f25() 114struct { 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) {} } 117 118// Small structures are handled recursively 119// CHECK: i32 @f26() 120// CHECK: void @f27(%struct.s27* sret %agg.result) 121struct 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) {} } 123 124// CHECK: void @f28(%struct.s28* sret %agg.result) 125struct s28 { int a; int b[]; } f28(void) { while (1) {} } 126 127// CHECK: define i16 @f29() 128struct s29 { struct { } a[1]; char b; char c; } f29(void) { while (1) {} } 129 130// CHECK: define i16 @f30() 131struct s30 { char a; char b : 4; } f30(void) { while (1) {} } 132 133// CHECK: define float @f31() 134struct s31 { char : 0; float b; char : 0; } f31(void) { while (1) {} } 135 136// CHECK: define i32 @f32() 137struct s32 { char a; unsigned : 0; } f32(void) { while (1) {} } 138 139// CHECK: define float @f33() 140struct s33 { float a; long long : 0; } f33(void) { while (1) {} } 141 142// CHECK: define float @f34() 143struct s34 { struct { int : 0; } a; float b; } f34(void) { while (1) {} } 144 145// CHECK: define i16 @f35() 146struct s35 { struct { int : 0; } a; char b; char c; } f35(void) { while (1) {} } 147 148// CHECK: define i16 @f36() 149struct s36 { struct { int : 0; } a[2][10]; char b; char c; } f36(void) { while (1) {} } 150 151// CHECK: define float @f37() 152struct s37 { float c[1][1]; } f37(void) { while (1) {} } 153 154// CHECK: define void @f38(%struct.s38* sret %agg.result) 155struct s38 { char a[3]; short b; } f38(void) { while (1) {} } 156 157// CHECK: define void @f39(%struct.s39* byval align 16 %x) 158typedef int v39 __attribute((vector_size(16))); 159struct s39 { v39 x; }; 160void f39(struct s39 x) {} 161 162// <rdar://problem/7247671> 163// CHECK: define i32 @f40() 164enum e40 { ec0 = 0 }; 165enum e40 f40(void) { } 166 167// CHECK: define void ()* @f41() 168typedef void (^vvbp)(void); 169vvbp f41(void) { } 170 171// CHECK: define i32 @f42() 172struct s42 { enum e40 f0; } f42(void) { } 173 174// CHECK: define i64 @f43() 175struct s43 { enum e40 f0; int f1; } f43(void) { } 176 177// CHECK: define i32 @f44() 178struct s44 { vvbp f0; } f44(void) { } 179 180// CHECK: define i64 @f45() 181struct s45 { vvbp f0; int f1; } f45(void) { } 182 183// CHECK: define void @f46(i32 %a0) 184void f46(enum e40 a0) { } 185 186// CHECK: define void @f47(void ()* %a1) 187void f47(vvbp a1) { } 188 189// CHECK: define void @f48(i32 %a0.0) 190struct s48 { enum e40 f0; }; 191void f48(struct s48 a0) { } 192 193// CHECK: define void @f49(i32 %a0.0, i32 %a0.1) 194struct s49 { enum e40 f0; int f1; }; 195void f49(struct s49 a0) { } 196 197// CHECK: define void @f50(void ()* %a0.0) 198struct s50 { vvbp f0; }; 199void f50(struct s50 a0) { } 200 201// CHECK: define void @f51(void ()* %a0.0, i32 %a0.1) 202struct s51 { vvbp f0; int f1; }; 203void f51(struct s51 a0) { } 204 205// CHECK: define void @f52(%struct.s52* byval align 4) 206struct s52 { 207 long double a; 208}; 209void f52(struct s52 x) {} 210 211// CHECK: define void @f53(%struct.s53* byval align 4) 212struct __attribute__((aligned(32))) s53 { 213 int x; 214 int y; 215}; 216void f53(struct s53 x) {} 217 218typedef unsigned short v2i16 __attribute__((__vector_size__(4))); 219 220// CHECK: define i32 @f54(i32 %arg.coerce) 221// rdar://8359483 222v2i16 f54(v2i16 arg) { return arg+arg; } 223 224 225typedef int v4i32 __attribute__((__vector_size__(16))); 226 227// CHECK: define <2 x i64> @f55(<4 x i32> %arg) 228// PR8029 229v4i32 f55(v4i32 arg) { return arg+arg; } 230 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) 239 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: } 249// 250// <rdar://problem/7964854> [i386] clang misaligns long double in structures 251// when passed byval 252// <rdar://problem/8431367> clang misaligns parameters on stack 253typedef int __attribute__((vector_size (8))) t56_v2i; 254typedef double __attribute__((vector_size (8))) t56_v1d; 255typedef int __attribute__((vector_size (16))) t56_v4i; 256typedef double __attribute__((vector_size (16))) t56_v2d; 257typedef int __attribute__((vector_size (32))) t56_v8i; 258typedef double __attribute__((vector_size (32))) t56_v4d; 259 260struct s56_0 { char a; }; 261struct s56_1 { t56_v2i a; }; 262struct s56_2 { t56_v1d a; }; 263struct s56_3 { t56_v4i a; }; 264struct s56_4 { t56_v2d a; }; 265struct s56_5 { t56_v8i a; }; 266struct s56_6 { t56_v4d a; }; 267 268void 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); 278} 279