Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / aarch64-aapcs-zerolength-bitfield.cpp
blob8b403fad69cfd92f5489af332ace5fd176d9b457
1 // REQUIRES: aarch64-registered-target
2 // RUN: %clang_cc1 -triple aarch64-linux-gnu -x c++ -std=c++1z %s -verify
3 // expected-no-diagnostics
5 #include <stddef.h>
7 struct t1
9 int foo : 1;
10 char : 0;
11 char bar;
14 static_assert(offsetof(struct t1, bar) == 1);
15 static_assert(sizeof(struct t1) == 4);
17 struct t2
19 int foo : 1;
20 short : 0;
21 char bar;
23 static_assert(offsetof(struct t2, bar) == 2);
24 static_assert(sizeof(struct t2) == 4);
26 struct t3
28 int foo : 1;
29 int : 0;
30 char bar;
32 static_assert(offsetof(struct t3, bar) == 4);
33 static_assert(sizeof(struct t3) == 8);
35 struct t4
37 int foo : 1;
38 long : 0;
39 char bar;
41 static_assert(offsetof(struct t4, bar) == 8);
42 static_assert(sizeof(struct t4) == 16);
44 struct t5
46 int foo : 1;
47 long long : 0;
48 char bar;
50 static_assert(offsetof(struct t5, bar) == 8);
51 static_assert(sizeof(struct t5) == 16);
53 struct t6
55 int foo : 1;
56 char : 0;
57 char bar : 1;
58 char bar2;
60 static_assert(offsetof(struct t6, bar2) == 2);
61 static_assert(sizeof(struct t6) == 4);
63 struct t7
65 int foo : 1;
66 short : 0;
67 char bar1 : 1;
68 char bar2;
70 static_assert(offsetof(struct t7, bar2) == 3);
71 static_assert(sizeof(struct t7) == 4);
73 struct t8
75 int foo : 1;
76 int : 0;
77 char bar1 : 1;
78 char bar2;
80 static_assert(offsetof(struct t8, bar2) == 5);
81 static_assert(sizeof(struct t8) == 8);
83 struct t9
85 int foo : 1;
86 long : 0;
87 char bar1 : 1;
88 char bar2;
90 static_assert(offsetof(struct t9, bar2) == 9);
91 static_assert(sizeof(struct t9) == 16);
93 struct t10
95 int foo : 1;
96 long long : 0;
97 char bar1 : 1;
98 char bar2;
100 static_assert(offsetof(struct t10, bar2) == 9);
101 static_assert(sizeof(struct t10) == 16);
103 struct t11
105 int foo : 1;
106 long long : 0;
107 char : 0;
108 char bar1 : 1;
109 char bar2;
111 static_assert(offsetof(struct t11, bar2) == 9);
112 static_assert(sizeof(struct t11) == 16);
114 struct t12
116 int foo : 1;
117 char : 0;
118 long long : 0;
119 char : 0;
120 char bar;
122 static_assert(offsetof(struct t12, bar) == 8);
123 static_assert(sizeof(struct t12) == 16);
125 struct t13
127 char foo;
128 long : 0;
129 char bar;
131 static_assert(offsetof(struct t13, bar) == 8);
132 static_assert(sizeof(struct t13) == 16);
134 struct t14
136 char foo1;
137 int : 0;
138 char foo2 : 1;
139 short foo3 : 16;
140 char : 0;
141 short foo4 : 16;
142 char bar1;
143 int : 0;
144 char bar2;
146 static_assert(offsetof(struct t14, bar1) == 10);
147 static_assert(offsetof(struct t14, bar2) == 12);
148 static_assert(sizeof(struct t14) == 16);
150 struct t15
152 char foo;
153 char : 0;
154 int : 0;
155 char bar;
156 long : 0;
157 char : 0;
159 static_assert(offsetof(struct t15, bar) == 4);
160 static_assert(sizeof(struct t15) == 8);
162 struct t16
164 long : 0;
165 char bar;
167 static_assert(offsetof(struct t16, bar) == 0);
168 static_assert(sizeof(struct t16) == 8);
170 struct t17
172 char foo;
173 long : 0;
174 long : 0;
175 char : 0;
176 char bar;
178 static_assert(offsetof(struct t17, bar) == 8);
179 static_assert(sizeof(struct t17) == 16);
181 struct t18
183 long : 0;
184 long : 0;
185 char : 0;
187 static_assert(sizeof(struct t18) == 8);
189 struct t19
191 char foo1;
192 long foo2 : 1;
193 char : 0;
194 long foo3 : 32;
195 char bar;
197 static_assert(offsetof(struct t19, bar) == 6);
198 static_assert(sizeof(struct t19) == 8);
200 struct t20
202 short : 0;
203 int foo : 1;
204 long : 0;
205 char bar;
207 static_assert(offsetof(struct t20, bar) == 8);
208 static_assert(sizeof(struct t20) == 16);
210 struct t21
212 short : 0;
213 int foo1 : 1;
214 char : 0;
215 int foo2 : 16;
216 long : 0;
217 char bar1;
218 int bar2;
219 long bar3;
220 char foo3 : 8;
221 char : 0;
222 long : 0;
223 int foo4 : 32;
224 short foo5: 1;
225 long bar4;
226 short foo6: 16;
227 short foo7: 16;
228 short foo8: 16;
230 static_assert(offsetof(struct t21, bar1) == 8);
231 static_assert(offsetof(struct t21, bar2) == 12);
232 static_assert(offsetof(struct t21, bar3) == 16);
233 static_assert(offsetof(struct t21, bar4) == 40);
234 static_assert(sizeof(struct t21) == 56);
236 // The rules also apply to anonymous bitfields with non-zero length.
237 struct t22
239 char foo;
240 short :2;
241 char bar;
243 static_assert(alignof(struct t22) == 2);
244 static_assert(offsetof(struct t22, bar) == 2);
246 int main() {
247 return 0;