summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
index 2e0a46c91a7..ca3c126340b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
+++ b/clang-tools-extra/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
OpenPOWER on IntegriCloud