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