xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/arm-apcs-zerolength-bitfield.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // REQUIRES: arm-registered-target
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -target-abi apcs-gnu -triple armv7-apple-darwin10 %s -verify
3*f4a2713aSLionel Sambuc // expected-no-diagnostics
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // Note: gcc forces the alignment to 4 bytes, regardless of the type of the
6*f4a2713aSLionel Sambuc // zero length bitfield.
7*f4a2713aSLionel Sambuc // rdar://9859156
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc #include <stddef.h>
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc struct t1
12*f4a2713aSLionel Sambuc {
13*f4a2713aSLionel Sambuc   int foo : 1;
14*f4a2713aSLionel Sambuc   char : 0;
15*f4a2713aSLionel Sambuc   char bar;
16*f4a2713aSLionel Sambuc };
17*f4a2713aSLionel Sambuc static int arr1_offset[(offsetof(struct t1, bar) == 4) ? 0 : -1];
18*f4a2713aSLionel Sambuc static int arr1_sizeof[(sizeof(struct t1) == 8) ? 0 : -1];
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc struct t2
21*f4a2713aSLionel Sambuc {
22*f4a2713aSLionel Sambuc   int foo : 1;
23*f4a2713aSLionel Sambuc   short : 0;
24*f4a2713aSLionel Sambuc   char bar;
25*f4a2713aSLionel Sambuc };
26*f4a2713aSLionel Sambuc static int arr2_offset[(offsetof(struct t2, bar) == 4) ? 0 : -1];
27*f4a2713aSLionel Sambuc static int arr2_sizeof[(sizeof(struct t2) == 8) ? 0 : -1];
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc struct t3
30*f4a2713aSLionel Sambuc {
31*f4a2713aSLionel Sambuc   int foo : 1;
32*f4a2713aSLionel Sambuc   int : 0;
33*f4a2713aSLionel Sambuc   char bar;
34*f4a2713aSLionel Sambuc };
35*f4a2713aSLionel Sambuc static int arr3_offset[(offsetof(struct t3, bar) == 4) ? 0 : -1];
36*f4a2713aSLionel Sambuc static int arr3_sizeof[(sizeof(struct t3) == 8) ? 0 : -1];
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc struct t4
39*f4a2713aSLionel Sambuc {
40*f4a2713aSLionel Sambuc   int foo : 1;
41*f4a2713aSLionel Sambuc   long : 0;
42*f4a2713aSLionel Sambuc   char bar;
43*f4a2713aSLionel Sambuc };
44*f4a2713aSLionel Sambuc static int arr4_offset[(offsetof(struct t4, bar) == 4) ? 0 : -1];
45*f4a2713aSLionel Sambuc static int arr4_sizeof[(sizeof(struct t4) == 8) ? 0 : -1];
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc struct t5
48*f4a2713aSLionel Sambuc {
49*f4a2713aSLionel Sambuc   int foo : 1;
50*f4a2713aSLionel Sambuc   long long : 0;
51*f4a2713aSLionel Sambuc   char bar;
52*f4a2713aSLionel Sambuc };
53*f4a2713aSLionel Sambuc static int arr5_offset[(offsetof(struct t5, bar) == 4) ? 0 : -1];
54*f4a2713aSLionel Sambuc static int arr5_sizeof[(sizeof(struct t5) == 8) ? 0 : -1];
55*f4a2713aSLionel Sambuc 
56*f4a2713aSLionel Sambuc struct t6
57*f4a2713aSLionel Sambuc {
58*f4a2713aSLionel Sambuc   int foo : 1;
59*f4a2713aSLionel Sambuc   char : 0;
60*f4a2713aSLionel Sambuc   char bar : 1;
61*f4a2713aSLionel Sambuc   char bar2;
62*f4a2713aSLionel Sambuc };
63*f4a2713aSLionel Sambuc static int arr6_offset[(offsetof(struct t6, bar2) == 5) ? 0 : -1];
64*f4a2713aSLionel Sambuc static int arr6_sizeof[(sizeof(struct t6) == 8) ? 0 : -1];
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc struct t7
67*f4a2713aSLionel Sambuc {
68*f4a2713aSLionel Sambuc   int foo : 1;
69*f4a2713aSLionel Sambuc   short : 0;
70*f4a2713aSLionel Sambuc   char bar1 : 1;
71*f4a2713aSLionel Sambuc   char bar2;
72*f4a2713aSLionel Sambuc };
73*f4a2713aSLionel Sambuc static int arr7_offset[(offsetof(struct t7, bar2) == 5) ? 0 : -1];
74*f4a2713aSLionel Sambuc static int arr7_sizeof[(sizeof(struct t7) == 8) ? 0 : -1];
75*f4a2713aSLionel Sambuc 
76*f4a2713aSLionel Sambuc struct t8
77*f4a2713aSLionel Sambuc {
78*f4a2713aSLionel Sambuc   int foo : 1;
79*f4a2713aSLionel Sambuc   int : 0;
80*f4a2713aSLionel Sambuc   char bar1 : 1;
81*f4a2713aSLionel Sambuc   char bar2;
82*f4a2713aSLionel Sambuc };
83*f4a2713aSLionel Sambuc static int arr8_offset[(offsetof(struct t8, bar2) == 5) ? 0 : -1];
84*f4a2713aSLionel Sambuc static int arr8_sizeof[(sizeof(struct t8) == 8) ? 0 : -1];
85*f4a2713aSLionel Sambuc 
86*f4a2713aSLionel Sambuc struct t9
87*f4a2713aSLionel Sambuc {
88*f4a2713aSLionel Sambuc   int foo : 1;
89*f4a2713aSLionel Sambuc   long : 0;
90*f4a2713aSLionel Sambuc   char bar1 : 1;
91*f4a2713aSLionel Sambuc   char bar2;
92*f4a2713aSLionel Sambuc };
93*f4a2713aSLionel Sambuc static int arr9_offset[(offsetof(struct t9, bar2) == 5) ? 0 : -1];
94*f4a2713aSLionel Sambuc static int arr9_sizeof[(sizeof(struct t9) == 8) ? 0 : -1];
95*f4a2713aSLionel Sambuc 
96*f4a2713aSLionel Sambuc struct t10
97*f4a2713aSLionel Sambuc {
98*f4a2713aSLionel Sambuc   int foo : 1;
99*f4a2713aSLionel Sambuc   long long : 0;
100*f4a2713aSLionel Sambuc   char bar1 : 1;
101*f4a2713aSLionel Sambuc   char bar2;
102*f4a2713aSLionel Sambuc };
103*f4a2713aSLionel Sambuc static int arr10_offset[(offsetof(struct t10, bar2) == 5) ? 0 : -1];
104*f4a2713aSLionel Sambuc static int arr10_sizeof[(sizeof(struct t10) == 8) ? 0 : -1];
105*f4a2713aSLionel Sambuc 
106*f4a2713aSLionel Sambuc struct t11
107*f4a2713aSLionel Sambuc {
108*f4a2713aSLionel Sambuc   int foo : 1;
109*f4a2713aSLionel Sambuc   long long : 0;
110*f4a2713aSLionel Sambuc   char : 0;
111*f4a2713aSLionel Sambuc   char bar1 : 1;
112*f4a2713aSLionel Sambuc   char bar2;
113*f4a2713aSLionel Sambuc };
114*f4a2713aSLionel Sambuc static int arr11_offset[(offsetof(struct t11, bar2) == 5) ? 0 : -1];
115*f4a2713aSLionel Sambuc static int arr11_sizeof[(sizeof(struct t11) == 8) ? 0 : -1];
116*f4a2713aSLionel Sambuc 
117*f4a2713aSLionel Sambuc struct t12
118*f4a2713aSLionel Sambuc {
119*f4a2713aSLionel Sambuc   int foo : 1;
120*f4a2713aSLionel Sambuc   char : 0;
121*f4a2713aSLionel Sambuc   long long : 0;
122*f4a2713aSLionel Sambuc   char : 0;
123*f4a2713aSLionel Sambuc   char bar;
124*f4a2713aSLionel Sambuc };
125*f4a2713aSLionel Sambuc static int arr12_offset[(offsetof(struct t12, bar) == 4) ? 0 : -1];
126*f4a2713aSLionel Sambuc static int arr12_sizeof[(sizeof(struct t12) == 8) ? 0 : -1];
127*f4a2713aSLionel Sambuc 
128*f4a2713aSLionel Sambuc struct t13
129*f4a2713aSLionel Sambuc {
130*f4a2713aSLionel Sambuc   char foo;
131*f4a2713aSLionel Sambuc   long : 0;
132*f4a2713aSLionel Sambuc   char bar;
133*f4a2713aSLionel Sambuc };
134*f4a2713aSLionel Sambuc static int arr13_offset[(offsetof(struct t13, bar) == 4) ? 0 : -1];
135*f4a2713aSLionel Sambuc static int arr13_sizeof[(sizeof(struct t13) == 8) ? 0 : -1];
136*f4a2713aSLionel Sambuc 
137*f4a2713aSLionel Sambuc struct t14
138*f4a2713aSLionel Sambuc {
139*f4a2713aSLionel Sambuc   char foo1;
140*f4a2713aSLionel Sambuc   int : 0;
141*f4a2713aSLionel Sambuc   char foo2 : 1;
142*f4a2713aSLionel Sambuc   short foo3 : 16;
143*f4a2713aSLionel Sambuc   char : 0;
144*f4a2713aSLionel Sambuc   short foo4 : 16;
145*f4a2713aSLionel Sambuc   char bar1;
146*f4a2713aSLionel Sambuc   int : 0;
147*f4a2713aSLionel Sambuc   char bar2;
148*f4a2713aSLionel Sambuc };
149*f4a2713aSLionel Sambuc static int arr14_bar1_offset[(offsetof(struct t14, bar1) == 10) ? 0 : -1];
150*f4a2713aSLionel Sambuc static int arr14_bar2_offset[(offsetof(struct t14, bar2) == 12) ? 0 : -1];
151*f4a2713aSLionel Sambuc static int arr14_sizeof[(sizeof(struct t14) == 16) ? 0 : -1];
152*f4a2713aSLionel Sambuc 
153*f4a2713aSLionel Sambuc struct t15
154*f4a2713aSLionel Sambuc {
155*f4a2713aSLionel Sambuc   char foo;
156*f4a2713aSLionel Sambuc   char : 0;
157*f4a2713aSLionel Sambuc   int : 0;
158*f4a2713aSLionel Sambuc   char bar;
159*f4a2713aSLionel Sambuc   long : 0;
160*f4a2713aSLionel Sambuc   char : 0;
161*f4a2713aSLionel Sambuc };
162*f4a2713aSLionel Sambuc static int arr15_offset[(offsetof(struct t15, bar) == 4) ? 0 : -1];
163*f4a2713aSLionel Sambuc static int arr15_sizeof[(sizeof(struct t15) == 8) ? 0 : -1];
164*f4a2713aSLionel Sambuc 
165*f4a2713aSLionel Sambuc struct t16
166*f4a2713aSLionel Sambuc {
167*f4a2713aSLionel Sambuc   long : 0;
168*f4a2713aSLionel Sambuc   char bar;
169*f4a2713aSLionel Sambuc };
170*f4a2713aSLionel Sambuc static int arr16_offset[(offsetof(struct t16, bar) == 0) ? 0 : -1];
171*f4a2713aSLionel Sambuc static int arr16_sizeof[(sizeof(struct t16) == 4) ? 0 : -1];
172*f4a2713aSLionel Sambuc 
173*f4a2713aSLionel Sambuc struct t17
174*f4a2713aSLionel Sambuc {
175*f4a2713aSLionel Sambuc   char foo;
176*f4a2713aSLionel Sambuc   long : 0;
177*f4a2713aSLionel Sambuc   long : 0;
178*f4a2713aSLionel Sambuc   char : 0;
179*f4a2713aSLionel Sambuc   char bar;
180*f4a2713aSLionel Sambuc };
181*f4a2713aSLionel Sambuc static int arr17_offset[(offsetof(struct t17, bar) == 4) ? 0 : -1];
182*f4a2713aSLionel Sambuc static int arr17_sizeof[(sizeof(struct t17) == 8) ? 0 : -1];
183*f4a2713aSLionel Sambuc 
184*f4a2713aSLionel Sambuc struct t18
185*f4a2713aSLionel Sambuc {
186*f4a2713aSLionel Sambuc   long : 0;
187*f4a2713aSLionel Sambuc   long : 0;
188*f4a2713aSLionel Sambuc   char : 0;
189*f4a2713aSLionel Sambuc };
190*f4a2713aSLionel Sambuc static int arr18_sizeof[(sizeof(struct t18) == 0) ? 0 : -1];
191*f4a2713aSLionel Sambuc 
192*f4a2713aSLionel Sambuc struct t19
193*f4a2713aSLionel Sambuc {
194*f4a2713aSLionel Sambuc   char foo1;
195*f4a2713aSLionel Sambuc   long foo2 : 1;
196*f4a2713aSLionel Sambuc   char : 0;
197*f4a2713aSLionel Sambuc   long foo3 : 32;
198*f4a2713aSLionel Sambuc   char bar;
199*f4a2713aSLionel Sambuc };
200*f4a2713aSLionel Sambuc static int arr19_offset[(offsetof(struct t19, bar) == 8) ? 0 : -1];
201*f4a2713aSLionel Sambuc static int arr19_sizeof[(sizeof(struct t19) == 12) ? 0 : -1];
202*f4a2713aSLionel Sambuc 
203*f4a2713aSLionel Sambuc struct t20
204*f4a2713aSLionel Sambuc {
205*f4a2713aSLionel Sambuc   short : 0;
206*f4a2713aSLionel Sambuc   int foo : 1;
207*f4a2713aSLionel Sambuc   long : 0;
208*f4a2713aSLionel Sambuc   char bar;
209*f4a2713aSLionel Sambuc };
210*f4a2713aSLionel Sambuc static int arr20_offset[(offsetof(struct t20, bar) == 4) ? 0 : -1];
211*f4a2713aSLionel Sambuc static int arr20_sizeof[(sizeof(struct t20) == 8) ? 0 : -1];
212*f4a2713aSLionel Sambuc 
213*f4a2713aSLionel Sambuc struct t21
214*f4a2713aSLionel Sambuc {
215*f4a2713aSLionel Sambuc   short : 0;
216*f4a2713aSLionel Sambuc   int foo1 : 1;
217*f4a2713aSLionel Sambuc   char : 0;
218*f4a2713aSLionel Sambuc   int foo2 : 16;
219*f4a2713aSLionel Sambuc   long : 0;
220*f4a2713aSLionel Sambuc   char bar1;
221*f4a2713aSLionel Sambuc   int bar2;
222*f4a2713aSLionel Sambuc   long bar3;
223*f4a2713aSLionel Sambuc   char foo3 : 8;
224*f4a2713aSLionel Sambuc   char : 0;
225*f4a2713aSLionel Sambuc   long : 0;
226*f4a2713aSLionel Sambuc   int foo4 : 32;
227*f4a2713aSLionel Sambuc   short foo5: 1;
228*f4a2713aSLionel Sambuc   long bar4;
229*f4a2713aSLionel Sambuc   short foo6: 16;
230*f4a2713aSLionel Sambuc   short foo7: 16;
231*f4a2713aSLionel Sambuc   short foo8: 16;
232*f4a2713aSLionel Sambuc };
233*f4a2713aSLionel Sambuc static int arr21_bar1_offset[(offsetof(struct t21, bar1) == 8) ? 0 : -1];
234*f4a2713aSLionel Sambuc static int arr21_bar2_offset[(offsetof(struct t21, bar2) == 12) ? 0 : -1];
235*f4a2713aSLionel Sambuc static int arr21_bar3_offset[(offsetof(struct t21, bar3) == 16) ? 0 : -1];
236*f4a2713aSLionel Sambuc static int arr21_bar4_offset[(offsetof(struct t21, bar4) == 32) ? 0 : -1];
237*f4a2713aSLionel Sambuc static int arr21_sizeof[(sizeof(struct t21) == 44) ? 0 : -1];
238*f4a2713aSLionel Sambuc 
main()239*f4a2713aSLionel Sambuc int main() {
240*f4a2713aSLionel Sambuc   return 0;
241*f4a2713aSLionel Sambuc }
242*f4a2713aSLionel Sambuc 
243