Skip to content

Commit 57caaa6

Browse files
committed
[clang] Format bitfield width diagnostics with thousands-separators
1 parent 6f16a8b commit 57caaa6

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6400,7 +6400,7 @@ def err_incorrect_number_of_vector_initializers : Error<
64006400
// Used by C++ which allows bit-fields that are wider than the type.
64016401
def warn_bitfield_width_exceeds_type_width: Warning<
64026402
"width of bit-field %0 (%1 bits) exceeds the width of its type; value will "
6403-
"be truncated to %2 bit%s2">, InGroup<BitFieldWidth>;
6403+
"be truncated to %2 bits">, InGroup<BitFieldWidth>;
64046404
def err_bitfield_too_wide : Error<
64056405
"%select{bit-field %1|anonymous bit-field}0 is too wide (%2 bits)">;
64066406
def warn_bitfield_too_small_for_enum : Warning<

clang/lib/Sema/SemaDecl.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18307,16 +18307,22 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
1830718307
if (Value.isSigned() && Value.isNegative()) {
1830818308
if (FieldName)
1830918309
return Diag(FieldLoc, diag::err_bitfield_has_negative_width)
18310-
<< FieldName << toString(Value, 10);
18310+
<< FieldName
18311+
<< toString(Value, 10, Value.isSigned(),
18312+
/*formatAsCLiteral=*/false, /*UpperCase=*/true,
18313+
/*InsertSeparators=*/true);
1831118314
return Diag(FieldLoc, diag::err_anon_bitfield_has_negative_width)
18312-
<< toString(Value, 10);
18315+
<< toString(Value, 10, Value.isSigned(), /*formatAsCLiteral=*/false,
18316+
/*UpperCase=*/true, /*InsertSeparators=*/true);
1831318317
}
1831418318

1831518319
// The size of the bit-field must not exceed our maximum permitted object
1831618320
// size.
1831718321
if (Value.getActiveBits() > ConstantArrayType::getMaxSizeBits(Context)) {
1831818322
return Diag(FieldLoc, diag::err_bitfield_too_wide)
18319-
<< !FieldName << FieldName << toString(Value, 10);
18323+
<< !FieldName << FieldName
18324+
<< toString(Value, 10, Value.isSigned(), /*formatAsCLiteral=*/false,
18325+
/*UpperCase=*/true, /*InsertSeparators=*/true);
1832018326
}
1832118327

1832218328
if (!FieldTy->isDependentType()) {
@@ -18335,17 +18341,26 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
1833518341
unsigned DiagWidth =
1833618342
CStdConstraintViolation ? TypeWidth : TypeStorageSize;
1833718343
return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
18338-
<< (bool)FieldName << FieldName << toString(Value, 10)
18344+
<< (bool)FieldName << FieldName
18345+
<< toString(Value, 10, Value.isSigned(),
18346+
/*formatAsCLiteral=*/false, /*UpperCase=*/true,
18347+
/*InsertSeparators=*/true)
1833918348
<< !CStdConstraintViolation << DiagWidth;
1834018349
}
1834118350

1834218351
// Warn on types where the user might conceivably expect to get all
1834318352
// specified bits as value bits: that's all integral types other than
1834418353
// 'bool'.
1834518354
if (BitfieldIsOverwide && !FieldTy->isBooleanType() && FieldName) {
18355+
llvm::APInt TypeWidthAP(sizeof(TypeWidth) * 8, TypeWidth,
18356+
/*IsSigned=*/false);
1834618357
Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width)
18347-
<< FieldName << toString(Value, 10)
18348-
<< (unsigned)TypeWidth;
18358+
<< FieldName
18359+
<< toString(Value, 10, Value.isSigned(), /*formatAsCLiteral=*/false,
18360+
/*UpperCase=*/true, /*InsertSeparators=*/true)
18361+
<< toString(TypeWidthAP, 10, /*Signed=*/false,
18362+
/*formatAsCLiteral=*/false, /*UpperCase=*/true,
18363+
/*InsertSeparators=*/true);
1834918364
}
1835018365
}
1835118366

0 commit comments

Comments
 (0)