1// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -w -o - %s | FileCheck -check-prefix=PCS %s
2
3// Sign extension is performed by the callee on AArch64, which means
4// that we *shouldn't* tag arguments and returns with their extension.
5
6// PCS: define i8 @f0(i16 %a)
7char f0(short a) {
8  return a;
9}
10
11// PCS: define [1 x i64] @f1()
12struct s1 { char f0; };
13struct s1 f1(void) {}
14
15// PCS: define [1 x i64] @f2()
16struct s2 { short f0; };
17struct s2 f2(void) {}
18
19// PCS: define [1 x i64] @f3()
20struct s3 { int f0; };
21struct s3 f3(void) {}
22
23// PCS: define [1 x i64] @f4()
24struct s4 { struct s4_0 { int f0; } f0; };
25struct s4 f4(void) {}
26
27// PCS: define [1 x i64] @f5()
28struct s5 { struct { } f0; int f1; };
29struct s5 f5(void) {}
30
31// PCS: define  [1 x i64] @f6()
32struct s6 { int f0[1]; };
33struct s6 f6(void) {}
34
35// PCS: define void @f7()
36struct s7 { struct { int : 0; } f0; };
37struct s7 f7(void) {}
38
39// PCS: define  void @f8()
40struct s8 { struct { int : 0; } f0[1]; };
41struct s8 f8(void) {}
42
43// PCS: define [1 x i64] @f9()
44struct s9 { long f0; int : 0; };
45struct s9 f9(void) {}
46
47// PCS: define [1 x i64] @f10()
48struct s10 { long f0; int : 0; int : 0; };
49struct s10 f10(void) {}
50
51// PCS: define [1 x i64] @f11()
52struct s11 { int : 0; long f0; };
53struct s11 f11(void) {}
54
55// PCS: define [1 x i64] @f12()
56union u12 { char f0; short f1; int f2; long f3; };
57union u12 f12(void) {}
58
59// PCS: define %struct.s13 @f13()
60struct s13 { float f0; };
61struct s13 f13(void) {}
62
63// PCS: define %union.u14 @f14()
64union u14 { float f0; };
65union u14 f14(void) {}
66
67// PCS: define void @f15()
68void f15(struct s7 a0) {}
69
70// PCS: define void @f16()
71void f16(struct s8 a0) {}
72
73// PCS: define [1 x i64] @f17()
74struct s17 { short f0 : 13; char f1 : 4; };
75struct s17 f17(void) {}
76
77// PCS: define [1 x i64] @f18()
78struct s18 { short f0; char f1 : 4; };
79struct s18 f18(void) {}
80
81// PCS: define [1 x i64] @f19()
82struct s19 { long f0; struct s8 f1; };
83struct s19 f19(void) {}
84
85// PCS: define [1 x i64] @f20()
86struct s20 { struct s8 f1; long f0; };
87struct s20 f20(void) {}
88
89// PCS: define [1 x i64] @f21()
90struct s21 { struct {} f1; long f0 : 4; };
91struct s21 f21(void) {}
92
93// PCS: define { float, float } @f22()
94// PCS: define { double, double } @f23(
95_Complex float      f22(void) {}
96_Complex double     f23(void) {}
97
98// PCS: define [1 x i64] @f24()
99struct s24 { _Complex char f0; };
100struct s24 f24() {}
101
102// PCS: define [1 x i64] @f25()
103struct s25 { _Complex short f0; };
104struct s25 f25() {}
105
106// PCS: define [1 x i64] @f26()
107struct s26 { _Complex int f0; };
108struct s26 f26() {}
109
110// PCS: define [2 x i64] @f27()
111struct s27 { _Complex long f0; };
112struct s27 f27() {}
113
114// PCS: define void @f28(i8 %a, i16 %b, i32 %c, i64 %d, float %e, double %f)
115void f28(char a, short b, int c, long d, float e, double f) {}
116
117// PCS: define void @f29([2 x i64] %a
118struct s29 { int arr[4]; };
119void f29(struct s29 a) {}
120
121// PCS: define void @f30(%struct.s30* %a)
122struct s30 { int arr[4]; char c;};
123void f30(struct s30 a) {}
124
125// PCS: define void @f31([4 x double] %a
126struct s31 { double arr[4]; };
127void f31(struct s31 a) {}
128
129// PCS: define void @f32(%struct.s32* %a)
130struct s32 { float arr[5]; };
131void f32(struct s32 a) {}
132
133// Not the only solution, but it *is* an HFA.
134// PCS: define void @f33([3 x float] %a.coerce0, float %a.coerce1)
135struct s33 { float arr[3]; float a; };
136void f33(struct s33 a) {}
137
138// PCS: define void @f34(%struct.s34* noalias sret
139struct s34 { int a[4]; char b };
140struct s34 f34(void) {}
141
142// PCS: define void @f35()
143struct s35 {};
144void f35(struct s35 a) {}
145
146// Check padding is added:
147// PCS: @f36(i32 %x0, i32 %x1, i32 %x2, i32 %x3, i32 %x4, i32 %x5, i32 %x6, [1 x i64], %struct.s36* byval align 8 %stacked)
148struct s36 { long a, b; };
149void f36(int x0, int x1, int x2, int x3, int x4, int x5, int x6, struct s36 stacked) {}
150
151// But only once:
152// PCS: @f37(i32 %x0, i32 %x1, i32 %x2, i32 %x3, i32 %x4, i32 %x5, i32 %x6, [1 x i64], %struct.s37* byval align 8 %stacked, %struct.s37* byval align 8 %stacked2)
153struct s37 { long a, b; };
154void f37(int x0, int x1, int x2, int x3, int x4, int x5, int x6, struct s37 stacked, struct s37 stacked2) {}
155
156// Check for HFA padding args. Also, they should not end up on the stack in a
157// way which will have holes in when lowered further by LLVM. In particular [3 x
158// float] would be unacceptable.
159
160// PCS: @f38(float %s0, double %d1, float %s2, float %s3, float %s4, float %s5, [2 x float], %struct.s38* byval align 4 %stacked)
161struct s38 { float a, b, c; };
162void f38(float s0, double d1, float s2, float s3, float s4, float s5, struct s38 stacked) {}
163
164// Check both VFP and integer arguments are padded (also that pointers and enums
165// get counted as integer types correctly).
166struct s39_int { long a, b; };
167struct s39_float { float a, b, c, d; };
168enum s39_enum { Val1, Val2 };
169// PCS: @f39(float %s0, i32 %x0, float %s1, i32* %x1, float %s2, i32 %x2, float %s3, float %s4, i32 %x3, [3 x float], %struct.s39_float* byval align 4 %stacked, i32 %x4, i32 %x5, i32 %x6, [1 x i64], %struct.s39_int* byval align 8 %stacked2)
170void f39(float s0, int x0, float s1, int *x1, float s2, enum s39_enum x2, float s3, float s4,
171         int x3, struct s39_float stacked, int x4, int x5, int x6,
172         struct s39_int stacked2) {}
173
174struct s40 { __int128 a; };
175// PCS: @f40(i32 %x0, [1 x i128] %x2_3.coerce, i32 %x4, i32 %x5, i32 %x6, [1 x i64], %struct.s40* byval align 16 %stacked)
176void f40(int x0, struct s40 x2_3, int x4, int x5, int x6, struct s40 stacked) {}
177
178// Checking: __int128 will get properly aligned type, with padding so big struct doesn't use x7.
179struct s41 { int arr[5]; };
180// PCS: @f41(i32 %x0, i32 %x1, i32 %x2, i32 %x3, i32 %x4, i32 %x5, i32 %x6, [1 x i64], i128* byval align 16, %struct.s41* %stacked2)
181int f41(int x0, int x1, int x2, int x3, int x4, int x5, int x6, __int128 stacked, struct s41 stacked2) {}
182
183// Checking: __int128 needing to be aligned in registers will consume correct
184// number. Previously padding was inserted before "stacked" because x6_7 was
185// "allocated" to x5 and x6 by clang.
186// PCS: @f42(i32 %x0, i32 %x1, i32 %x2, i32 %x3, i32 %x4, i128 %x6_7, i128* byval align 16)
187void f42(int x0, int x1, int x2, int x3, int x4, __int128 x6_7, __int128 stacked) {}
188
189// Checking: __fp16 is extended to double when calling variadic functions
190void variadic(int a, ...);
191void f43(__fp16 *in) {
192  variadic(42, *in);
193// CHECK: call void @variadic(i32 42, double
194}
195