Skip to content

Commit cb339e1

Browse files
committed
Mention requirements in FieldDecl::getBitwidthValue()
1 parent 3cb7e31 commit cb339e1

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,6 +3143,8 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
31433143

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

31483150
/// Set the bit-field width for this member.

clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr OpPC,
380380

381381
Bits BitWidth;
382382
if (const FieldDecl *FD = P.getField(); FD && FD->isBitField())
383-
BitWidth = Bits(std::min(FD->getBitWidthValue(ASTCtx),
383+
BitWidth = Bits(std::min(FD->getBitWidthValue(),
384384
(unsigned)FullBitWidth.getQuantity()));
385385
else if (T == PT_Bool && PackedBools)
386386
BitWidth = Bits(1);

clang/lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,6 +4603,7 @@ unsigned FieldDecl::getBitWidthValue() const {
46034603
assert(isBitField() && "not a bitfield");
46044604
assert(isa<ConstantExpr>(getBitWidth()));
46054605
assert(cast<ConstantExpr>(getBitWidth())->hasAPValueResult());
4606+
assert(cast<ConstantExpr>(getBitWidth())->getAPValueResult().isInt());
46064607
return cast<ConstantExpr>(getBitWidth())
46074608
->getAPValueResult()
46084609
.getInt()

0 commit comments

Comments
 (0)