refactoring.
}
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;
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();
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;
}
// 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);
}
}
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.
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);
"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(),
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,