@@ -76,13 +76,10 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
76
76
// Case 2: fill_char of memset() is larger in size than an unsigned char
77
77
// so it gets truncated during conversion.
78
78
79
+ llvm::APSInt NumValue;
79
80
const auto UCharMax = (1 << Result.Context ->getCharWidth ()) - 1 ;
80
- Expr::EvalResult EVResult;
81
- if (!NumFill->EvaluateAsInt (EVResult, *Result.Context ))
82
- return ;
83
-
84
- llvm::APSInt NumValue = EVResult.Val .getInt ();
85
- if (NumValue >= 0 && NumValue <= UCharMax)
81
+ if (!NumFill->EvaluateAsInt (NumValue, *Result.Context ) ||
82
+ (NumValue >= 0 && NumValue <= UCharMax))
86
83
return ;
87
84
88
85
diag (NumFill->getBeginLoc (), " memset fill value is out of unsigned "
@@ -97,22 +94,18 @@ void SuspiciousMemsetUsageCheck::check(const MatchFinder::MatchResult &Result) {
97
94
const Expr *ByteCount = Call->getArg (2 );
98
95
99
96
// Return if `byte_count` is not zero at compile time.
100
- Expr::EvalResult Value2;
97
+ llvm::APSInt Value1, Value2;
101
98
if (ByteCount->isValueDependent () ||
102
- !ByteCount->EvaluateAsInt (Value2, *Result.Context ) ||
103
- Value2.Val .getInt () != 0 )
99
+ !ByteCount->EvaluateAsInt (Value2, *Result.Context ) || Value2 != 0 )
104
100
return ;
105
101
106
102
// Return if `fill_char` is known to be zero or negative at compile
107
103
// time. In these cases, swapping the args would be a nop, or
108
104
// introduce a definite bug. The code is likely correct.
109
- Expr::EvalResult EVResult;
110
105
if (!FillChar->isValueDependent () &&
111
- FillChar->EvaluateAsInt (EVResult, *Result.Context )) {
112
- llvm::APSInt Value1 = EVResult.Val .getInt ();
113
- if (Value1 == 0 || Value1.isNegative ())
114
- return ;
115
- }
106
+ FillChar->EvaluateAsInt (Value1, *Result.Context ) &&
107
+ (Value1 == 0 || Value1.isNegative ()))
108
+ return ;
116
109
117
110
// `byte_count` is known to be zero at compile time, and `fill_char` is
118
111
// either not known or known to be a positive integer. Emit a warning
0 commit comments