Skip to content

Commit a28b252

Browse files
Use APInt::getSignificantBits instead of APInt::getMinSignedBits (NFC)
Note that getMinSignedBits has been soft-deprecated in favor of getSignificantBits.
1 parent 2dfa957 commit a28b252

30 files changed

+64
-63
lines changed

clang-tools-extra/clangd/Hover.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D,
396396
// -2^32 => 0xfffffffeffffffff
397397
static llvm::FormattedNumber printHex(const llvm::APSInt &V) {
398398
uint64_t Bits = V.getExtValue();
399-
if (V.isNegative() && V.getMinSignedBits() <= 32)
399+
if (V.isNegative() && V.getSignificantBits() <= 32)
400400
return llvm::format_hex(uint32_t(Bits), 0);
401401
return llvm::format_hex(Bits, 0);
402402
}
@@ -430,7 +430,7 @@ std::optional<std::string> printExprValue(const Expr *E,
430430

431431
// Show enums symbolically, not numerically like APValue::printPretty().
432432
if (T->isEnumeralType() && Constant.Val.isInt() &&
433-
Constant.Val.getInt().getMinSignedBits() <= 64) {
433+
Constant.Val.getInt().getSignificantBits() <= 64) {
434434
// Compare to int64_t to avoid bit-width match requirements.
435435
int64_t Val = Constant.Val.getInt().getExtValue();
436436
for (const EnumConstantDecl *ECD :
@@ -442,7 +442,7 @@ std::optional<std::string> printExprValue(const Expr *E,
442442
}
443443
// Show hex value of integers if they're at least 10 (or negative!)
444444
if (T->isIntegralOrEnumerationType() && Constant.Val.isInt() &&
445-
Constant.Val.getInt().getMinSignedBits() <= 64 &&
445+
Constant.Val.getInt().getSignificantBits() <= 64 &&
446446
Constant.Val.getInt().uge(10))
447447
return llvm::formatv("{0} ({1})", Constant.Val.getAsString(Ctx, T),
448448
printHex(Constant.Val.getInt()))

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12008,7 +12008,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1200812008
if (!EvaluateInteger(E->getArg(0), Val, Info))
1200912009
return false;
1201012010

12011-
return Success(Val.getBitWidth() - Val.getMinSignedBits(), E);
12011+
return Success(Val.getBitWidth() - Val.getSignificantBits(), E);
1201212012
}
1201312013

1201412014
case Builtin::BI__builtin_clz:

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12456,7 +12456,7 @@ struct IntRange {
1245612456
static IntRange GetValueRange(ASTContext &C, llvm::APSInt &value,
1245712457
unsigned MaxWidth) {
1245812458
if (value.isSigned() && value.isNegative())
12459-
return IntRange(value.getMinSignedBits(), false);
12459+
return IntRange(value.getSignificantBits(), false);
1246012460

1246112461
if (value.getBitWidth() > MaxWidth)
1246212462
value = value.trunc(MaxWidth);
@@ -13373,7 +13373,7 @@ static bool AnalyzeBitFieldAssignment(Sema &S, FieldDecl *Bitfield, Expr *Init,
1337313373
if (!Value.isSigned() || Value.isNegative())
1337413374
if (UnaryOperator *UO = dyn_cast<UnaryOperator>(OriginalInit))
1337513375
if (UO->getOpcode() == UO_Minus || UO->getOpcode() == UO_Not)
13376-
OriginalWidth = Value.getMinSignedBits();
13376+
OriginalWidth = Value.getSignificantBits();
1337713377

1337813378
if (OriginalWidth <= FieldWidth)
1337913379
return false;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19060,7 +19060,7 @@ static bool isRepresentableIntegerValue(ASTContext &Context,
1906019060
--BitWidth;
1906119061
return Value.getActiveBits() <= BitWidth;
1906219062
}
19063-
return Value.getMinSignedBits() <= BitWidth;
19063+
return Value.getSignificantBits() <= BitWidth;
1906419064
}
1906519065

1906619066
// Given an integral type, return the next larger integral type
@@ -19595,8 +19595,8 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
1959519595
unsigned ActiveBits = InitVal.getActiveBits();
1959619596
NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
1959719597
} else {
19598-
NumNegativeBits = std::max(NumNegativeBits,
19599-
(unsigned)InitVal.getMinSignedBits());
19598+
NumNegativeBits =
19599+
std::max(NumNegativeBits, (unsigned)InitVal.getSignificantBits());
1960019600
}
1960119601
}
1960219602

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10502,7 +10502,7 @@ static bool canConvertIntToOtherIntTy(Sema &S, ExprResult *Int,
1050210502
// bits that the vector element type, reject it.
1050310503
llvm::APSInt Result = EVResult.Val.getInt();
1050410504
unsigned NumBits = IntSigned
10505-
? (Result.isNegative() ? Result.getMinSignedBits()
10505+
? (Result.isNegative() ? Result.getSignificantBits()
1050610506
: Result.getActiveBits())
1050710507
: Result.getActiveBits();
1050810508
if (Order < 0 && S.Context.getIntWidth(OtherIntTy) < NumBits)
@@ -11745,7 +11745,7 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS,
1174511745
}
1174611746

1174711747
llvm::APInt ResultBits =
11748-
static_cast<llvm::APInt&>(Right) + Left.getMinSignedBits();
11748+
static_cast<llvm::APInt &>(Right) + Left.getSignificantBits();
1174911749
if (LeftBits.uge(ResultBits))
1175011750
return;
1175111751
llvm::APSInt Result = Left.extend(ResultBits.getLimitedValue());
@@ -11768,9 +11768,9 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS,
1176811768
}
1176911769

1177011770
S.Diag(Loc, diag::warn_shift_result_gt_typewidth)
11771-
<< HexResult.str() << Result.getMinSignedBits() << LHSType
11772-
<< Left.getBitWidth() << LHS.get()->getSourceRange()
11773-
<< RHS.get()->getSourceRange();
11771+
<< HexResult.str() << Result.getSignificantBits() << LHSType
11772+
<< Left.getBitWidth() << LHS.get()->getSourceRange()
11773+
<< RHS.get()->getSourceRange();
1177411774
}
1177511775

1177611776
/// Return the resulting type when a vector is shifted

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7521,7 +7521,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
75217521
else if (OldValue.isUnsigned())
75227522
RequiredBits = OldValue.getActiveBits() + 1;
75237523
else
7524-
RequiredBits = OldValue.getMinSignedBits();
7524+
RequiredBits = OldValue.getSignificantBits();
75257525
if (RequiredBits > AllowedBits) {
75267526
Diag(Arg->getBeginLoc(), diag::warn_template_arg_too_large)
75277527
<< toString(OldValue, 10) << toString(Value, 10) << Param->getType()

clang/lib/StaticAnalyzer/Core/APSIntType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ APSIntType::testInRange(const llvm::APSInt &Value,
2323
unsigned MinBits;
2424
if (AllowSignConversions) {
2525
if (Value.isSigned() && !IsUnsigned)
26-
MinBits = Value.getMinSignedBits();
26+
MinBits = Value.getSignificantBits();
2727
else
2828
MinBits = Value.getActiveBits();
2929

@@ -33,7 +33,7 @@ APSIntType::testInRange(const llvm::APSInt &Value,
3333
// Unsigned integers can be converted to unsigned integers of the same width
3434
// or signed integers with one more bit.
3535
if (Value.isSigned())
36-
MinBits = Value.getMinSignedBits() - IsUnsigned;
36+
MinBits = Value.getSignificantBits() - IsUnsigned;
3737
else
3838
MinBits = Value.getActiveBits() + !IsUnsigned;
3939
}

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ class TargetTransformInfoImplBase {
887887
bool signedElement = IntElement->getValue().isNegative();
888888
// Get the element min required size.
889889
unsigned ElementMinRequiredSize =
890-
IntElement->getValue().getMinSignedBits() - 1;
890+
IntElement->getValue().getSignificantBits() - 1;
891891
// In case one element is signed then all the vector is signed.
892892
isSigned |= signedElement;
893893
// Save the max required bit size between all the elements.
@@ -902,7 +902,7 @@ class TargetTransformInfoImplBase {
902902

903903
if (const auto *CI = dyn_cast<ConstantInt>(Val)) {
904904
isSigned = CI->getValue().isNegative();
905-
return CI->getValue().getMinSignedBits() - 1;
905+
return CI->getValue().getSignificantBits() - 1;
906906
}
907907

908908
if (const auto *Cast = dyn_cast<SExtInst>(Val)) {

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ class SelectionDAG {
10601060

10611061
/// Return a node that represents the runtime scaling 'MulImm * RuntimeVL'.
10621062
SDValue getVScale(const SDLoc &DL, EVT VT, APInt MulImm) {
1063-
assert(MulImm.getMinSignedBits() <= VT.getSizeInBits() &&
1063+
assert(MulImm.getSignificantBits() <= VT.getSizeInBits() &&
10641064
"Immediate does not fit VT");
10651065
return getNode(ISD::VSCALE, DL, VT,
10661066
getConstant(MulImm.sextOrTrunc(VT.getSizeInBits()), DL, VT));

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ Constant *llvm::ConstantFoldLoadFromConst(Constant *C, Type *Ty,
713713
return Result;
714714

715715
// Try hard to fold loads from bitcasted strange and non-type-safe things.
716-
if (Offset.getMinSignedBits() <= 64)
716+
if (Offset.getSignificantBits() <= 64)
717717
if (Constant *Result =
718718
FoldReinterpretLoadFromConst(C, Ty, Offset.getSExtValue(), DL))
719719
return Result;

0 commit comments

Comments
 (0)