[clang] [clang][Analyzer][NFC] Use condition type for comparison in several checkers (PR #72358)
Ben Shi via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 14 23:24:38 PST 2023
https://github.com/benshi001 created https://github.com/llvm/llvm-project/pull/72358
None
>From b2abb3ff72a2a9f57a3fc4b71d19daefd436410b Mon Sep 17 00:00:00 2001
From: Ben Shi <bennshi at tencent.com>
Date: Wed, 15 Nov 2023 15:16:18 +0800
Subject: [PATCH] [clang][Analyzer][NFC] Use condition type for comparison in
several checkers
---
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp | 4 ++--
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp | 4 ++--
clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp | 3 ++-
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index b1bc98e93a27995..31f5b03dcdeba80 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -881,8 +881,8 @@ SVal CStringChecker::getCStringLengthForRegion(CheckerContext &C,
const llvm::APSInt *maxLengthInt = BVF.evalAPSInt(BO_Div, maxValInt,
fourInt);
NonLoc maxLength = svalBuilder.makeIntVal(*maxLengthInt);
- SVal evalLength = svalBuilder.evalBinOpNN(state, BO_LE, *strLn,
- maxLength, sizeTy);
+ SVal evalLength = svalBuilder.evalBinOpNN(state, BO_LE, *strLn, maxLength,
+ svalBuilder.getConditionType());
state = state->assume(evalLength.castAs<DefinedOrUnknownSVal>(), true);
}
state = state->set<CStringLength>(MR, strLength);
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 69610029beb0a9e..2b5c1dc4c99affa 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -719,9 +719,9 @@ void StreamChecker::evalFreadFwrite(const FnDescription *Desc,
NonLoc RetVal = makeRetVal(C, CE).castAs<NonLoc>();
ProgramStateRef StateFailed =
State->BindExpr(CE, C.getLocationContext(), RetVal);
+ SValBuilder &SVB = C.getSValBuilder();
auto Cond =
- C.getSValBuilder()
- .evalBinOpNN(State, BO_LT, RetVal, *NMembVal, C.getASTContext().IntTy)
+ SVB.evalBinOpNN(State, BO_LT, RetVal, *NMembVal, SVB.getConditionType())
.getAs<DefinedOrUnknownSVal>();
if (!Cond)
return;
diff --git a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
index b195d912cadfe9b..1d03d1656b3cb14 100644
--- a/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -188,7 +188,8 @@ ProgramStateRef VLASizeChecker::checkVLAIndexSize(CheckerContext &C,
QualType SizeTy = SizeE->getType();
DefinedOrUnknownSVal Zero = SVB.makeZeroVal(SizeTy);
- SVal LessThanZeroVal = SVB.evalBinOp(State, BO_LT, SizeD, Zero, SizeTy);
+ SVal LessThanZeroVal =
+ SVB.evalBinOp(State, BO_LT, SizeD, Zero, SVB.getConditionType());
if (std::optional<DefinedSVal> LessThanZeroDVal =
LessThanZeroVal.getAs<DefinedSVal>()) {
ConstraintManager &CM = C.getConstraintManager();
More information about the cfe-commits
mailing list