@@ -75,7 +75,7 @@ struct CGRecordLowering {
75
75
// sentinel member type that ensures correct rounding.
76
76
struct MemberInfo {
77
77
CharUnits Offset;
78
- enum InfoKind { VFPtr, VBPtr, Field, Base, VBase, Scissor } Kind;
78
+ enum InfoKind { VFPtr, VBPtr, Field, Base, VBase } Kind;
79
79
llvm::Type *Data;
80
80
union {
81
81
const FieldDecl *FD;
@@ -197,7 +197,7 @@ struct CGRecordLowering {
197
197
const CXXRecordDecl *Query) const ;
198
198
void calculateZeroInit ();
199
199
CharUnits calculateTailClippingOffset (bool isNonVirtualBaseType) const ;
200
- void checkBitfieldClipping () const ;
200
+ void checkBitfieldClipping (bool isNonVirtualBaseType ) const ;
201
201
// / Determines if we need a packed llvm struct.
202
202
void determinePacked (bool NVBaseType);
203
203
// / Inserts padding everywhere it's needed.
@@ -299,8 +299,8 @@ void CGRecordLowering::lower(bool NVBaseType) {
299
299
accumulateVBases ();
300
300
}
301
301
llvm::stable_sort (Members);
302
+ checkBitfieldClipping (NVBaseType);
302
303
Members.push_back (StorageInfo (Size, getIntNType (8 )));
303
- checkBitfieldClipping ();
304
304
determinePacked (NVBaseType);
305
305
insertPadding ();
306
306
Members.pop_back ();
@@ -894,8 +894,6 @@ CGRecordLowering::calculateTailClippingOffset(bool isNonVirtualBaseType) const {
894
894
}
895
895
896
896
void CGRecordLowering::accumulateVBases () {
897
- Members.push_back (MemberInfo (calculateTailClippingOffset (false ),
898
- MemberInfo::Scissor, nullptr , RD));
899
897
for (const auto &Base : RD->vbases ()) {
900
898
const CXXRecordDecl *BaseDecl = Base.getType ()->getAsCXXRecordDecl ();
901
899
if (BaseDecl->isEmpty ())
@@ -950,18 +948,19 @@ void CGRecordLowering::calculateZeroInit() {
950
948
}
951
949
952
950
// Verify accumulateBitfields computed the correct storage representations.
953
- void CGRecordLowering::checkBitfieldClipping () const {
951
+ void CGRecordLowering::checkBitfieldClipping (bool IsNonVirtualBaseType ) const {
954
952
#ifndef NDEBUG
953
+ auto ScissorOffset = calculateTailClippingOffset (IsNonVirtualBaseType);
955
954
auto Tail = CharUnits::Zero ();
956
955
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 )
959
958
continue ;
960
959
961
960
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 " );
965
964
}
966
965
#endif
967
966
}
0 commit comments