aboutsummaryrefslogtreecommitdiff
path: root/clang-tidy/bugprone
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2018-11-20 23:24:39 +0000
committerBill Wendling <isanbard@gmail.com>2018-11-20 23:24:39 +0000
commit70b4e5417497402a45ebe00af5e7a316d4465f88 (patch)
tree37f9d7f3e03dcf2f87f4db1e6c1c9d53534742ca /clang-tidy/bugprone
parent75c03f0595339c5393f253d36c908294815376cb (diff)
Update EvaluateAsInt to the new syntax.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@347366 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/bugprone')
-rw-r--r--clang-tidy/bugprone/MisplacedWideningCastCheck.cpp12
-rw-r--r--clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp23
2 files changed, 21 insertions, 14 deletions
diff --git a/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp b/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
index b9cbfebe..c36a1b23 100644
--- a/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
+++ b/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
@@ -65,16 +65,16 @@ static unsigned getMaxCalculationWidth(const ASTContext &Context,
if (Bop->getOpcode() == BO_Add)
return std::max(LHSWidth, RHSWidth) + 1;
if (Bop->getOpcode() == BO_Rem) {
- llvm::APSInt Val;
- if (Bop->getRHS()->EvaluateAsInt(Val, Context))
- return Val.getActiveBits();
+ Expr::EvalResult Result;
+ if (Bop->getRHS()->EvaluateAsInt(Result, Context))
+ return Result.Val.getInt().getActiveBits();
} else if (Bop->getOpcode() == BO_Shl) {
- llvm::APSInt Bits;
- if (Bop->getRHS()->EvaluateAsInt(Bits, Context)) {
+ Expr::EvalResult Result;
+ if (Bop->getRHS()->EvaluateAsInt(Result, Context)) {
// 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
// fix that.
- return LHSWidth + Bits.getExtValue();
+ return LHSWidth + Result.Val.getInt().getExtValue();
}
// Unknown bitcount, assume there is truncation.
diff --git a/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp b/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
index 2e0a46c9..ca3c1263 100644
--- a/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
+++ b/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
@@ -76,10 +76,13 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
// Case 2: fill_char of memset() is larger in size than an unsigned char
// so it gets truncated during conversion.
- llvm::APSInt NumValue;
const auto UCharMax = (1 << Result.Context->getCharWidth()) - 1;
- if (!NumFill->EvaluateAsInt(NumValue, *Result.Context) ||
- (NumValue >= 0 && NumValue <= UCharMax))
+ Expr::EvalResult EVResult;
+ if (!NumFill->EvaluateAsInt(EVResult, *Result.Context))
+ return;
+
+ llvm::APSInt NumValue = EVResult.Val.getInt();
+ if (NumValue >= 0 && NumValue <= UCharMax)
return;
diag(NumFill->getBeginLoc(), "memset fill value is out of unsigned "
@@ -94,18 +97,22 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
const Expr *ByteCount = Call->getArg(2);
// Return if `byte_count` is not zero at compile time.
- llvm::APSInt Value1, Value2;
+ Expr::EvalResult Value2;
if (ByteCount->isValueDependent() ||
- !ByteCount->EvaluateAsInt(Value2, *Result.Context) || Value2 != 0)
+ !ByteCount->EvaluateAsInt(Value2, *Result.Context) ||
+ Value2.Val.getInt() != 0)
return;
// 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
// introduce a definite bug. The code is likely correct.
+ Expr::EvalResult EVResult;
if (!FillChar->isValueDependent() &&
- FillChar->EvaluateAsInt(Value1, *Result.Context) &&
- (Value1 == 0 || Value1.isNegative()))
- return;
+ FillChar->EvaluateAsInt(EVResult, *Result.Context)) {
+ llvm::APSInt Value1 = EVResult.Val.getInt();
+ if (Value1 == 0 || Value1.isNegative())
+ return;
+ }
// `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