Skip to content

Commit 1d6bf0c

Browse files
authored
[clang][NFC] Remove class layout scissor (#89055)
PR #87090 amended `accumulateBitfields` to do the correct clipping. The scissor is no longer necessary and `checkBitfieldClipping` can compute its location directly when needed.
1 parent c8864bc commit 1d6bf0c

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct CGRecordLowering {
7575
// sentinel member type that ensures correct rounding.
7676
struct MemberInfo {
7777
CharUnits Offset;
78-
enum InfoKind { VFPtr, VBPtr, Field, Base, VBase, Scissor } Kind;
78+
enum InfoKind { VFPtr, VBPtr, Field, Base, VBase } Kind;
7979
llvm::Type *Data;
8080
union {
8181
const FieldDecl *FD;
@@ -197,7 +197,7 @@ struct CGRecordLowering {
197197
const CXXRecordDecl *Query) const;
198198
void calculateZeroInit();
199199
CharUnits calculateTailClippingOffset(bool isNonVirtualBaseType) const;
200-
void checkBitfieldClipping() const;
200+
void checkBitfieldClipping(bool isNonVirtualBaseType) const;
201201
/// Determines if we need a packed llvm struct.
202202
void determinePacked(bool NVBaseType);
203203
/// Inserts padding everywhere it's needed.
@@ -299,8 +299,8 @@ void CGRecordLowering::lower(bool NVBaseType) {
299299
accumulateVBases();
300300
}
301301
llvm::stable_sort(Members);
302+
checkBitfieldClipping(NVBaseType);
302303
Members.push_back(StorageInfo(Size, getIntNType(8)));
303-
checkBitfieldClipping();
304304
determinePacked(NVBaseType);
305305
insertPadding();
306306
Members.pop_back();
@@ -894,8 +894,6 @@ CGRecordLowering::calculateTailClippingOffset(bool isNonVirtualBaseType) const {
894894
}
895895

896896
void CGRecordLowering::accumulateVBases() {
897-
Members.push_back(MemberInfo(calculateTailClippingOffset(false),
898-
MemberInfo::Scissor, nullptr, RD));
899897
for (const auto &Base : RD->vbases()) {
900898
const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
901899
if (BaseDecl->isEmpty())
@@ -950,18 +948,19 @@ void CGRecordLowering::calculateZeroInit() {
950948
}
951949

952950
// Verify accumulateBitfields computed the correct storage representations.
953-
void CGRecordLowering::checkBitfieldClipping() const {
951+
void CGRecordLowering::checkBitfieldClipping(bool IsNonVirtualBaseType) const {
954952
#ifndef NDEBUG
953+
auto ScissorOffset = calculateTailClippingOffset(IsNonVirtualBaseType);
955954
auto Tail = CharUnits::Zero();
956955
for (const auto &M : Members) {
957-
// Only members with data and the scissor can cut into tail padding.
958-
if (!M.Data && M.Kind != MemberInfo::Scissor)
956+
// Only members with data could possibly overlap.
957+
if (!M.Data)
959958
continue;
960959

961960
assert(M.Offset >= Tail && "Bitfield access unit is not clipped");
962-
Tail = M.Offset;
963-
if (M.Data)
964-
Tail += getSize(M.Data);
961+
Tail = M.Offset + getSize(M.Data);
962+
assert((Tail <= ScissorOffset || M.Offset >= ScissorOffset) &&
963+
"Bitfield straddles scissor offset");
965964
}
966965
#endif
967966
}

0 commit comments

Comments
 (0)