Skip to content

Commit c4b2d4a

Browse files
committed
Address feedback
1 parent bd3ffbe commit c4b2d4a

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,10 @@ def Padded : DiagGroup<"padded", [PaddedBitField]>;
635635
def UnalignedAccess : DiagGroup<"unaligned-access">;
636636
def MSBitfieldCompatibility : DiagGroup<"ms-bitfield-compatibility"> {
637637
code Documentation = [{
638-
Under the MSVC ABI adjacent bit-fields are not packed if the underlying type
639-
has a different storage size. This warning indicates that a pair of adjacent
640-
bit-fields may not pack in the same way due to this behavioural difference.
638+
Under the MS Windows platform ABI, adjacent bit-fields are not packed if the
639+
underlying type has a different storage size. This warning indicates that a
640+
pair of adjacent bit-fields may not pack in the same way due to this behavioural
641+
difference.
641642

642643
This can occur when mixing different types explicitly:
643644

@@ -659,13 +660,13 @@ def MSBitfieldCompatibility : DiagGroup<"ms-bitfield-compatibility"> {
659660
Enum2 field2 : 1;
660661
};
661662

662-
In each of these cases under the MSVC ABI the second bit-field will not be
663-
packed with the preceding bit-field, and instead will be aligned as if the
664-
fields were each separately defined integer fields of their respective storage
665-
size. For binary compatibility this is obviously and observably incompatible,
666-
however where bit-fields are being used solely for memory use reduction this
667-
incomplete packing may silently increase the size of objects vs what is
668-
expected.
663+
In each of these cases under the MS Windows platform ABI the second bit-field
664+
will not be packed with the preceding bit-field, and instead will be aligned
665+
as if the fields were each separately defined integer fields of their respective
666+
storage size. For binary compatibility this is obviously and observably
667+
incompatible, however where bit-fields are being used solely for memory use
668+
reduction this incomplete packing may silently increase the size of objects vs
669+
what is expected.
669670

670671
This issue can be addressed by ensuring the storage type of each bit-field is
671672
the same, either by explicitly using the same integer type, or in the case of

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6425,7 +6425,7 @@ def note_change_bitfield_sign : Note<
64256425
def warn_ms_bitfield_mismatched_storage_packing : Warning<
64266426
"bit-field %0 of type %1 has a different storage size than the "
64276427
"preceding bit-field (%2 vs %3 bytes) and will not be packed under "
6428-
"the MSVC ABI">,
6428+
"the MS Windows platform ABI">,
64296429
InGroup<MSBitfieldCompatibility>, DefaultIgnore;
64306430
def note_ms_bitfield_mismatched_storage_size_previous : Note<
64316431
"preceding bit-field %0 declared here with type %1">;

clang/test/SemaCXX/ms_struct-bitfield-padding.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static_assert(sizeof(F) == 4);
5555
struct G {
5656
EnumU32_1 a : 15;
5757
EnumU64 b : 15;
58-
// expected-warning@-1 {{bit-field 'b' of type 'EnumU64' has a different storage size than the preceding bit-field (8 vs 4 bytes) and will not be packed under the MSVC ABI}}
58+
// expected-warning@-1 {{bit-field 'b' of type 'EnumU64' has a different storage size than the preceding bit-field (8 vs 4 bytes) and will not be packed under the MS Windows platform ABI}}
5959
// expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU32_1'}}
6060
};
6161

@@ -76,7 +76,7 @@ struct I {
7676
EnumU8 a : 3;
7777
EnumI8 b : 5;
7878
EnumU32_1 c : 10;
79-
// expected-warning@-1 {{bit-field 'c' of type 'EnumU32_1' has a different storage size than the preceding bit-field (4 vs 1 bytes) and will not be packed under the MSVC ABI}}
79+
// expected-warning@-1 {{bit-field 'c' of type 'EnumU32_1' has a different storage size than the preceding bit-field (4 vs 1 bytes) and will not be packed under the MS Windows platform ABI}}
8080
// expected-note@-3 {{preceding bit-field 'b' declared here with type 'EnumI8'}}
8181
};
8282
#ifdef MS_BITFIELDS
@@ -116,10 +116,10 @@ static_assert(sizeof(M) == 4);
116116
struct N {
117117
EnumU32_1 a : 10;
118118
EnumU64 b : 10;
119-
// expected-warning@-1 {{bit-field 'b' of type 'EnumU64' has a different storage size than the preceding bit-field (8 vs 4 bytes) and will not be packed under the MSVC ABI}}
119+
// expected-warning@-1 {{bit-field 'b' of type 'EnumU64' has a different storage size than the preceding bit-field (8 vs 4 bytes) and will not be packed under the MS Windows platform ABI}}
120120
// expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU32_1'}}
121121
EnumU32_1 c : 10;
122-
// expected-warning@-1 {{bit-field 'c' of type 'EnumU32_1' has a different storage size than the preceding bit-field (4 vs 8 bytes) and will not be packed under the MSVC ABI}}
122+
// expected-warning@-1 {{bit-field 'c' of type 'EnumU32_1' has a different storage size than the preceding bit-field (4 vs 8 bytes) and will not be packed under the MS Windows platform ABI}}
123123
// expected-note@-5 {{preceding bit-field 'b' declared here with type 'EnumU64'}}
124124
};
125125

@@ -132,7 +132,7 @@ static_assert(sizeof(N) == 8);
132132
struct O {
133133
EnumU16 a : 10;
134134
EnumU32_1 b : 10;
135-
// expected-warning@-1 {{bit-field 'b' of type 'EnumU32_1' has a different storage size than the preceding bit-field (4 vs 2 bytes) and will not be packed under the MSVC ABI}}
135+
// expected-warning@-1 {{bit-field 'b' of type 'EnumU32_1' has a different storage size than the preceding bit-field (4 vs 2 bytes) and will not be packed under the MS Windows platform ABI}}
136136
// expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU16'}}
137137
};
138138
#ifdef MS_BITFIELDS
@@ -144,7 +144,7 @@ static_assert(sizeof(O) == 4);
144144
struct P {
145145
EnumU32_1 a : 10;
146146
EnumU16 b : 10;
147-
// expected-warning@-1 {{bit-field 'b' of type 'EnumU16' has a different storage size than the preceding bit-field (2 vs 4 bytes) and will not be packed under the MSVC ABI}}
147+
// expected-warning@-1 {{bit-field 'b' of type 'EnumU16' has a different storage size than the preceding bit-field (2 vs 4 bytes) and will not be packed under the MS Windows platform ABI}}
148148
// expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU32_1'}}
149149
};
150150
#ifdef MS_BITFIELDS
@@ -156,7 +156,7 @@ static_assert(sizeof(P) == 4);
156156
struct Q {
157157
EnumU8 a : 6;
158158
EnumU16 b : 6;
159-
// expected-warning@-1 {{bit-field 'b' of type 'EnumU16' has a different storage size than the preceding bit-field (2 vs 1 bytes) and will not be packed under the MSVC ABI}}
159+
// expected-warning@-1 {{bit-field 'b' of type 'EnumU16' has a different storage size than the preceding bit-field (2 vs 1 bytes) and will not be packed under the MS Windows platform ABI}}
160160
// expected-note@-3 {{preceding bit-field 'a' declared here with type 'EnumU8'}}
161161
};
162162
#ifdef MS_BITFIELDS
@@ -169,7 +169,7 @@ struct R {
169169
EnumU16 a : 9;
170170
EnumU16 b : 9;
171171
EnumU8 c : 6;
172-
// expected-warning@-1 {{bit-field 'c' of type 'EnumU8' has a different storage size than the preceding bit-field (1 vs 2 bytes) and will not be packed under the MSVC ABI}}
172+
// expected-warning@-1 {{bit-field 'c' of type 'EnumU8' has a different storage size than the preceding bit-field (1 vs 2 bytes) and will not be packed under the MS Windows platform ABI}}
173173
// expected-note@-3 {{preceding bit-field 'b' declared here with type 'EnumU16'}}
174174
};
175175

@@ -178,3 +178,19 @@ static_assert(sizeof(R) == 6);
178178
#else
179179
static_assert(sizeof(R) == 4);
180180
#endif
181+
182+
struct S {
183+
char a : 4;
184+
char b : 4;
185+
char c : 4;
186+
char d : 4;
187+
short x : 7;
188+
// expected-warning@-1 {{bit-field 'x' of type 'short' has a different storage size than the preceding bit-field (2 vs 1 bytes) and will not be packed under the MS Windows platform ABI}}
189+
// expected-note@-3 {{preceding bit-field 'd' declared here with type 'char'}}
190+
// This is a false positive. Reporting this correctly requires duplicating the record layout process
191+
// in target and MS layout modes, and it's also unclear if that's the correct choice for users of
192+
// this diagnostic.
193+
short y : 9;
194+
};
195+
196+
static_assert(sizeof(S) == 4);

0 commit comments

Comments
 (0)