Skip to content

Revert "[CLANG-CL] ignores wpadded" #134239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ Modified Compiler Flags

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

- `-Wpadded` option implemented for the `x86_64-windows-msvc` target. Fixes #61702

Removed Compiler Flags
-------------------------

Expand Down
65 changes: 11 additions & 54 deletions clang/lib/AST/RecordLayoutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2274,9 +2274,9 @@ static unsigned getPaddingDiagFromTagKind(TagTypeKind Tag) {
}
}

static void CheckFieldPadding(const ASTContext &Context, bool IsUnion,
uint64_t Offset, uint64_t UnpaddedOffset,
const FieldDecl *D) {
void ItaniumRecordLayoutBuilder::CheckFieldPadding(
uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
// We let objc ivars without warning, objc interfaces generally are not used
// for padding tricks.
if (isa<ObjCIvarDecl>(D))
Expand All @@ -2300,31 +2300,23 @@ static void CheckFieldPadding(const ASTContext &Context, bool IsUnion,
if (D->getIdentifier()) {
auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_bitfield
: diag::warn_padded_struct_field;
Context.getDiagnostics().Report(D->getLocation(),
Diagnostic)
Diag(D->getLocation(), Diagnostic)
<< getPaddingDiagFromTagKind(D->getParent()->getTagKind())
<< Context.getTypeDeclType(D->getParent()) << PadSize
<< (InBits ? 1 : 0) // (byte|bit)
<< D->getIdentifier();
} else {
auto Diagnostic = D->isBitField() ? diag::warn_padded_struct_anon_bitfield
: diag::warn_padded_struct_anon_field;
Context.getDiagnostics().Report(D->getLocation(),
Diagnostic)
Diag(D->getLocation(), Diagnostic)
<< getPaddingDiagFromTagKind(D->getParent()->getTagKind())
<< Context.getTypeDeclType(D->getParent()) << PadSize
<< (InBits ? 1 : 0); // (byte|bit)
}
}
}

void ItaniumRecordLayoutBuilder::CheckFieldPadding(
uint64_t Offset, uint64_t UnpaddedOffset, uint64_t UnpackedOffset,
unsigned UnpackedAlign, bool isPacked, const FieldDecl *D) {
::CheckFieldPadding(Context, IsUnion, Offset, UnpaddedOffset, D);
if (isPacked && Offset != UnpackedOffset) {
HasPackedField = true;
}
}
if (isPacked && Offset != UnpackedOffset) {
HasPackedField = true;
}
}

static const CXXMethodDecl *computeKeyFunction(ASTContext &Context,
Expand Down Expand Up @@ -2650,6 +2642,8 @@ struct MicrosoftRecordLayoutBuilder {
/// virtual base classes and their offsets in the record.
ASTRecordLayout::VBaseOffsetsMapTy VBases;
/// The number of remaining bits in our last bitfield allocation.
/// This value isn't meaningful unless LastFieldIsNonZeroWidthBitfield is
/// true.
unsigned RemainingBitsInField;
bool IsUnion : 1;
/// True if the last field laid out was a bitfield and was not 0
Expand Down Expand Up @@ -3010,15 +3004,6 @@ void MicrosoftRecordLayoutBuilder::layoutField(const FieldDecl *FD) {
} else {
FieldOffset = Size.alignTo(Info.Alignment);
}

uint64_t UnpaddedFielddOffsetInBits =
Context.toBits(DataSize) - RemainingBitsInField;

::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldOffset),
UnpaddedFielddOffsetInBits, FD);

RemainingBitsInField = 0;

placeFieldAtOffset(FieldOffset);

if (!IsOverlappingEmptyField)
Expand Down Expand Up @@ -3064,14 +3049,10 @@ void MicrosoftRecordLayoutBuilder::layoutBitField(const FieldDecl *FD) {
} else {
// Allocate a new block of memory and place the bitfield in it.
CharUnits FieldOffset = Size.alignTo(Info.Alignment);
uint64_t UnpaddedFieldOffsetInBits =
Context.toBits(DataSize) - RemainingBitsInField;
placeFieldAtOffset(FieldOffset);
Size = FieldOffset + Info.Size;
Alignment = std::max(Alignment, Info.Alignment);
RemainingBitsInField = Context.toBits(Info.Size) - Width;
::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldOffset),
UnpaddedFieldOffsetInBits, FD);
}
DataSize = Size;
}
Expand All @@ -3095,14 +3076,9 @@ MicrosoftRecordLayoutBuilder::layoutZeroWidthBitField(const FieldDecl *FD) {
} else {
// Round up the current record size to the field's alignment boundary.
CharUnits FieldOffset = Size.alignTo(Info.Alignment);
uint64_t UnpaddedFieldOffsetInBits =
Context.toBits(DataSize) - RemainingBitsInField;
placeFieldAtOffset(FieldOffset);
RemainingBitsInField = 0;
Size = FieldOffset;
Alignment = std::max(Alignment, Info.Alignment);
::CheckFieldPadding(Context, IsUnion, Context.toBits(FieldOffset),
UnpaddedFieldOffsetInBits, FD);
}
DataSize = Size;
}
Expand Down Expand Up @@ -3227,9 +3203,6 @@ void MicrosoftRecordLayoutBuilder::layoutVirtualBases(const CXXRecordDecl *RD) {
}

void MicrosoftRecordLayoutBuilder::finalizeLayout(const RecordDecl *RD) {
uint64_t UnpaddedSizeInBits = Context.toBits(DataSize);
UnpaddedSizeInBits -= RemainingBitsInField;

// Respect required alignment. Note that in 32-bit mode Required alignment
// may be 0 and cause size not to be updated.
DataSize = Size;
Expand Down Expand Up @@ -3258,22 +3231,6 @@ void MicrosoftRecordLayoutBuilder::finalizeLayout(const RecordDecl *RD) {
Size = Context.toCharUnitsFromBits(External.Size);
if (External.Align)
Alignment = Context.toCharUnitsFromBits(External.Align);
return;
}
unsigned CharBitNum = Context.getTargetInfo().getCharWidth();
uint64_t SizeInBits = Context.toBits(Size);
if (SizeInBits > UnpaddedSizeInBits) {
unsigned int PadSize = SizeInBits - UnpaddedSizeInBits;
bool InBits = true;
if (PadSize % CharBitNum == 0) {
PadSize = PadSize / CharBitNum;
InBits = false;
}

Context.getDiagnostics().Report(RD->getLocation(),
diag::warn_padded_struct_size)
<< Context.getTypeDeclType(RD) << PadSize
<< (InBits ? 1 : 0); // (byte|bit)
}
}

Expand Down
32 changes: 0 additions & 32 deletions clang/test/SemaCXX/windows-Wpadded-bitfield.cpp

This file was deleted.

40 changes: 0 additions & 40 deletions clang/test/SemaCXX/windows-Wpadded.cpp

This file was deleted.

Loading