Skip to content

Commit 82dbb1b

Browse files
committed
Fix the clang-tidy build after get/isIntegerConstantExpression
refactoring.
1 parent 074b121 commit 82dbb1b

4 files changed

Lines changed: 28 additions & 20 deletions

File tree

‎clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ static QualType getUnqualifiedType(const Expr &E) {
7979
}
8080

8181
static APValue getConstantExprValue(const ASTContext &Ctx, const Expr &E) {
82-
llvm::APSInt IntegerConstant;
83-
if (E.isIntegerConstantExpr(IntegerConstant, Ctx))
84-
return APValue(IntegerConstant);
82+
if (auto IntegerConstant = E.getIntegerConstantExpr(Ctx))
83+
return APValue(*IntegerConstant);
8584
APValue Constant;
8685
if (Ctx.getLangOpts().CPlusPlus && E.isCXX11ConstantExpr(Ctx, &Constant))
8786
return Constant;

‎clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ void ProBoundsConstantArrayIndexCheck::check(
6565
if (IndexExpr->isValueDependent())
6666
return; // We check in the specialization.
6767

68-
llvm::APSInt Index;
69-
if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr,
70-
/*isEvaluated=*/true)) {
68+
Optional<llvm::APSInt> Index =
69+
IndexExpr->getIntegerConstantExpr(*Result.Context);
70+
if (!Index) {
7171
SourceRange BaseRange;
7272
if (const auto *ArraySubscriptE = dyn_cast<ArraySubscriptExpr>(Matched))
7373
BaseRange = ArraySubscriptE->getBase()->getSourceRange();
@@ -101,9 +101,9 @@ void ProBoundsConstantArrayIndexCheck::check(
101101
if (!StdArrayDecl)
102102
return;
103103

104-
if (Index.isSigned() && Index.isNegative()) {
104+
if (Index->isSigned() && Index->isNegative()) {
105105
diag(Matched->getExprLoc(), "std::array<> index %0 is negative")
106-
<< Index.toString(10);
106+
<< Index->toString(10);
107107
return;
108108
}
109109

@@ -118,11 +118,11 @@ void ProBoundsConstantArrayIndexCheck::check(
118118

119119
// Get uint64_t values, because different bitwidths would lead to an assertion
120120
// in APInt::uge.
121-
if (Index.getZExtValue() >= ArraySize.getZExtValue()) {
121+
if (Index->getZExtValue() >= ArraySize.getZExtValue()) {
122122
diag(Matched->getExprLoc(),
123123
"std::array<> index %0 is past the end of the array "
124124
"(which contains %1 elements)")
125-
<< Index.toString(10) << ArraySize.toString(10, false);
125+
<< Index->toString(10) << ArraySize.toString(10, false);
126126
}
127127
}
128128

‎clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,13 @@ static bool retrieveIntegerConstantExpr(const MatchFinder::MatchResult &Result,
500500
const Expr *&ConstExpr) {
501501
std::string CstId = (Id + "-const").str();
502502
ConstExpr = Result.Nodes.getNodeAs<Expr>(CstId);
503-
return ConstExpr && ConstExpr->isIntegerConstantExpr(Value, *Result.Context);
503+
if (!ConstExpr)
504+
return false;
505+
Optional<llvm::APSInt> R = ConstExpr->getIntegerConstantExpr(*Result.Context);
506+
if (!R)
507+
return false;
508+
Value = *R;
509+
return true;
504510
}
505511

506512
// Overloaded `retrieveIntegerConstantExpr` for compatibility.
@@ -673,7 +679,7 @@ static bool retrieveRelationalIntegerConstantExpr(
673679

674680
if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
675681
if (!Arg->isValueDependent() &&
676-
!Arg->isIntegerConstantExpr(Value, *Result.Context))
682+
!Arg->isIntegerConstantExpr(*Result.Context))
677683
return false;
678684
}
679685
Symbol = OverloadedOperatorExpr->getArg(0);
@@ -1265,21 +1271,23 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
12651271
"left-right-shift-confusion")) {
12661272
const auto *ShiftingConst = Result.Nodes.getNodeAs<Expr>("shift-const");
12671273
assert(ShiftingConst && "Expr* 'ShiftingConst' is nullptr!");
1268-
APSInt ShiftingValue;
1274+
Optional<llvm::APSInt> ShiftingValue =
1275+
ShiftingConst->getIntegerConstantExpr(*Result.Context);
12691276

1270-
if (!ShiftingConst->isIntegerConstantExpr(ShiftingValue, *Result.Context))
1277+
if (!ShiftingValue)
12711278
return;
12721279

12731280
const auto *AndConst = Result.Nodes.getNodeAs<Expr>("and-const");
12741281
assert(AndConst && "Expr* 'AndCont' is nullptr!");
1275-
APSInt AndValue;
1276-
if (!AndConst->isIntegerConstantExpr(AndValue, *Result.Context))
1282+
Optional<llvm::APSInt> AndValue =
1283+
AndConst->getIntegerConstantExpr(*Result.Context);
1284+
if (!AndValue)
12771285
return;
12781286

12791287
// If ShiftingConst is shifted left with more bits than the position of the
12801288
// leftmost 1 in the bit representation of AndValue, AndConstant is
12811289
// ineffective.
1282-
if (AndValue.getActiveBits() > ShiftingValue)
1290+
if (AndValue->getActiveBits() > *ShiftingValue)
12831291
return;
12841292

12851293
auto Diag = diag(BinaryAndExpr->getOperatorLoc(),

‎clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,12 @@ static bool arrayMatchesBoundExpr(ASTContext *Context,
438438
Context->getAsConstantArrayType(ArrayType);
439439
if (!ConstType)
440440
return false;
441-
llvm::APSInt ConditionSize;
442-
if (!ConditionExpr->isIntegerConstantExpr(ConditionSize, *Context))
441+
Optional<llvm::APSInt> ConditionSize =
442+
ConditionExpr->getIntegerConstantExpr(*Context);
443+
if (!ConditionSize)
443444
return false;
444445
llvm::APSInt ArraySize(ConstType->getSize());
445-
return llvm::APSInt::isSameValue(ConditionSize, ArraySize);
446+
return llvm::APSInt::isSameValue(*ConditionSize, ArraySize);
446447
}
447448

448449
ForLoopIndexUseVisitor::ForLoopIndexUseVisitor(ASTContext *Context,

0 commit comments

Comments
 (0)