Skip to content

Commit 63bf5d5

Browse files
authored
Revert "[clang] add support for -Wpadded on Windows (#130182)"
This reverts commit 76fa953.
1 parent 739fe98 commit 63bf5d5

File tree

4 files changed

+11
-128
lines changed

4 files changed

+11
-128
lines changed

clang/docs/ReleaseNotes.rst

-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ Modified Compiler Flags
190190

191191
- The compiler flag `-fbracket-depth` default value is increased from 256 to 2048. (#GH94728)
192192

193-
- `-Wpadded` option implemented for the `x86_64-windows-msvc` target. Fixes #61702
194-
195193
Removed Compiler Flags
196194
-------------------------
197195

clang/lib/AST/RecordLayoutBuilder.cpp

+11-54
Original file line numberDiff line numberDiff line change
@@ -2274,9 +2274,9 @@ static unsigned getPaddingDiagFromTagKind(TagTypeKind Tag) {
22742274
}
22752275
}
22762276

2277-
static void CheckFieldPadding(const ASTContext &Context, bool IsUnion,
2278-
uint64_t Offset, uint64_t UnpaddedOffset,
2279-
const FieldDecl *D) {
2277+
void ItaniumRecordLayoutBuilder::CheckFieldPadding(
2278+
uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
2279+
unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
22802280
// We let objc ivars without warning, objc interfaces generally are not used
22812281
// for padding tricks.
22822282
if (isa<ObjCIvarDecl>(D))
@@ -2300,31 +2300,23 @@ static void CheckFieldPadding(const ASTContext &Context, bool IsUnion,
23002300
if (D->getIdentifier()) {
23012301
auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_bitfield
23022302
: diag::warn_padded_struct_field;
2303-
Context.getDiagnostics().Report(D->getLocation(),
2304-
Diagnostic)
2303+
Diag(D->getLocation(), Diagnostic)
23052304
<< getPaddingDiagFromTagKind(D->getParent()->getTagKind())
23062305
<< Context.getTypeDeclType(D->getParent()) << PadSize
23072306
<< (InBits ? 1 : 0) // (byte|bit)
23082307
<< D->getIdentifier();
23092308
} else {
23102309
auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_anon_bitfield
23112310
: diag::warn_padded_struct_anon_field;
2312-
Context.getDiagnostics().Report(D->getLocation(),
2313-
Diagnostic)
2311+
Diag(D->getLocation(), Diagnostic)
23142312
<< getPaddingDiagFromTagKind(D->getParent()->getTagKind())
23152313
<< Context.getTypeDeclType(D->getParent()) << PadSize
23162314
<< (InBits ? 1 : 0); // (byte|bit)
23172315
}
2318-
}
2319-
}
2320-
2321-
void ItaniumRecordLayoutBuilder::CheckFieldPadding(
2322-
uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
2323-
unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
2324-
::CheckFieldPadding(Context, IsUnion, Offset, UnpaddedOffset, D);
2325-
if (isPacked && Offset != UnpackedOffset) {
2326-
HasPackedField = true;
2327-
}
2316+
}
2317+
if (isPacked && Offset != UnpackedOffset) {
2318+
HasPackedField = true;
2319+
}
23282320
}
23292321

23302322
static const CXXMethodDecl *computeKeyFunction(ASTContext &Context,
@@ -2650,6 +2642,8 @@ struct MicrosoftRecordLayoutBuilder {
26502642
/// virtual base classes and their offsets in the record.
26512643
ASTRecordLayout::VBaseOffsetsMapTy VBases;
26522644
/// The number of remaining bits in our last bitfield allocation.
2645+
/// This value isn't meaningful unless LastFieldIsNonZeroWidthBitfield is
2646+
/// true.
26532647
unsigned RemainingBitsInField;
26542648
bool IsUnion : 1;
26552649
/// True if the last field laid out was a bitfield and was not 0
@@ -3010,15 +3004,6 @@ void MicrosoftRecordLayoutBuilder::layoutField(const FieldDecl *FD) {
30103004
} else {
30113005
FieldOffset = Size.alignTo(Info.Alignment);
30123006
}
3013-
3014-
uint64_t UnpaddedFielddOffsetInBits =
3015-
Context.toBits(DataSize) - RemainingBitsInField;
3016-
3017-
::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldOffset),
3018-
UnpaddedFielddOffsetInBits, FD);
3019-
3020-
RemainingBitsInField = 0;
3021-
30223007
placeFieldAtOffset(FieldOffset);
30233008

30243009
if (!IsOverlappingEmptyField)
@@ -3064,14 +3049,10 @@ void MicrosoftRecordLayoutBuilder::layoutBitField(const FieldDecl *FD) {
30643049
} else {
30653050
// Allocate a new block of memory and place the bitfield in it.
30663051
CharUnits FieldOffset = Size.alignTo(Info.Alignment);
3067-
uint64_t UnpaddedFieldOffsetInBits =
3068-
Context.toBits(DataSize) - RemainingBitsInField;
30693052
placeFieldAtOffset(FieldOffset);
30703053
Size = FieldOffset + Info.Size;
30713054
Alignment = std::max(Alignment, Info.Alignment);
30723055
RemainingBitsInField = Context.toBits(Info.Size) - Width;
3073-
::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldOffset),
3074-
UnpaddedFieldOffsetInBits, FD);
30753056
}
30763057
DataSize = Size;
30773058
}
@@ -3095,14 +3076,9 @@ MicrosoftRecordLayoutBuilder::layoutZeroWidthBitField(const FieldDecl *FD) {
30953076
} else {
30963077
// Round up the current record size to the field's alignment boundary.
30973078
CharUnits FieldOffset = Size.alignTo(Info.Alignment);
3098-
uint64_t UnpaddedFieldOffsetInBits =
3099-
Context.toBits(DataSize) - RemainingBitsInField;
31003079
placeFieldAtOffset(FieldOffset);
3101-
RemainingBitsInField = 0;
31023080
Size = FieldOffset;
31033081
Alignment = std::max(Alignment, Info.Alignment);
3104-
::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldOffset),
3105-
UnpaddedFieldOffsetInBits, FD);
31063082
}
31073083
DataSize = Size;
31083084
}
@@ -3227,9 +3203,6 @@ void MicrosoftRecordLayoutBuilder::layoutVirtualBases(const CXXRecordDecl *RD) {
32273203
}
32283204

32293205
void MicrosoftRecordLayoutBuilder::finalizeLayout(const RecordDecl *RD) {
3230-
uint64_t UnpaddedSizeInBits = Context.toBits(DataSize);
3231-
UnpaddedSizeInBits -= RemainingBitsInField;
3232-
32333206
// Respect required alignment. Note that in 32-bit mode Required alignment
32343207
// may be 0 and cause size not to be updated.
32353208
DataSize = Size;
@@ -3258,22 +3231,6 @@ void MicrosoftRecordLayoutBuilder::finalizeLayout(const RecordDecl *RD) {
32583231
Size = Context.toCharUnitsFromBits(External.Size);
32593232
if (External.Align)
32603233
Alignment = Context.toCharUnitsFromBits(External.Align);
3261-
return;
3262-
}
3263-
unsigned CharBitNum = Context.getTargetInfo().getCharWidth();
3264-
uint64_t SizeInBits = Context.toBits(Size);
3265-
if (SizeInBits > UnpaddedSizeInBits) {
3266-
unsigned int PadSize = SizeInBits - UnpaddedSizeInBits;
3267-
bool InBits = true;
3268-
if (PadSize % CharBitNum == 0) {
3269-
PadSize = PadSize / CharBitNum;
3270-
InBits = false;
3271-
}
3272-
3273-
Context.getDiagnostics().Report(RD->getLocation(),
3274-
diag::warn_padded_struct_size)
3275-
<< Context.getTypeDeclType(RD) << PadSize
3276-
<< (InBits ? 1 : 0); // (byte|bit)
32773234
}
32783235
}
32793236

clang/test/SemaCXX/windows-Wpadded-bitfield.cpp

-32
This file was deleted.

clang/test/SemaCXX/windows-Wpadded.cpp

-40
This file was deleted.

0 commit comments

Comments
 (0)