Skip to content

Commit 81fc3ad

Browse files
authored
[clang] Avoid re-evaluating field bitwidth (#117732)
Save the bitwidth value as a `ConstantExpr` with the value set. Remove the `ASTContext` parameter from `getBitWidthValue()`, so the latter simply returns the value from the `ConstantExpr` instead of constant-evaluating the bitwidth expression every time it is called.
1 parent 72a28a3 commit 81fc3ad

38 files changed

+96
-94
lines changed

clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ AST_MATCHER(FieldDecl, hasIntBitwidth) {
3838
assert(Node.isBitField());
3939
const ASTContext &Ctx = Node.getASTContext();
4040
unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
41-
unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
41+
unsigned CurrentBitWidth = Node.getBitWidthValue();
4242
return IntBitWidth == CurrentBitWidth;
4343
}
4444

clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static MagnitudeBits calcMagnitudeBits(const ASTContext &Context,
124124
unsigned SignedBits = IntExprType->isUnsignedIntegerType() ? 0U : 1U;
125125

126126
if (const auto *BitField = IntExpr->getSourceBitField()) {
127-
unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
127+
unsigned BitFieldWidth = BitField->getBitWidthValue();
128128
return {BitFieldWidth - SignedBits, BitFieldWidth};
129129
}
130130

clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
160160
}
161161
if (const auto *BitfieldDecl =
162162
Result.Nodes.getNodeAs<FieldDecl>("bitfield")) {
163-
return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
163+
return twoPow(BitfieldDecl->getBitWidthValue());
164164
}
165165

166166
return static_cast<std::size_t>(0);

clang-tools-extra/clangd/Hover.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
10181018
const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Record);
10191019
HI.Offset = Layout.getFieldOffset(FD->getFieldIndex());
10201020
if (FD->isBitField())
1021-
HI.Size = FD->getBitWidthValue(Ctx);
1021+
HI.Size = FD->getBitWidthValue();
10221022
else if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType()))
10231023
HI.Size = FD->isZeroSize(Ctx) ? 0 : Size->getQuantity() * 8;
10241024
if (HI.Size) {

clang/include/clang/AST/Decl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,7 +3142,9 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
31423142

31433143
/// Computes the bit width of this field, if this is a bit field.
31443144
/// May not be called on non-bitfields.
3145-
unsigned getBitWidthValue(const ASTContext &Ctx) const;
3145+
/// Note that in order to successfully use this function, the bitwidth
3146+
/// expression must be a ConstantExpr with a valid integer result set.
3147+
unsigned getBitWidthValue() const;
31463148

31473149
/// Set the bit-field width for this member.
31483150
// Note: used by some clients (i.e., do not remove it).
@@ -3173,7 +3175,7 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
31733175
/// Is this a zero-length bit-field? Such bit-fields aren't really bit-fields
31743176
/// at all and instead act as a separator between contiguous runs of other
31753177
/// bit-fields.
3176-
bool isZeroLengthBitField(const ASTContext &Ctx) const;
3178+
bool isZeroLengthBitField() const;
31773179

31783180
/// Determine if this field is a subobject of zero size, that is, either a
31793181
/// zero-length bit-field or a field of empty class type with the

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,7 @@ AST_MATCHER(FieldDecl, isBitField) {
708708
/// fieldDecl(hasBitWidth(2))
709709
/// matches 'int a;' and 'int c;' but not 'int b;'.
710710
AST_MATCHER_P(FieldDecl, hasBitWidth, unsigned, Width) {
711-
return Node.isBitField() &&
712-
Node.getBitWidthValue(Finder->getASTContext()) == Width;
711+
return Node.isBitField() && Node.getBitWidthValue() == Width;
713712
}
714713

715714
/// Matches non-static data members that have an in-class initializer.

clang/lib/AST/ASTContext.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,7 +2795,7 @@ getSubobjectSizeInBits(const FieldDecl *Field, const ASTContext &Context,
27952795
if (Field->isUnnamedBitField())
27962796
return 0;
27972797

2798-
int64_t BitfieldSize = Field->getBitWidthValue(Context);
2798+
int64_t BitfieldSize = Field->getBitWidthValue();
27992799
if (IsBitIntType) {
28002800
if ((unsigned)BitfieldSize >
28012801
cast<BitIntType>(Field->getType())->getNumBits())
@@ -7769,7 +7769,7 @@ QualType ASTContext::isPromotableBitField(Expr *E) const {
77697769

77707770
QualType FT = Field->getType();
77717771

7772-
uint64_t BitWidth = Field->getBitWidthValue(*this);
7772+
uint64_t BitWidth = Field->getBitWidthValue();
77737773
uint64_t IntSize = getTypeSize(IntTy);
77747774
// C++ [conv.prom]p5:
77757775
// A prvalue for an integral bit-field can be converted to a prvalue of type
@@ -8797,7 +8797,7 @@ static void EncodeBitField(const ASTContext *Ctx, std::string& S,
87978797
S += getObjCEncodingForPrimitiveType(Ctx, BT);
87988798
}
87998799
}
8800-
S += llvm::utostr(FD->getBitWidthValue(*Ctx));
8800+
S += llvm::utostr(FD->getBitWidthValue());
88018801
}
88028802

88038803
// Helper function for determining whether the encoded type string would include
@@ -9223,7 +9223,7 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
92239223
}
92249224

92259225
for (FieldDecl *Field : RDecl->fields()) {
9226-
if (!Field->isZeroLengthBitField(*this) && Field->isZeroSize(*this))
9226+
if (!Field->isZeroLengthBitField() && Field->isZeroSize(*this))
92279227
continue;
92289228
uint64_t offs = layout.getFieldOffset(Field->getFieldIndex());
92299229
FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs),
@@ -9320,7 +9320,7 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
93209320
if (field->isBitField()) {
93219321
EncodeBitField(this, S, field->getType(), field);
93229322
#ifndef NDEBUG
9323-
CurOffs += field->getBitWidthValue(*this);
9323+
CurOffs += field->getBitWidthValue();
93249324
#endif
93259325
} else {
93269326
QualType qt = field->getType();

clang/lib/AST/ByteCode/Interp.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,8 +1471,7 @@ bool InitThisBitField(InterpState &S, CodePtr OpPC, const Record::Field *F,
14711471
return false;
14721472
const Pointer &Field = This.atField(FieldOffset);
14731473
const auto &Value = S.Stk.pop<T>();
1474-
Field.deref<T>() =
1475-
Value.truncate(F->Decl->getBitWidthValue(S.getASTContext()));
1474+
Field.deref<T>() = Value.truncate(F->Decl->getBitWidthValue());
14761475
Field.initialize();
14771476
return true;
14781477
}
@@ -1495,8 +1494,7 @@ bool InitBitField(InterpState &S, CodePtr OpPC, const Record::Field *F) {
14951494
assert(F->isBitField());
14961495
const T &Value = S.Stk.pop<T>();
14971496
const Pointer &Field = S.Stk.peek<Pointer>().atField(F->Offset);
1498-
Field.deref<T>() =
1499-
Value.truncate(F->Decl->getBitWidthValue(S.getASTContext()));
1497+
Field.deref<T>() = Value.truncate(F->Decl->getBitWidthValue());
15001498
Field.activate();
15011499
Field.initialize();
15021500
return true;
@@ -1750,7 +1748,7 @@ bool StoreBitField(InterpState &S, CodePtr OpPC) {
17501748
if (Ptr.canBeInitialized())
17511749
Ptr.initialize();
17521750
if (const auto *FD = Ptr.getField())
1753-
Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue(S.getASTContext()));
1751+
Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue());
17541752
else
17551753
Ptr.deref<T>() = Value;
17561754
return true;
@@ -1765,7 +1763,7 @@ bool StoreBitFieldPop(InterpState &S, CodePtr OpPC) {
17651763
if (Ptr.canBeInitialized())
17661764
Ptr.initialize();
17671765
if (const auto *FD = Ptr.getField())
1768-
Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue(S.getASTContext()));
1766+
Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue());
17691767
else
17701768
Ptr.deref<T>() = Value;
17711769
return true;

clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ bool clang::interp::readPointerToBuffer(const Context &Ctx,
269269
Bits BitWidth = FullBitWidth;
270270

271271
if (const FieldDecl *FD = P.getField(); FD && FD->isBitField())
272-
BitWidth = Bits(std::min(FD->getBitWidthValue(ASTCtx),
272+
BitWidth = Bits(std::min(FD->getBitWidthValue(),
273273
(unsigned)FullBitWidth.getQuantity()));
274274
else if (T == PT_Bool && PackedBools)
275275
BitWidth = Bits(1);
@@ -301,8 +301,8 @@ bool clang::interp::readPointerToBuffer(const Context &Ctx,
301301
assert(NumBits.isFullByte());
302302
assert(NumBits.getQuantity() <= FullBitWidth.getQuantity());
303303
F.bitcastToMemory(Buff.get());
304-
// Now, only (maybe) swap the actual size of the float, excluding the
305-
// padding bits.
304+
// Now, only (maybe) swap the actual size of the float, excluding
305+
// the padding bits.
306306
if (llvm::sys::IsBigEndianHost)
307307
swapBytes(Buff.get(), NumBits.roundToBytes());
308308

@@ -406,7 +406,7 @@ bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr OpPC,
406406

407407
Bits BitWidth;
408408
if (const FieldDecl *FD = P.getField(); FD && FD->isBitField())
409-
BitWidth = Bits(std::min(FD->getBitWidthValue(ASTCtx),
409+
BitWidth = Bits(std::min(FD->getBitWidthValue(),
410410
(unsigned)FullBitWidth.getQuantity()));
411411
else if (T == PT_Bool && PackedBools)
412412
BitWidth = Bits(1);

clang/lib/AST/Decl.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4599,18 +4599,24 @@ void FieldDecl::setLazyInClassInitializer(LazyDeclStmtPtr NewInit) {
45994599
Init = NewInit;
46004600
}
46014601

4602-
unsigned FieldDecl::getBitWidthValue(const ASTContext &Ctx) const {
4602+
unsigned FieldDecl::getBitWidthValue() const {
46034603
assert(isBitField() && "not a bitfield");
4604-
return getBitWidth()->EvaluateKnownConstInt(Ctx).getZExtValue();
4604+
assert(isa<ConstantExpr>(getBitWidth()));
4605+
assert(cast<ConstantExpr>(getBitWidth())->hasAPValueResult());
4606+
assert(cast<ConstantExpr>(getBitWidth())->getAPValueResult().isInt());
4607+
return cast<ConstantExpr>(getBitWidth())
4608+
->getAPValueResult()
4609+
.getInt()
4610+
.getZExtValue();
46054611
}
46064612

4607-
bool FieldDecl::isZeroLengthBitField(const ASTContext &Ctx) const {
4613+
bool FieldDecl::isZeroLengthBitField() const {
46084614
return isUnnamedBitField() && !getBitWidth()->isValueDependent() &&
4609-
getBitWidthValue(Ctx) == 0;
4615+
getBitWidthValue() == 0;
46104616
}
46114617

46124618
bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
4613-
if (isZeroLengthBitField(Ctx))
4619+
if (isZeroLengthBitField())
46144620
return true;
46154621

46164622
// C++2a [intro.object]p7:

clang/lib/AST/DeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ void CXXRecordDecl::addedMember(Decl *D) {
993993
// C++ [meta.unary.prop]p4: [LWG2358]
994994
// T is a class type [...] with [...] no unnamed bit-fields of non-zero
995995
// length
996-
if (data().Empty && !Field->isZeroLengthBitField(Context) &&
996+
if (data().Empty && !Field->isZeroLengthBitField() &&
997997
Context.getLangOpts().getClangABICompat() >
998998
LangOptions::ClangABI::Ver6)
999999
data().Empty = false;

clang/lib/AST/Expr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ bool Expr::isKnownToHaveBooleanValue(bool Semantic) const {
196196

197197
if (const FieldDecl *FD = E->getSourceBitField())
198198
if (!Semantic && FD->getType()->isUnsignedIntegerType() &&
199-
!FD->getBitWidth()->isValueDependent() &&
200-
FD->getBitWidthValue(FD->getASTContext()) == 1)
199+
!FD->getBitWidth()->isValueDependent() && FD->getBitWidthValue() == 1)
201200
return true;
202201

203202
return false;

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,7 @@ static bool truncateBitfieldValue(EvalInfo &Info, const Expr *E,
28752875

28762876
APSInt &Int = Value.getInt();
28772877
unsigned OldBitWidth = Int.getBitWidth();
2878-
unsigned NewBitWidth = FD->getBitWidthValue(Info.Ctx);
2878+
unsigned NewBitWidth = FD->getBitWidthValue();
28792879
if (NewBitWidth < OldBitWidth)
28802880
Int = Int.trunc(NewBitWidth).extend(OldBitWidth);
28812881
return true;

clang/lib/AST/Randstruct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void randomizeStructureLayoutImpl(const ASTContext &Context,
9191
auto FieldIter = FieldsOut.begin();
9292
FieldDecl *FD = *FieldIter;
9393

94-
if (FD->isBitField() && !FD->isZeroLengthBitField(Context)) {
94+
if (FD->isBitField() && !FD->isZeroLengthBitField()) {
9595
// Start a bitfield run if this is the first bitfield we have found.
9696
if (!CurrentBitfieldRun)
9797
CurrentBitfieldRun = std::make_unique<BitfieldRunBucket>();

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ static bool isAIXLayout(const ASTContext &Context) {
15421542

15431543
void ItaniumRecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
15441544
bool FieldPacked = Packed || D->hasAttr<PackedAttr>();
1545-
uint64_t FieldSize = D->getBitWidthValue(Context);
1545+
uint64_t FieldSize = D->getBitWidthValue();
15461546
TypeInfo FieldInfo = Context.getTypeInfo(D->getType());
15471547
uint64_t StorageUnitSize = FieldInfo.Width;
15481548
unsigned FieldAlign = FieldInfo.Align;
@@ -3022,7 +3022,7 @@ void MicrosoftRecordLayoutBuilder::layoutField(const FieldDecl *FD) {
30223022
}
30233023

30243024
void MicrosoftRecordLayoutBuilder::layoutBitField(const FieldDecl *FD) {
3025-
unsigned Width = FD->getBitWidthValue(Context);
3025+
unsigned Width = FD->getBitWidthValue();
30263026
if (Width == 0) {
30273027
layoutZeroWidthBitField(FD);
30283028
return;
@@ -3692,7 +3692,7 @@ static void DumpRecordLayout(raw_ostream &OS, const RecordDecl *RD,
36923692
if (Field.isBitField()) {
36933693
uint64_t LocalFieldByteOffsetInBits = C.toBits(FieldOffset - Offset);
36943694
unsigned Begin = LocalFieldOffsetInBits - LocalFieldByteOffsetInBits;
3695-
unsigned Width = Field.getBitWidthValue(C);
3695+
unsigned Width = Field.getBitWidthValue();
36963696
PrintBitFieldOffset(OS, FieldOffset, Begin, Width, IndentLevel);
36973697
} else {
36983698
PrintOffset(OS, FieldOffset, IndentLevel);

clang/lib/CodeGen/ABIInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool ABIInfo::isHomogeneousAggregate(QualType Ty, const Type *&Base,
106106
continue;
107107

108108
if (isZeroLengthBitfieldPermittedInHomogeneousAggregate() &&
109-
FD->isZeroLengthBitField(getContext()))
109+
FD->isZeroLengthBitField())
110110
continue;
111111

112112
uint64_t FldMembers;

clang/lib/CodeGen/ABIInfoImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ bool CodeGen::isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,
303303

304304
bool CodeGen::isEmptyFieldForLayout(const ASTContext &Context,
305305
const FieldDecl *FD) {
306-
if (FD->isZeroLengthBitField(Context))
306+
if (FD->isZeroLengthBitField())
307307
return true;
308308

309309
if (FD->isUnnamedBitField())

clang/lib/CodeGen/CGCall.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ getTypeExpansion(QualType Ty, const ASTContext &Context) {
954954
CharUnits UnionSize = CharUnits::Zero();
955955

956956
for (const auto *FD : RD->fields()) {
957-
if (FD->isZeroLengthBitField(Context))
957+
if (FD->isZeroLengthBitField())
958958
continue;
959959
assert(!FD->isBitField() &&
960960
"Cannot expand structure with bit-field members.");
@@ -974,7 +974,7 @@ getTypeExpansion(QualType Ty, const ASTContext &Context) {
974974
}
975975

976976
for (const auto *FD : RD->fields()) {
977-
if (FD->isZeroLengthBitField(Context))
977+
if (FD->isZeroLengthBitField())
978978
continue;
979979
assert(!FD->isBitField() &&
980980
"Cannot expand structure with bit-field members.");
@@ -3682,7 +3682,7 @@ static void setUsedBits(CodeGenModule &CGM, const RecordType *RTy, int Offset,
36823682
for (auto I = RD->field_begin(), E = RD->field_end(); I != E; ++I, ++Idx) {
36833683
const FieldDecl *F = *I;
36843684

3685-
if (F->isUnnamedBitField() || F->isZeroLengthBitField(Context) ||
3685+
if (F->isUnnamedBitField() || F->isZeroLengthBitField() ||
36863686
F->getType()->isIncompleteArrayType())
36873687
continue;
36883688

clang/lib/CodeGen/CGClass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ namespace {
945945
ASTContext &Ctx = CGF.getContext();
946946
unsigned LastFieldSize =
947947
LastField->isBitField()
948-
? LastField->getBitWidthValue(Ctx)
948+
? LastField->getBitWidthValue()
949949
: Ctx.toBits(
950950
Ctx.getTypeInfoDataSizeInChars(LastField->getType()).Width);
951951
uint64_t MemcpySizeBits = LastFieldOffset + LastFieldSize -

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,8 +1721,7 @@ llvm::DIDerivedType *CGDebugInfo::createBitFieldSeparatorIfNeeded(
17211721

17221722
assert(PreviousBitfield->isBitField());
17231723

1724-
ASTContext &Context = CGM.getContext();
1725-
if (!PreviousBitfield->isZeroLengthBitField(Context))
1724+
if (!PreviousBitfield->isZeroLengthBitField())
17261725
return nullptr;
17271726

17281727
QualType Ty = PreviousBitfield->getType();
@@ -3214,9 +3213,8 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const ObjCInterfaceType *Ty,
32143213
if (!FType->isIncompleteArrayType()) {
32153214

32163215
// Bit size, align and offset of the type.
3217-
FieldSize = Field->isBitField()
3218-
? Field->getBitWidthValue(CGM.getContext())
3219-
: CGM.getContext().getTypeSize(FType);
3216+
FieldSize = Field->isBitField() ? Field->getBitWidthValue()
3217+
: CGM.getContext().getTypeSize(FType);
32203218
FieldAlign = getTypeAlignIfRequired(FType, CGM.getContext());
32213219
}
32223220

clang/lib/CodeGen/CGNonTrivialStruct.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace CodeGen;
2525
static uint64_t getFieldSize(const FieldDecl *FD, QualType FT,
2626
ASTContext &Ctx) {
2727
if (FD && FD->isBitField())
28-
return FD->getBitWidthValue(Ctx);
28+
return FD->getBitWidthValue();
2929
return Ctx.getTypeSize(FT);
3030
}
3131

@@ -255,7 +255,7 @@ struct GenBinaryFuncName : CopyStructVisitor<GenBinaryFuncName<IsMove>, IsMove>,
255255
void visitVolatileTrivial(QualType FT, const FieldDecl *FD,
256256
CharUnits CurStructOffset) {
257257
// Zero-length bit-fields don't need to be copied/assigned.
258-
if (FD && FD->isZeroLengthBitField(this->Ctx))
258+
if (FD && FD->isZeroLengthBitField())
259259
return;
260260

261261
// Because volatile fields can be bit-fields and are individually copied,
@@ -544,7 +544,7 @@ struct GenBinaryFunc : CopyStructVisitor<Derived, IsMove>,
544544
LValue DstLV, SrcLV;
545545
if (FD) {
546546
// No need to copy zero-length bit-fields.
547-
if (FD->isZeroLengthBitField(this->CGF->getContext()))
547+
if (FD->isZeroLengthBitField())
548548
return;
549549

550550
QualType RT = QualType(FD->getParent()->getTypeForDecl(), 0);

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,8 +2543,7 @@ void CGObjCCommonMac::BuildRCRecordLayout(const llvm::StructLayout *RecLayout,
25432543
if (LastFieldBitfieldOrUnnamed) {
25442544
if (LastFieldBitfieldOrUnnamed->isBitField()) {
25452545
// Last field was a bitfield. Must update the info.
2546-
uint64_t BitFieldSize
2547-
= LastFieldBitfieldOrUnnamed->getBitWidthValue(CGM.getContext());
2546+
uint64_t BitFieldSize = LastFieldBitfieldOrUnnamed->getBitWidthValue();
25482547
unsigned UnsSize = (BitFieldSize / ByteSizeInBits) +
25492548
((BitFieldSize % ByteSizeInBits) != 0);
25502549
CharUnits Size = CharUnits::fromQuantity(UnsSize);

clang/lib/CodeGen/CGObjCRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
8989
CGF.CGM.getContext().lookupFieldBitOffset(OID, nullptr, Ivar);
9090
uint64_t BitOffset = FieldBitOffset % CGF.CGM.getContext().getCharWidth();
9191
uint64_t AlignmentBits = CGF.CGM.getTarget().getCharAlign();
92-
uint64_t BitFieldSize = Ivar->getBitWidthValue(CGF.getContext());
92+
uint64_t BitFieldSize = Ivar->getBitWidthValue();
9393
CharUnits StorageSize = CGF.CGM.getContext().toCharUnitsFromBits(
9494
llvm::alignTo(BitOffset + BitFieldSize, AlignmentBits));
9595
CharUnits Alignment = CGF.CGM.getContext().toCharUnitsFromBits(AlignmentBits);

0 commit comments

Comments
 (0)