Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / AArch64 / ABI-align-packed-assembly.c
blobd6e96a6004f679a4de0c8233862a5e345c2cf30d
1 // REQUIRES: aarch64-registered-target
2 // RUN: %clang_cc1 -triple aarch64 -target-feature +neon -S -O2 -o - %s | FileCheck %s
3 #include <stdarg.h>
4 #include <arm_neon.h>
6 // natural alignment 16, adjusted alignment 16
7 // expected alignment of copy on callee stack: 16
8 struct non_packed_struct {
9 uint16x8_t M0; // member alignment 16
12 // natural alignment 1, adjusted alignment 1
13 // expected alignment of copy on callee stack: 8
14 struct __attribute((packed)) packed_struct {
15 uint16x8_t M0; // member alignment 1, because the field is packed when the struct is packed
18 // natural alignment 1, adjusted alignment 1
19 // expected alignment of copy on callee stack: 8
20 struct packed_member {
21 uint16x8_t M0 __attribute((packed)); // member alignment 1
24 // natural alignment 16, adjusted alignment 16 since __attribute((aligned (n))) sets the minimum alignment
25 // expected alignment of copy on callee stack: 16
26 struct __attribute((aligned (8))) aligned_struct_8 {
27 uint16x8_t M0; // member alignment 16
30 // natural alignment 16, adjusted alignment 16
31 // expected alignment of copy on callee stack: 16
32 struct aligned_member_8 {
33 uint16x8_t M0 __attribute((aligned (8))); // member alignment 16 since __attribute((aligned (n))) sets the minimum alignment
36 // natural alignment 8, adjusted alignment 8
37 // expected alignment of copy on callee stack: 8
38 #pragma pack(8)
39 struct pragma_packed_struct_8 {
40 uint16x8_t M0; // member alignment 8 because the struct is subject to packed(8)
43 // natural alignment 4, adjusted alignment 4
44 // expected alignment of copy on callee stack: 8
45 #pragma pack(4)
46 struct pragma_packed_struct_4 {
47 uint16x8_t M0; // member alignment 4 because the struct is subject to packed(4)
50 double gd;
51 void init(int, ...);
53 struct non_packed_struct gs_non_packed_struct;
55 __attribute__((noinline)) void named_arg_non_packed_struct(double d0, double d1, double d2, double d3,
56 double d4, double d5, double d6, double d7,
57 double d8, struct non_packed_struct s_non_packed_struct) {
58 // CHECK: ldr q1, [sp, #16]
59 gd = d8;
60 gs_non_packed_struct = s_non_packed_struct;
63 void variadic_non_packed_struct(double d0, double d1, double d2, double d3,
64 double d4, double d5, double d6, double d7,
65 double d8, ...) {
66 va_list vl;
67 va_start(vl, d8);
68 struct non_packed_struct on_callee_stack;
69 on_callee_stack = va_arg(vl, struct non_packed_struct);
72 void test_non_packed_struct() {
73 struct non_packed_struct s_non_packed_struct;
74 init(1, &s_non_packed_struct);
76 // CHECK: mov x8, #4611686018427387904 // =0x4000000000000000
77 // CHECK: str x8, [sp]
78 // CHECK: str q0, [sp, #16]
79 named_arg_non_packed_struct(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_non_packed_struct);
80 // CHECK: str q0, [sp, #16]
81 variadic_non_packed_struct(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_non_packed_struct);
84 struct packed_struct gs_packed_struct;
86 __attribute__((noinline)) void named_arg_packed_struct(double d0, double d1, double d2, double d3,
87 double d4, double d5, double d6, double d7,
88 double d8, struct packed_struct s_packed_struct) {
89 // CHECK: ldur q1, [sp, #8]
90 gd = d8;
91 gs_packed_struct = s_packed_struct;
94 void variadic_packed_struct(double d0, double d1, double d2, double d3,
95 double d4, double d5, double d6, double d7,
96 double d8, ...) {
97 va_list vl;
98 va_start(vl, d8);
99 struct packed_struct on_callee_stack;
100 on_callee_stack = va_arg(vl, struct packed_struct);
103 void test_packed_struct() {
104 struct packed_struct s_packed_struct;
105 init(1, &s_packed_struct);
107 // CHECK: mov x8, #4611686018427387904 // =0x4000000000000000
108 // CHECK: str x8, [sp]
109 // CHECK: stur q0, [sp, #8]
110 named_arg_packed_struct(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_packed_struct);
111 // CHECK: stur q0, [sp, #8]
112 variadic_packed_struct(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_packed_struct);
115 struct packed_member gs_packed_member;
117 __attribute__((noinline)) void named_arg_packed_member(double d0, double d1, double d2, double d3,
118 double d4, double d5, double d6, double d7,
119 double d8, struct packed_member s_packed_member) {
120 // CHECK: ldur q1, [sp, #8]
121 gd = d8;
122 gs_packed_member = s_packed_member;
125 void variadic_packed_member(double d0, double d1, double d2, double d3,
126 double d4, double d5, double d6, double d7,
127 double d8, ...) {
128 va_list vl;
129 va_start(vl, d8);
130 struct packed_member on_callee_stack;
131 on_callee_stack = va_arg(vl, struct packed_member);
134 void test_packed_member() {
135 struct packed_member s_packed_member;
136 init(1, &s_packed_member);
138 // CHECK: mov x8, #4611686018427387904 // =0x4000000000000000
139 // CHECK: str x8, [sp]
140 // CHECK: stur q0, [sp, #8]
141 named_arg_packed_member(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_packed_member);
142 // CHECK: stur q0, [sp, #8]
143 variadic_packed_member(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_packed_member);
146 struct aligned_struct_8 gs_aligned_struct_8;
148 __attribute__((noinline)) void named_arg_aligned_struct_8(double d0, double d1, double d2, double d3,
149 double d4, double d5, double d6, double d7,
150 double d8, struct aligned_struct_8 s_aligned_struct_8) {
151 // CHECK: ldr q1, [sp, #16]
152 gd = d8;
153 gs_aligned_struct_8 = s_aligned_struct_8;
156 void variadic_aligned_struct_8(double d0, double d1, double d2, double d3,
157 double d4, double d5, double d6, double d7,
158 double d8, ...) {
159 va_list vl;
160 va_start(vl, d8);
161 struct aligned_struct_8 on_callee_stack;
162 on_callee_stack = va_arg(vl, struct aligned_struct_8);
165 void test_aligned_struct_8() {
166 struct aligned_struct_8 s_aligned_struct_8;
167 init(1, &s_aligned_struct_8);
169 // CHECK: mov x8, #4611686018427387904 // =0x4000000000000000
170 // CHECK: str x8, [sp]
171 // CHECK: str q0, [sp, #16]
172 named_arg_aligned_struct_8(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_aligned_struct_8);
173 // CHECK: str q0, [sp, #16]
174 variadic_aligned_struct_8(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_aligned_struct_8);
177 struct aligned_member_8 gs_aligned_member_8;
179 __attribute__((noinline)) void named_arg_aligned_member_8(double d0, double d1, double d2, double d3,
180 double d4, double d5, double d6, double d7,
181 double d8, struct aligned_member_8 s_aligned_member_8) {
182 // CHECK: ldr q1, [sp, #16]
183 gd = d8;
184 gs_aligned_member_8 = s_aligned_member_8;
187 void variadic_aligned_member_8(double d0, double d1, double d2, double d3,
188 double d4, double d5, double d6, double d7,
189 double d8, ...) {
190 va_list vl;
191 va_start(vl, d8);
192 struct aligned_member_8 on_callee_stack;
193 on_callee_stack = va_arg(vl, struct aligned_member_8);
196 void test_aligned_member_8() {
197 struct aligned_member_8 s_aligned_member_8;
198 init(1, &s_aligned_member_8);
200 // CHECK: mov x8, #4611686018427387904 // =0x4000000000000000
201 // CHECK: str x8, [sp]
202 // CHECK: str q0, [sp, #16]
203 named_arg_aligned_member_8(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_aligned_member_8);
204 // CHECK: str q0, [sp, #16]
205 variadic_aligned_member_8(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_aligned_member_8);
208 struct pragma_packed_struct_8 gs_pragma_packed_struct_8;
210 __attribute__((noinline)) void named_arg_pragma_packed_struct_8(double d0, double d1, double d2, double d3,
211 double d4, double d5, double d6, double d7,
212 double d8, struct pragma_packed_struct_8 s_pragma_packed_struct_8) {
213 // CHECK: ldur q1, [sp, #8]
214 gd = d8;
215 gs_pragma_packed_struct_8 = s_pragma_packed_struct_8;
218 void variadic_pragma_packed_struct_8(double d0, double d1, double d2, double d3,
219 double d4, double d5, double d6, double d7,
220 double d8, ...) {
221 va_list vl;
222 va_start(vl, d8);
223 struct pragma_packed_struct_8 on_callee_stack;
224 on_callee_stack = va_arg(vl, struct pragma_packed_struct_8);
227 void test_pragma_packed_struct_8() {
228 struct pragma_packed_struct_8 s_pragma_packed_struct_8;
229 init(1, &s_pragma_packed_struct_8);
231 // CHECK: mov x8, #4611686018427387904 // =0x4000000000000000
232 // CHECK: str x8, [sp]
233 // CHECK: stur q0, [sp, #8]
234 named_arg_pragma_packed_struct_8(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_pragma_packed_struct_8);
235 // CHECK: stur q0, [sp, #8]
236 variadic_pragma_packed_struct_8(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_pragma_packed_struct_8);
239 struct pragma_packed_struct_4 gs_pragma_packed_struct_4;
241 __attribute__((noinline)) void named_arg_pragma_packed_struct_4(double d0, double d1, double d2, double d3,
242 double d4, double d5, double d6, double d7,
243 double d8, struct pragma_packed_struct_4 s_pragma_packed_struct_4) {
244 // CHECK: ldur q1, [sp, #8]
245 gd = d8;
246 gs_pragma_packed_struct_4 = s_pragma_packed_struct_4;
249 void variadic_pragma_packed_struct_4(double d0, double d1, double d2, double d3,
250 double d4, double d5, double d6, double d7,
251 double d8, ...) {
252 va_list vl;
253 va_start(vl, d8);
254 struct pragma_packed_struct_4 on_callee_stack;
255 on_callee_stack = va_arg(vl, struct pragma_packed_struct_4);
258 void test_pragma_packed_struct_4() {
259 struct pragma_packed_struct_4 s_pragma_packed_struct_4;
260 init(1, &s_pragma_packed_struct_4);
262 // CHECK: mov x8, #4611686018427387904 // =0x4000000000000000
263 // CHECK: str x8, [sp]
264 // CHECK: stur q0, [sp, #8]
265 named_arg_pragma_packed_struct_4(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_pragma_packed_struct_4);
266 // CHECK: stur q0, [sp, #8]
267 variadic_pragma_packed_struct_4(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, s_pragma_packed_struct_4);