Debian Codegraph @

clang/test/Sema/bitfield-layout_1.c

raw
1 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9
2 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=arm-linux-gnueabihf
3 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=aarch64-linux-gnu
4 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-pc-linux-gnu
5 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-apple-darwin9 -Wms-bitfield-padding
6 // expected-no-diagnostics
7
8 #define CHECK_SIZE(name, size) \
9 extern int name##_1[sizeof(name) == size ? 1 : -1];
10
11
12 struct __attribute__((packed)) {
13 int a;
14 int b : 4;
15 int c : 32;
16 } s0;
17 CHECK_SIZE(s0,9)
18
19 #pragma pack (1)
20 struct {
21 int a;
22 int b : 4;
23 int c : 32;
24 } s1;
25 CHECK_SIZE(s1,9)
26
27 #pragma pack (2)
28 struct {
29 int a;
30 int b : 4;
31 int c : 32;
32 } s2;
33 CHECK_SIZE(s2,10)
34
35 #pragma pack (2)
36 struct __attribute__((packed)) {
37 int a;
38 int b : 4;
39 int c : 32;
40 } s3;
41 CHECK_SIZE(s3,10)
42
43 #pragma pack (4)
44 struct __attribute__((packed)) {
45 int a;
46 int b : 4;
47 int c : 32;
48 } s4;
49 CHECK_SIZE(s4,12)
50
51 #pragma pack (16)
52 struct {
53 int a;
54 int __attribute__((packed)) b : 4;
55 int __attribute__((packed)) c : 32;
56 } s41;
57 CHECK_SIZE(s41,12)
58
59 #pragma pack (16)
60 struct {
61 int a;
62 int b : 4;
63 int c : 32;
64 } s5;
65 CHECK_SIZE(s5,12)
66
67 #pragma pack (1)
68 struct __attribute__((aligned(4))) {
69 int a;
70 int b : 4;
71 int c : 32;
72 } s6;
73 CHECK_SIZE(s6,12)
74
75 #pragma pack (2)
76 struct {
77 char a;
78 int b : 4;
79 int c : 32;
80 char s;
81 } s7;
82 CHECK_SIZE(s7,8)
83
84 #pragma pack (1)
85 struct {
86 char a;
87 int b : 4;
88 int c : 28;
89 char s;
90 } s8;
91 CHECK_SIZE(s8,6)
92
93 #pragma pack (8)
94 struct {
95 char a;
96 int b : 4;
97 int c : 28;
98 char s;
99 } s9;
100 CHECK_SIZE(s9,8)
101
102 #pragma pack (8)
103 struct {
104 char a;
105 char s;
106 } s10;
107 CHECK_SIZE(s10,2)
108
109 #pragma pack(4)
110 struct {
111 char a;
112 int b : 4;
113 int c : 28;
114 char s1;
115 char s2;
116 char s3;
117 } s11;
118 CHECK_SIZE(s11,8)
119
120 #pragma pack(4)
121 struct {
122 short s1;
123 int a1 : 17;
124 int a2 : 17;
125 int a3 : 30;
126 short s2;
127 } s12;
128 CHECK_SIZE(s12,12)
129
130 #pragma pack(4)
131 struct {
132 char c1;
133 int i1 : 17;
134 int i2 : 17;
135 int i3 : 30;
136 char c2;
137 } s13;
138 CHECK_SIZE(s13,12)
139
140 #pragma pack(2)
141 struct {
142 char a;
143 int s;
144 } s14;
145 CHECK_SIZE(s14,6)
146
147 #pragma pack(4)
148 struct {
149 char a;
150 short s;
151 } s15;
152 CHECK_SIZE(s15,4)
153
154 #pragma pack(2)
155 struct {
156 char a;
157 int b : 4;
158 int c : 28;
159 char s1;
160 char s2;
161 char s3;
162 } s16;
163 CHECK_SIZE(s16,8)
164
165 #pragma pack (16)
166 struct {
167 int __attribute__((packed)) a;
168 int __attribute__((packed)) b : 4;
169 int __attribute__((packed)) c : 32;
170 } s17;
171 CHECK_SIZE(s17,12)
172
173 #pragma pack (16)
174 struct {
175 int __attribute__((aligned(8))) a;
176 int __attribute__((aligned(8))) b : 4;
177 int __attribute__((aligned(8))) c : 32;
178 } s18;
179 CHECK_SIZE(s18,24)
180
181 #pragma pack (16)
182 struct {
183 int __attribute__((aligned(1))) a;
184 int __attribute__((aligned(1))) b : 4;
185 int __attribute__((aligned(1))) c : 32;
186 } s19;
187 CHECK_SIZE(s19,12)
188
189 #pragma pack (1)
190 struct __attribute__((aligned(8))) {
191 int a;
192 int b : 4;
193 int c : 32;
194 } s20;
195 CHECK_SIZE(s20,16)
196
197 #pragma pack (2)
198 struct {
199 int __attribute__((aligned(8))) a;
200 int __attribute__((aligned(8))) b : 4;
201 int __attribute__((aligned(8))) c : 32;
202 } s21;
203 CHECK_SIZE(s21,10)