forked from OSchip/llvm-project
Revert r347419 "Update call to EvaluateAsInt() to the new syntax."
It's pre-requisite was reverted in r347656. llvm-svn: 347657
This commit is contained in:
parent
8c79706e89
commit
02f5511ff4
|
@ -65,16 +65,16 @@ static unsigned getMaxCalculationWidth(const ASTContext &Context,
|
||||||
if (Bop->getOpcode() == BO_Add)
|
if (Bop->getOpcode() == BO_Add)
|
||||||
return std::max(LHSWidth, RHSWidth) + 1;
|
return std::max(LHSWidth, RHSWidth) + 1;
|
||||||
if (Bop->getOpcode() == BO_Rem) {
|
if (Bop->getOpcode() == BO_Rem) {
|
||||||
Expr::EvalResult Result;
|
llvm::APSInt Val;
|
||||||
if (Bop->getRHS()->EvaluateAsInt(Result, Context))
|
if (Bop->getRHS()->EvaluateAsInt(Val, Context))
|
||||||
return Result.Val.getInt().getActiveBits();
|
return Val.getActiveBits();
|
||||||
} else if (Bop->getOpcode() == BO_Shl) {
|
} else if (Bop->getOpcode() == BO_Shl) {
|
||||||
Expr::EvalResult Result;
|
llvm::APSInt Bits;
|
||||||
if (Bop->getRHS()->EvaluateAsInt(Result, Context)) {
|
if (Bop->getRHS()->EvaluateAsInt(Bits, Context)) {
|
||||||
// We don't handle negative values and large values well. It is assumed
|
// We don't handle negative values and large values well. It is assumed
|
||||||
// that compiler warnings are written for such values so the user will
|
// that compiler warnings are written for such values so the user will
|
||||||
// fix that.
|
// fix that.
|
||||||
return LHSWidth + Result.Val.getInt().getExtValue();
|
return LHSWidth + Bits.getExtValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unknown bitcount, assume there is truncation.
|
// Unknown bitcount, assume there is truncation.
|
||||||
|
|
|
@ -76,13 +76,10 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
|
||||||
// Case 2: fill_char of memset() is larger in size than an unsigned char
|
// Case 2: fill_char of memset() is larger in size than an unsigned char
|
||||||
// so it gets truncated during conversion.
|
// so it gets truncated during conversion.
|
||||||
|
|
||||||
|
llvm::APSInt NumValue;
|
||||||
const auto UCharMax = (1 << Result.Context->getCharWidth()) - 1;
|
const auto UCharMax = (1 << Result.Context->getCharWidth()) - 1;
|
||||||
Expr::EvalResult EVResult;
|
if (!NumFill->EvaluateAsInt(NumValue, *Result.Context) ||
|
||||||
if (!NumFill->EvaluateAsInt(EVResult, *Result.Context))
|
(NumValue >= 0 && NumValue <= UCharMax))
|
||||||
return;
|
|
||||||
|
|
||||||
llvm::APSInt NumValue = EVResult.Val.getInt();
|
|
||||||
if (NumValue >= 0 && NumValue <= UCharMax)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
diag(NumFill->getBeginLoc(), "memset fill value is out of unsigned "
|
diag(NumFill->getBeginLoc(), "memset fill value is out of unsigned "
|
||||||
|
@ -97,22 +94,18 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
|
||||||
const Expr *ByteCount = Call->getArg(2);
|
const Expr *ByteCount = Call->getArg(2);
|
||||||
|
|
||||||
// Return if `byte_count` is not zero at compile time.
|
// Return if `byte_count` is not zero at compile time.
|
||||||
Expr::EvalResult Value2;
|
llvm::APSInt Value1, Value2;
|
||||||
if (ByteCount->isValueDependent() ||
|
if (ByteCount->isValueDependent() ||
|
||||||
!ByteCount->EvaluateAsInt(Value2, *Result.Context) ||
|
!ByteCount->EvaluateAsInt(Value2, *Result.Context) || Value2 != 0)
|
||||||
Value2.Val.getInt() != 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Return if `fill_char` is known to be zero or negative at compile
|
// Return if `fill_char` is known to be zero or negative at compile
|
||||||
// time. In these cases, swapping the args would be a nop, or
|
// time. In these cases, swapping the args would be a nop, or
|
||||||
// introduce a definite bug. The code is likely correct.
|
// introduce a definite bug. The code is likely correct.
|
||||||
Expr::EvalResult EVResult;
|
|
||||||
if (!FillChar->isValueDependent() &&
|
if (!FillChar->isValueDependent() &&
|
||||||
FillChar->EvaluateAsInt(EVResult, *Result.Context)) {
|
FillChar->EvaluateAsInt(Value1, *Result.Context) &&
|
||||||
llvm::APSInt Value1 = EVResult.Val.getInt();
|
(Value1 == 0 || Value1.isNegative()))
|
||||||
if (Value1 == 0 || Value1.isNegative())
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// `byte_count` is known to be zero at compile time, and `fill_char` is
|
// `byte_count` is known to be zero at compile time, and `fill_char` is
|
||||||
// either not known or known to be a positive integer. Emit a warning
|
// either not known or known to be a positive integer. Emit a warning
|
||||||
|
|
|
@ -101,8 +101,8 @@ void ProperlySeededRandomGeneratorCheck::checkSeed(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Expr::EvalResult EVResult;
|
llvm::APSInt Value;
|
||||||
if (Func->getArg(0)->EvaluateAsInt(EVResult, *Result.Context)) {
|
if (Func->getArg(0)->EvaluateAsInt(Value, *Result.Context)) {
|
||||||
diag(Func->getExprLoc(),
|
diag(Func->getExprLoc(),
|
||||||
"random number generator seeded with a constant value will generate a "
|
"random number generator seeded with a constant value will generate a "
|
||||||
"predictable sequence of values");
|
"predictable sequence of values");
|
||||||
|
|
Loading…
Reference in New Issue