You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an off-by-default warning to complain about MSVC bitfield padding (llvm#117428)
This just adds a warning for bitfields placed next to other bitfields
where the underlying type has different storage. Under the MS struct
bitfield packing ABI such bitfields are not packed.
// checkms-warning@-1 {{bit-field '' of type 'char' has a different storage size than the preceding bit-field (1 vs 2 bytes) and will not be packed under the Microsoft ABI}}
33
+
// checkms-note@#a2x {{preceding bit-field 'x' declared here with type 'short'}}
34
+
inty : 17;
35
+
// checkms-warning@-1 {{bit-field 'y' of type 'int' has a different storage size than the preceding bit-field (4 vs 1 bytes) and will not be packed under the Microsoft ABI}}
36
+
// checkms-note@#a2anon {{preceding bit-field '' declared here with type 'char'}}
37
+
};
38
+
28
39
CHECK_SIZE(struct, a2, 5)
29
40
CHECK_ALIGN(struct, a2, 1)
30
41
31
42
// Zero-width bit-fields at the end of packed struct
// checkms-warning@-1 {{bit-field '' of type 'int' has a different storage size than the preceding bit-field (4 vs 2 bytes) and will not be packed under the Microsoft ABI}}
47
+
// checkms-note@#a3x {{preceding bit-field 'x' declared here with type 'short'}}
48
+
};
49
+
33
50
#if defined(__arm__) || defined(__aarch64__)
34
51
CHECK_SIZE(struct, a3, 4)
35
52
CHECK_ALIGN(struct, a3, 4)
@@ -39,7 +56,12 @@ CHECK_ALIGN(struct, a3, 1)
39
56
#endif
40
57
41
58
// For comparison, non-zero-width bit-fields at the end of packed struct
// checkms-warning@-1 {{bit-field '' of type 'int' has a different storage size than the preceding bit-field (4 vs 2 bytes) and will not be packed under the Microsoft ABI}}
63
+
// checkms-note@#a4x {{preceding bit-field 'x' declared here with type 'short'}}
// checkms-warning@-1 {{bit-field 'n' of type 'int' has a different storage size than the preceding bit-field (4 vs 1 bytes) and will not be packed under the Microsoft ABI}}
193
+
// checkms-note@#g5 {{preceding bit-field '' declared here with type 'char'}}
170
194
};
171
195
CHECK_SIZE(struct, g5, 4);
172
196
CHECK_ALIGN(struct, g5, 4);
173
197
174
198
struct __attribute__((packed)) g6 {
175
-
char : 1;
199
+
char : 1;// #g6
176
200
__attribute__((aligned(1))) intn : 24;
201
+
// checkms-warning@-1 {{bit-field 'n' of type 'int' has a different storage size than the preceding bit-field (4 vs 1 bytes) and will not be packed under the Microsoft ABI}}
202
+
// checkms-note@#g6 {{preceding bit-field '' declared here with type 'char'}}
177
203
};
178
204
CHECK_SIZE(struct, g6, 4);
179
205
CHECK_ALIGN(struct, g6, 1);
180
206
181
207
structg7 {
182
-
char : 1;
208
+
char : 1;// #g7
183
209
__attribute__((aligned(1))) intn : 25;
210
+
// checkms-warning@-1 {{bit-field 'n' of type 'int' has a different storage size than the preceding bit-field (4 vs 1 bytes) and will not be packed under the Microsoft ABI}}
211
+
// checkms-note@#g7 {{preceding bit-field '' declared here with type 'char'}}
184
212
};
185
213
#if defined(__ORBIS__)
186
214
CHECK_SIZE(struct, g7, 4);
@@ -190,8 +218,10 @@ CHECK_SIZE(struct, g7, 8);
190
218
CHECK_ALIGN(struct, g7, 4);
191
219
192
220
struct __attribute__((packed)) g8 {
193
-
char : 1;
221
+
char : 1;// #g8
194
222
__attribute__((aligned(1))) intn : 25;
223
+
// checkms-warning@-1 {{bit-field 'n' of type 'int' has a different storage size than the preceding bit-field (4 vs 1 bytes) and will not be packed under the Microsoft ABI}}
224
+
// checkms-note@#g8 {{preceding bit-field '' declared here with type 'char'}}
// The -mms-bitfields commandline parameter should behave the same
5
7
// as the ms_struct attribute.
6
8
struct
7
9
{
8
-
inta : 1;
10
+
inta : 1;// #a
9
11
shortb : 1;
12
+
// checkms-warning@-1 {{bit-field 'b' of type 'short' has a different storage size than the preceding bit-field (2 vs 4 bytes) and will not be packed under the Microsoft ABI}}
13
+
// checkms-note@#a {{preceding bit-field 'a' declared here with type 'int'}}
0 commit comments