Skip to content

Commit 11447fe

Browse files
committed
Address feedback
1 parent fbe679e commit 11447fe

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6423,8 +6423,9 @@ def warn_signed_bitfield_enum_conversion : Warning<
64236423
def note_change_bitfield_sign : Note<
64246424
"consider making the bit-field type %select{unsigned|signed}0">;
64256425
def warn_ms_bitfield_mismatched_storage_packing : Warning<
6426-
"bit-field %0 of type %1 has a different storage size (%2 vs %3 bytes) than the "
6427-
"preceding bit-field and may not be packed under MSVC ABI">,
6426+
"bit-field %0 of type %1 has a different storage size than the "
6427+
"preceding bit-field (%2 vs %3 bytes) and will not be packed under "
6428+
"the MSVC ABI">,
64286429
InGroup<MSBitfieldCompatibility>, DefaultIgnore;
64296430
def note_ms_bitfield_mismatched_storage_size_previous : Note<
64306431
"preceding bit-field %0 declared here with type %1">;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19016,7 +19016,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
1901619016

1901719017
// Verify that all the fields are okay.
1901819018
SmallVector<FieldDecl*, 32> RecFields;
19019-
std::optional<const FieldDecl *> PreviousField;
19019+
const FieldDecl *PreviousField = nullptr;
1902019020
for (ArrayRef<Decl *>::iterator i = Fields.begin(), end = Fields.end();
1902119021
i != end; PreviousField = cast<FieldDecl>(*i), ++i) {
1902219022
FieldDecl *FD = cast<FieldDecl>(*i);
@@ -19229,26 +19229,22 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
1922919229
if (Record && FD->getType().isVolatileQualified())
1923019230
Record->setHasVolatileMember(true);
1923119231
auto IsNonDependentBitField = [](const FieldDecl *FD) {
19232-
if (!FD->isBitField())
19233-
return false;
19234-
if (FD->getType()->isDependentType())
19235-
return false;
19236-
return true;
19232+
return FD->isBitField() && !FD->getType()->isDependentType();
1923719233
};
1923819234

1923919235
if (Record && PreviousField && IsNonDependentBitField(FD) &&
19240-
IsNonDependentBitField(*PreviousField)) {
19241-
unsigned FDStorageSize =
19242-
Context.getTypeSizeInChars(FD->getType()).getQuantity();
19243-
unsigned PreviousFieldStorageSize =
19244-
Context.getTypeSizeInChars((*PreviousField)->getType()).getQuantity();
19236+
IsNonDependentBitField(PreviousField)) {
19237+
CharUnits FDStorageSize = Context.getTypeSizeInChars(FD->getType());
19238+
CharUnits PreviousFieldStorageSize =
19239+
Context.getTypeSizeInChars(PreviousField->getType());
1924519240
if (FDStorageSize != PreviousFieldStorageSize) {
1924619241
Diag(FD->getLocation(),
1924719242
diag::warn_ms_bitfield_mismatched_storage_packing)
19248-
<< FD << FD->getType() << FDStorageSize << PreviousFieldStorageSize;
19249-
Diag((*PreviousField)->getLocation(),
19243+
<< FD << FD->getType() << FDStorageSize.getQuantity()
19244+
<< PreviousFieldStorageSize.getQuantity();
19245+
Diag(PreviousField->getLocation(),
1925019246
diag::note_ms_bitfield_mismatched_storage_size_previous)
19251-
<< *PreviousField << (*PreviousField)->getType();
19247+
<< PreviousField << PreviousField->getType();
1925219248
}
1925319249
}
1925419250
// Keep track of the number of named members.

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

Lines changed: 8 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 (8 vs 4 bytes) than the preceding bit-field and may not be packed under 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 MSVC 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 (4 vs 1 bytes) than the preceding bit-field and may not be packed under 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 MSVC 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 (8 vs 4 bytes) than the preceding bit-field and may not be packed under 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 MSVC 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 (4 vs 8 bytes) than the preceding bit-field and may not be packed under 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 MSVC 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 (4 vs 2 bytes) than the preceding bit-field and may not be packed under 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 MSVC 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 (2 vs 4 bytes) than the preceding bit-field and may not be packed under 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 MSVC 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 (2 vs 1 bytes) than the preceding bit-field and may not be packed under 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 MSVC 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 (1 vs 2 bytes) than the preceding bit-field and may not be packed under 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 MSVC ABI}}
173173
// expected-note@-3 {{preceding bit-field 'b' declared here with type 'EnumU16'}}
174174
};
175175

0 commit comments

Comments
 (0)