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