Skip to content

Commit 59bdea2

Browse files
committed
Revert "[clang] Avoid re-evaluating field bitwidth (#117732)"
This reverts commit 81fc3ad. This breaks some LLDB tests, e.g. SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp: lldb: ../llvm-project/clang/lib/AST/Decl.cpp:4604: unsigned int clang::FieldDecl::getBitWidthValue() const: Assertion `isa<ConstantExpr>(getBitWidth())' failed.
1 parent 346fad5 commit 59bdea2

38 files changed

+94
-96
lines changed

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

+1-1
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();
41+
unsigned CurrentBitWidth = Node.getBitWidthValue(Ctx);
4242
return IntBitWidth == CurrentBitWidth;
4343
}
4444

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

+1-1
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();
127+
unsigned BitFieldWidth = BitField->getBitWidthValue(Context);
128128
return {BitFieldWidth - SignedBits, BitFieldWidth};
129129
}
130130

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

+1-1
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());
163+
return twoPow(BitfieldDecl->getBitWidthValue(*Result.Context));
164164
}
165165

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

clang-tools-extra/clangd/Hover.cpp

+1-1
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();
1021+
HI.Size = FD->getBitWidthValue(Ctx);
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

+2-4
Original file line numberDiff line numberDiff line change
@@ -3142,9 +3142,7 @@ 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-
/// 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;
3145+
unsigned getBitWidthValue(const ASTContext &Ctx) const;
31483146

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

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

clang/include/clang/ASTMatchers/ASTMatchers.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ 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() && Node.getBitWidthValue() == Width;
711+
return Node.isBitField() &&
712+
Node.getBitWidthValue(Finder->getASTContext()) == Width;
712713
}
713714

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

clang/lib/AST/ASTContext.cpp

+5-5
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();
2798+
int64_t BitfieldSize = Field->getBitWidthValue(Context);
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();
7772+
uint64_t BitWidth = Field->getBitWidthValue(*this);
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());
8800+
S += llvm::utostr(FD->getBitWidthValue(*Ctx));
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() && Field->isZeroSize(*this))
9226+
if (!Field->isZeroLengthBitField(*this) && 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();
9323+
CurOffs += field->getBitWidthValue(*this);
93249324
#endif
93259325
} else {
93269326
QualType qt = field->getType();

clang/lib/AST/ByteCode/Interp.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,8 @@ 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>() = Value.truncate(F->Decl->getBitWidthValue());
1474+
Field.deref<T>() =
1475+
Value.truncate(F->Decl->getBitWidthValue(S.getASTContext()));
14751476
Field.initialize();
14761477
return true;
14771478
}
@@ -1494,7 +1495,8 @@ bool InitBitField(InterpState &S, CodePtr OpPC, const Record::Field *F) {
14941495
assert(F->isBitField());
14951496
const T &Value = S.Stk.pop<T>();
14961497
const Pointer &Field = S.Stk.peek<Pointer>().atField(F->Offset);
1497-
Field.deref<T>() = Value.truncate(F->Decl->getBitWidthValue());
1498+
Field.deref<T>() =
1499+
Value.truncate(F->Decl->getBitWidthValue(S.getASTContext()));
14981500
Field.activate();
14991501
Field.initialize();
15001502
return true;
@@ -1748,7 +1750,7 @@ bool StoreBitField(InterpState &S, CodePtr OpPC) {
17481750
if (Ptr.canBeInitialized())
17491751
Ptr.initialize();
17501752
if (const auto *FD = Ptr.getField())
1751-
Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue());
1753+
Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue(S.getASTContext()));
17521754
else
17531755
Ptr.deref<T>() = Value;
17541756
return true;
@@ -1763,7 +1765,7 @@ bool StoreBitFieldPop(InterpState &S, CodePtr OpPC) {
17631765
if (Ptr.canBeInitialized())
17641766
Ptr.initialize();
17651767
if (const auto *FD = Ptr.getField())
1766-
Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue());
1768+
Ptr.deref<T>() = Value.truncate(FD->getBitWidthValue(S.getASTContext()));
17671769
else
17681770
Ptr.deref<T>() = Value;
17691771
return true;

clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp

+4-4
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(),
272+
BitWidth = Bits(std::min(FD->getBitWidthValue(ASTCtx),
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
305-
// the padding bits.
304+
// Now, only (maybe) swap the actual size of the float, excluding the
305+
// 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(),
409+
BitWidth = Bits(std::min(FD->getBitWidthValue(ASTCtx),
410410
(unsigned)FullBitWidth.getQuantity()));
411411
else if (T == PT_Bool && PackedBools)
412412
BitWidth = Bits(1);

clang/lib/AST/Decl.cpp

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

4602-
unsigned FieldDecl::getBitWidthValue() const {
4602+
unsigned FieldDecl::getBitWidthValue(const ASTContext &Ctx) const {
46034603
assert(isBitField() && "not a bitfield");
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();
4604+
return getBitWidth()->EvaluateKnownConstInt(Ctx).getZExtValue();
46114605
}
46124606

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

46184612
bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
4619-
if (isZeroLengthBitField())
4613+
if (isZeroLengthBitField(Ctx))
46204614
return true;
46214615

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

clang/lib/AST/DeclCXX.cpp

+1-1
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() &&
996+
if (data().Empty && !Field->isZeroLengthBitField(Context) &&
997997
Context.getLangOpts().getClangABICompat() >
998998
LangOptions::ClangABI::Ver6)
999999
data().Empty = false;

clang/lib/AST/Expr.cpp

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

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

202203
return false;

clang/lib/AST/ExprConstant.cpp

+1-1
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();
2878+
unsigned NewBitWidth = FD->getBitWidthValue(Info.Ctx);
28792879
if (NewBitWidth < OldBitWidth)
28802880
Int = Int.trunc(NewBitWidth).extend(OldBitWidth);
28812881
return true;

clang/lib/AST/Randstruct.cpp

+1-1
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()) {
94+
if (FD->isBitField() && !FD->isZeroLengthBitField(Context)) {
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

+3-3
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();
1545+
uint64_t FieldSize = D->getBitWidthValue(Context);
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();
3025+
unsigned Width = FD->getBitWidthValue(Context);
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();
3695+
unsigned Width = Field.getBitWidthValue(C);
36963696
PrintBitFieldOffset(OS, FieldOffset, Begin, Width, IndentLevel);
36973697
} else {
36983698
PrintOffset(OS, FieldOffset, IndentLevel);

clang/lib/CodeGen/ABIInfo.cpp

+1-1
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())
109+
FD->isZeroLengthBitField(getContext()))
110110
continue;
111111

112112
uint64_t FldMembers;

clang/lib/CodeGen/ABIInfoImpl.cpp

+1-1
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())
306+
if (FD->isZeroLengthBitField(Context))
307307
return true;
308308

309309
if (FD->isUnnamedBitField())

clang/lib/CodeGen/CGCall.cpp

+3-3
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())
957+
if (FD->isZeroLengthBitField(Context))
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())
977+
if (FD->isZeroLengthBitField(Context))
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() ||
3685+
if (F->isUnnamedBitField() || F->isZeroLengthBitField(Context) ||
36863686
F->getType()->isIncompleteArrayType())
36873687
continue;
36883688

clang/lib/CodeGen/CGClass.cpp

+1-1
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()
948+
? LastField->getBitWidthValue(Ctx)
949949
: Ctx.toBits(
950950
Ctx.getTypeInfoDataSizeInChars(LastField->getType()).Width);
951951
uint64_t MemcpySizeBits = LastFieldOffset + LastFieldSize -

clang/lib/CodeGen/CGDebugInfo.cpp

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

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

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

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

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

clang/lib/CodeGen/CGNonTrivialStruct.cpp

+3-3
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();
28+
return FD->getBitWidthValue(Ctx);
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())
258+
if (FD && FD->isZeroLengthBitField(this->Ctx))
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())
547+
if (FD->isZeroLengthBitField(this->CGF->getContext()))
548548
return;
549549

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

clang/lib/CodeGen/CGObjCMac.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,8 @@ 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 = LastFieldBitfieldOrUnnamed->getBitWidthValue();
2546+
uint64_t BitFieldSize
2547+
= LastFieldBitfieldOrUnnamed->getBitWidthValue(CGM.getContext());
25472548
unsigned UnsSize = (BitFieldSize / ByteSizeInBits) +
25482549
((BitFieldSize % ByteSizeInBits) != 0);
25492550
CharUnits Size = CharUnits::fromQuantity(UnsSize);

clang/lib/CodeGen/CGObjCRuntime.cpp

+1-1
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();
92+
uint64_t BitFieldSize = Ivar->getBitWidthValue(CGF.getContext());
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)