Fix the clang-tidy build after get/isIntegerConstantExpression

refactoring.
This commit is contained in:
Haojian Wu 2020-07-22 09:37:51 +02:00
parent 074b121642
commit 82dbb1b2b4
4 changed files with 28 additions and 20 deletions

View File

@ -79,9 +79,8 @@ static QualType getUnqualifiedType(const Expr &E) {
}
static APValue getConstantExprValue(const ASTContext &Ctx, const Expr &E) {
llvm::APSInt IntegerConstant;
if (E.isIntegerConstantExpr(IntegerConstant, Ctx))
return APValue(IntegerConstant);
if (auto IntegerConstant = E.getIntegerConstantExpr(Ctx))
return APValue(*IntegerConstant);
APValue Constant;
if (Ctx.getLangOpts().CPlusPlus && E.isCXX11ConstantExpr(Ctx, &Constant))
return Constant;

View File

@ -65,9 +65,9 @@ void ProBoundsConstantArrayIndexCheck::check(
if (IndexExpr->isValueDependent())
return; // We check in the specialization.
llvm::APSInt Index;
if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr,
/*isEvaluated=*/true)) {
Optional<llvm::APSInt> Index =
IndexExpr->getIntegerConstantExpr(*Result.Context);
if (!Index) {
SourceRange BaseRange;
if (const auto *ArraySubscriptE = dyn_cast<ArraySubscriptExpr>(Matched))
BaseRange = ArraySubscriptE->getBase()->getSourceRange();
@ -101,9 +101,9 @@ void ProBoundsConstantArrayIndexCheck::check(
if (!StdArrayDecl)
return;
if (Index.isSigned() && Index.isNegative()) {
if (Index->isSigned() && Index->isNegative()) {
diag(Matched->getExprLoc(), "std::array<> index %0 is negative")
<< Index.toString(10);
<< Index->toString(10);
return;
}
@ -118,11 +118,11 @@ void ProBoundsConstantArrayIndexCheck::check(
// Get uint64_t values, because different bitwidths would lead to an assertion
// in APInt::uge.
if (Index.getZExtValue() >= ArraySize.getZExtValue()) {
if (Index->getZExtValue() >= ArraySize.getZExtValue()) {
diag(Matched->getExprLoc(),
"std::array<> index %0 is past the end of the array "
"(which contains %1 elements)")
<< Index.toString(10) << ArraySize.toString(10, false);
<< Index->toString(10) << ArraySize.toString(10, false);
}
}

View File

@ -500,7 +500,13 @@ static bool retrieveIntegerConstantExpr(const MatchFinder::MatchResult &Result,
const Expr *&ConstExpr) {
std::string CstId = (Id + "-const").str();
ConstExpr = Result.Nodes.getNodeAs<Expr>(CstId);
return ConstExpr && ConstExpr->isIntegerConstantExpr(Value, *Result.Context);
if (!ConstExpr)
return false;
Optional<llvm::APSInt> R = ConstExpr->getIntegerConstantExpr(*Result.Context);
if (!R)
return false;
Value = *R;
return true;
}
// Overloaded `retrieveIntegerConstantExpr` for compatibility.
@ -673,7 +679,7 @@ static bool retrieveRelationalIntegerConstantExpr(
if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
if (!Arg->isValueDependent() &&
!Arg->isIntegerConstantExpr(Value, *Result.Context))
!Arg->isIntegerConstantExpr(*Result.Context))
return false;
}
Symbol = OverloadedOperatorExpr->getArg(0);
@ -1265,21 +1271,23 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
"left-right-shift-confusion")) {
const auto *ShiftingConst = Result.Nodes.getNodeAs<Expr>("shift-const");
assert(ShiftingConst && "Expr* 'ShiftingConst' is nullptr!");
APSInt ShiftingValue;
Optional<llvm::APSInt> ShiftingValue =
ShiftingConst->getIntegerConstantExpr(*Result.Context);
if (!ShiftingConst->isIntegerConstantExpr(ShiftingValue, *Result.Context))
if (!ShiftingValue)
return;
const auto *AndConst = Result.Nodes.getNodeAs<Expr>("and-const");
assert(AndConst && "Expr* 'AndCont' is nullptr!");
APSInt AndValue;
if (!AndConst->isIntegerConstantExpr(AndValue, *Result.Context))
Optional<llvm::APSInt> AndValue =
AndConst->getIntegerConstantExpr(*Result.Context);
if (!AndValue)
return;
// If ShiftingConst is shifted left with more bits than the position of the
// leftmost 1 in the bit representation of AndValue, AndConstant is
// ineffective.
if (AndValue.getActiveBits() > ShiftingValue)
if (AndValue->getActiveBits() > *ShiftingValue)
return;
auto Diag = diag(BinaryAndExpr->getOperatorLoc(),

View File

@ -438,11 +438,12 @@ static bool arrayMatchesBoundExpr(ASTContext *Context,
Context->getAsConstantArrayType(ArrayType);
if (!ConstType)
return false;
llvm::APSInt ConditionSize;
if (!ConditionExpr->isIntegerConstantExpr(ConditionSize, *Context))
Optional<llvm::APSInt> ConditionSize =
ConditionExpr->getIntegerConstantExpr(*Context);
if (!ConditionSize)
return false;
llvm::APSInt ArraySize(ConstType->getSize());
return llvm::APSInt::isSameValue(ConditionSize, ArraySize);
return llvm::APSInt::isSameValue(*ConditionSize, ArraySize);
}
ForLoopIndexUseVisitor::ForLoopIndexUseVisitor(ASTContext *Context,