Skip to content

Commit c6d6929

Browse files
committed
fixup! add helper wrappers for isEmptyField/isEmptyRecord
1 parent c8dfbac commit c6d6929

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

clang/lib/CodeGen/ABIInfoImpl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,16 @@ bool CodeGen::isEmptyField(const ASTContext &Context, const FieldDecl *FD,
289289
return isEmptyRecord(Context, FT, AllowArrays, AsIfNoUniqueAddr);
290290
}
291291

292+
bool CodeGen::isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD) {
293+
if (FD->isZeroLengthBitField(Context))
294+
return true;
295+
296+
if (FD->isUnnamedBitField())
297+
return false;
298+
299+
return isEmptyField(Context, FD, /*AllowArrays=*/false, /*AsIfNoUniqueAddr=*/true);
300+
}
301+
292302
bool CodeGen::isEmptyRecord(const ASTContext &Context, QualType T,
293303
bool AllowArrays, bool AsIfNoUniqueAddr) {
294304
const RecordType *RT = T->getAs<RecordType>();
@@ -310,6 +320,10 @@ bool CodeGen::isEmptyRecord(const ASTContext &Context, QualType T,
310320
return true;
311321
}
312322

323+
bool CodeGen::isEmptyRecordForLayout(const ASTContext &Context, QualType T) {
324+
return isEmptyRecord(Context, T, /*AllowArrays=*/false, /*AsIfNoUniqueAddr=*/true);
325+
}
326+
313327
const Type *CodeGen::isSingleElementStruct(QualType T, ASTContext &Context) {
314328
const RecordType *RT = T->getAs<RecordType>();
315329
if (!RT)

clang/lib/CodeGen/ABIInfoImpl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ Address emitMergePHI(CodeGenFunction &CGF, Address Addr1,
129129
bool isEmptyField(const ASTContext &Context, const FieldDecl *FD,
130130
bool AllowArrays, bool AsIfNoUniqueAddr = false);
131131

132+
/// isEmptyFieldForLayout - Return true iff the field is "empty", that is,
133+
/// either a zero-width bit-field or an empty record.
134+
bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD);
135+
132136
/// isEmptyRecord - Return true iff a structure contains only empty
133137
/// fields. Note that a structure with a flexible array member is not
134138
/// considered empty. If AsIfNoUniqueAddr is true, then C++ record fields are
@@ -137,6 +141,11 @@ bool isEmptyField(const ASTContext &Context, const FieldDecl *FD,
137141
bool isEmptyRecord(const ASTContext &Context, QualType T, bool AllowArrays,
138142
bool AsIfNoUniqueAddr = false);
139143

144+
/// isEmptyRecordForLayout - Return true iff a structure contains only empty
145+
/// fields. Note, C++ record fields are considered empty if the
146+
/// [[no_unique_address]] attribute would have made them empty.
147+
bool isEmptyRecordForLayout(const ASTContext &Context, QualType T);
148+
140149
/// isSingleElementStruct - Determine if a structure is a "single
141150
/// element struct", i.e. it has exactly one non-empty field or
142151
/// exactly one field which is itself a single element

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4763,7 +4763,7 @@ static Address emitAddrOfZeroSizeField(CodeGenFunction &CGF, Address Base,
47634763
/// The resulting address doesn't necessarily have the right type.
47644764
static Address emitAddrOfFieldStorage(CodeGenFunction &CGF, Address base,
47654765
const FieldDecl *field) {
4766-
if (isEmptyField(CGF.getContext(), field, false, true))
4766+
if (isEmptyFieldForLayout(CGF.getContext(), field))
47674767
return emitAddrOfZeroSizeField(CGF, base, field);
47684768

47694769
const RecordDecl *rec = field->getParent();

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ static llvm::Constant *EmitNullConstant(CodeGenModule &CGM,
24822482
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl());
24832483

24842484
// Ignore empty bases.
2485-
if (isEmptyRecord(CGM.getContext(), I.getType(), false, true) ||
2485+
if (isEmptyRecordForLayout(CGM.getContext(), I.getType()) ||
24862486
CGM.getContext()
24872487
.getASTRecordLayout(base)
24882488
.getNonVirtualSize()
@@ -2521,7 +2521,7 @@ static llvm::Constant *EmitNullConstant(CodeGenModule &CGM,
25212521
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl());
25222522

25232523
// Ignore empty bases.
2524-
if (isEmptyRecord(CGM.getContext(), I.getType(), false, true))
2524+
if (isEmptyRecordForLayout(CGM.getContext(), I.getType()))
25252525
continue;
25262526

25272527
unsigned fieldIndex = layout.getVirtualBaseIndex(base);

clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void CGRecordLowering::accumulateFields(bool isNonVirtualBaseType) {
385385
Field = accumulateBitFields(isNonVirtualBaseType, Field, FieldEnd);
386386
assert((Field == FieldEnd || !Field->isBitField()) &&
387387
"Failed to accumulate all the bitfields");
388-
} else if (isEmptyField(Context, *Field, false, true)) {
388+
} else if (isEmptyFieldForLayout(Context, *Field)) {
389389
// Empty fields have no storage.
390390
++Field;
391391
} else {
@@ -635,9 +635,7 @@ CGRecordLowering::accumulateBitFields(bool isNonVirtualBaseType,
635635
// non-reusable tail padding.
636636
CharUnits LimitOffset;
637637
for (auto Probe = Field; Probe != FieldEnd; ++Probe)
638-
if (!Probe->isZeroLengthBitField(Context) &&
639-
!(isEmptyField(Context, *Probe, false, true) &&
640-
!Probe->isBitField())) {
638+
if (!isEmptyFieldForLayout(Context, *Probe)) {
641639
// A member with storage sets the limit.
642640
assert((getFieldBitOffset(*Probe) % CharBits) == 0 &&
643641
"Next storage is not byte-aligned");
@@ -735,7 +733,7 @@ void CGRecordLowering::accumulateBases() {
735733
// Bases can be zero-sized even if not technically empty if they
736734
// contain only a trailing array member.
737735
const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
738-
if (!isEmptyRecord(Context, Base.getType(), false, true) &&
736+
if (!isEmptyRecordForLayout(Context, Base.getType()) &&
739737
!Context.getASTRecordLayout(BaseDecl).getNonVirtualSize().isZero())
740738
Members.push_back(MemberInfo(Layout.getBaseClassOffset(BaseDecl),
741739
MemberInfo::Base, getStorageType(BaseDecl), BaseDecl));
@@ -883,7 +881,7 @@ CGRecordLowering::calculateTailClippingOffset(bool isNonVirtualBaseType) const {
883881
if (!isNonVirtualBaseType && isOverlappingVBaseABI())
884882
for (const auto &Base : RD->vbases()) {
885883
const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
886-
if (isEmptyRecord(Context, Base.getType(), false, true))
884+
if (isEmptyRecordForLayout(Context, Base.getType()))
887885
continue;
888886
// If the vbase is a primary virtual base of some base, then it doesn't
889887
// get its own storage location but instead lives inside of that base.
@@ -899,7 +897,7 @@ CGRecordLowering::calculateTailClippingOffset(bool isNonVirtualBaseType) const {
899897
void CGRecordLowering::accumulateVBases() {
900898
for (const auto &Base : RD->vbases()) {
901899
const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
902-
if (isEmptyRecord(Context, Base.getType(), false, true))
900+
if (isEmptyRecordForLayout(Context, Base.getType()))
903901
continue;
904902
CharUnits Offset = Layout.getVBaseClassOffset(BaseDecl);
905903
// If the vbase is a primary virtual base of some base, then it doesn't
@@ -1165,8 +1163,7 @@ CodeGenTypes::ComputeRecordLayout(const RecordDecl *D, llvm::StructType *Ty) {
11651163
const FieldDecl *FD = *it;
11661164

11671165
// Ignore zero-sized fields.
1168-
if (FD->isZeroLengthBitField(Context) ||
1169-
(isEmptyField(Context, FD, false, true) && !FD->isBitField()))
1166+
if (isEmptyFieldForLayout(getContext(), FD))
11701167
continue;
11711168

11721169
// For non-bit-fields, just check that the LLVM struct offset matches the

0 commit comments

Comments
 (0)