Debian Codegraph @

clang/test/CodeGen/aapcs-align.cpp

raw
1 // REQUIRES: arm-registered-target
2 // RUN: %clang_cc1 -triple arm-none-none-eabi \
3 // RUN: -O2 \
4 // RUN: -target-cpu cortex-a8 \
5 // RUN: -emit-llvm -o - %s | FileCheck %s
6
7 extern "C" {
8
9 // CHECK: @sizeof_OverSizedBitfield ={{.*}} global i32 8
10 // CHECK: @alignof_OverSizedBitfield ={{.*}} global i32 8
11 // CHECK: @sizeof_VeryOverSizedBitfield ={{.*}} global i32 16
12 // CHECK: @alignof_VeryOverSizedBitfield ={{.*}} global i32 8
13
14 // Base case, nothing interesting.
15 struct S {
16 int x, y;
17 };
18
19 void f0(int, S);
20 void f0m(int, int, int, int, int, S);
21 void g0() {
22 S s = {6, 7};
23 f0(1, s);
24 f0m(1, 2, 3, 4, 5, s);
25 }
26 // CHECK: define{{.*}} void @g0
27 // CHECK: call void @f0(i32 noundef 1, [2 x i32] [i32 6, i32 7]
28 // CHECK: call void @f0m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [2 x i32] [i32 6, i32 7]
29 // CHECK: declare void @f0(i32 noundef, [2 x i32])
30 // CHECK: declare void @f0m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [2 x i32])
31
32 // Aligned struct, passed according to its natural alignment.
33 struct __attribute__((aligned(8))) S8 {
34 int x, y;
35 } s8;
36
37 void f1(int, S8);
38 void f1m(int, int, int, int, int, S8);
39 void g1() {
40 S8 s = {6, 7};
41 f1(1, s);
42 f1m(1, 2, 3, 4, 5, s);
43 }
44 // CHECK: define{{.*}} void @g1
45 // CHECK: call void @f1(i32 noundef 1, [2 x i32] [i32 6, i32 7]
46 // CHECK: call void @f1m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [2 x i32] [i32 6, i32 7]
47 // CHECK: declare void @f1(i32 noundef, [2 x i32])
48 // CHECK: declare void @f1m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [2 x i32])
49
50 // Aligned struct, passed according to its natural alignment.
51 struct alignas(16) S16 {
52 int x, y;
53 };
54
55 extern "C" void f2(int, S16);
56 extern "C" void f2m(int, int, int, int, int, S16);
57
58 void g2() {
59 S16 s = {6, 7};
60 f2(1, s);
61 f2m(1, 2, 3, 4, 5, s);
62 }
63 // CHECK: define{{.*}} void @g2
64 // CHECK: call void @f2(i32 noundef 1, [4 x i32] [i32 6, i32 7
65 // CHECK: call void @f2m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [4 x i32] [i32 6, i32 7
66 // CHECK: declare void @f2(i32 noundef, [4 x i32])
67 // CHECK: declare void @f2m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [4 x i32])
68
69 // Increased natural alignment.
70 struct SF8 {
71 int x __attribute__((aligned(8)));
72 int y;
73 };
74
75 void f3(int, SF8);
76 void f3m(int, int, int, int, int, SF8);
77 void g3() {
78 SF8 s = {6, 7};
79 f3(1, s);
80 f3m(1, 2, 3, 4, 5, s);
81 }
82 // CHECK: define{{.*}} void @g3
83 // CHECK: call void @f3(i32 noundef 1, [1 x i64] [i64 30064771078]
84 // CHECK: call void @f3m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [1 x i64] [i64 30064771078]
85 // CHECK: declare void @f3(i32 noundef, [1 x i64])
86 // CHECK: declare void @f3m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [1 x i64])
87
88 // Increased natural alignment, capped to 8 though.
89 struct SF16 {
90 int x;
91 int y alignas(16);
92 int z, a, b, c, d, e, f, g, h, i, j, k;
93 };
94
95 void f4(int, SF16);
96 void f4m(int, int, int, int, int, SF16);
97 void g4() {
98 SF16 s = {6, 7};
99 f4(1, s);
100 f4m(1, 2, 3, 4, 5, s);
101 }
102 // CHECK: define{{.*}} void @g4
103 // CHECK: call void @f4(i32 noundef 1, ptr noundef nonnull byval(%struct.SF16) align 8
104 // CHECK: call void @f4m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, ptr noundef nonnull byval(%struct.SF16) align 8
105 // CHECK: declare void @f4(i32 noundef, ptr noundef byval(%struct.SF16) align 8)
106 // CHECK: declare void @f4m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef byval(%struct.SF16) align 8)
107
108 // Packed structure.
109 struct __attribute__((packed)) P {
110 int x;
111 long long u;
112 };
113
114 void f5(int, P);
115 void f5m(int, int, int, int, int, P);
116 void g5() {
117 P s = {6, 7};
118 f5(1, s);
119 f5m(1, 2, 3, 4, 5, s);
120 }
121 // CHECK: define{{.*}} void @g5
122 // CHECK: call void @f5(i32 noundef 1, [3 x i32] [i32 6, i32 7, i32 0])
123 // CHECK: call void @f5m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [3 x i32] [i32 6, i32 7, i32 0])
124 // CHECK: declare void @f5(i32 noundef, [3 x i32])
125 // CHECK: declare void @f5m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [3 x i32])
126
127
128 // Packed and aligned, alignement causes padding at the end.
129 struct __attribute__((packed, aligned(8))) P8 {
130 int x;
131 long long u;
132 };
133
134 void f6(int, P8);
135 void f6m(int, int, int, int, int, P8);
136 void g6() {
137 P8 s = {6, 7};
138 f6(1, s);
139 f6m(1, 2, 3, 4, 5, s);
140 }
141 // CHECK: define{{.*}} void @g6
142 // CHECK: call void @f6(i32 noundef 1, [4 x i32] [i32 6, i32 7, i32 0, i32 undef])
143 // CHECK: call void @f6m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [4 x i32] [i32 6, i32 7, i32 0, i32 undef])
144 // CHECK: declare void @f6(i32 noundef, [4 x i32])
145 // CHECK: declare void @f6m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [4 x i32])
146
147 // Over-sized bitfield, which results in a 64-bit container type, so 64-bit
148 // alignment.
149 struct OverSizedBitfield {
150 int x : 64;
151 };
152
153 unsigned sizeof_OverSizedBitfield = sizeof(OverSizedBitfield);
154 unsigned alignof_OverSizedBitfield = alignof(OverSizedBitfield);
155
156 // CHECK: define{{.*}} void @g7
157 // CHECK: call void @f7(i32 noundef 1, [1 x i64] [i64 42])
158 // CHECK: declare void @f7(i32 noundef, [1 x i64])
159 void f7(int a, OverSizedBitfield b);
160 void g7() {
161 OverSizedBitfield s = {42};
162 f7(1, s);
163 }
164
165 // There are no 128-bit fundamental data types defined by AAPCS32, so this gets
166 // a 64-bit container plus 64 bits of padding, giving it a size of 16 bytes and
167 // alignment of 8 bytes.
168 struct VeryOverSizedBitfield {
169 int x : 128;
170 };
171
172 unsigned sizeof_VeryOverSizedBitfield = sizeof(VeryOverSizedBitfield);
173 unsigned alignof_VeryOverSizedBitfield = alignof(VeryOverSizedBitfield);
174
175 // CHECK: define{{.*}} void @g8
176 // CHECK: call void @f8(i32 noundef 1, [2 x i64] [i64 42, i64 0])
177 // CHECK: declare void @f8(i32 noundef, [2 x i64])
178 void f8(int a, VeryOverSizedBitfield b);
179 void g8() {
180 VeryOverSizedBitfield s = {42};
181 f8(1, s);
182 }
183
184 }