aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
diff options
context:
space:
mode:
authorBalazs Benics <benicsbalazs@gmail.com>2024-12-19 12:04:04 +0100
committerGitHub <noreply@github.com>2024-12-19 12:04:04 +0100
commitb41240be6b9e58687011b2bd1b942c6625cbb5ad (patch)
tree4af3967bfacb4362c4b3ac744c3db2a35e2c38a2 /clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
parent056e5eccaf440e9127990f9fba1e5cacac399a14 (diff)
downloadllvm-b41240be6b9e58687011b2bd1b942c6625cbb5ad.zip
llvm-b41240be6b9e58687011b2bd1b942c6625cbb5ad.tar.gz
llvm-b41240be6b9e58687011b2bd1b942c6625cbb5ad.tar.bz2
[analyzer][NFC] Introduce APSIntPtr, a safe wrapper of APSInt (1/4) (#120435)
One could create dangling APSInt references in various ways in the past, that were sometimes assumed to be persisted in the BasicValueFactor. One should always use BasicValueFactory to create persistent APSInts, that could be used by ConcreteInts or SymIntExprs and similar long-living objects. If one used a temporary or local variables for this, these would dangle. To enforce the contract of the analyzer BasicValueFactory and the uses of APSInts, let's have a dedicated strong-type for this. The idea is that APSIntPtr is always owned by the BasicValueFactory, and that is the only component that can construct it. These PRs are all NFC - besides fixing dangling APSInt references.
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 4f30b2a..356d63e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -1643,7 +1643,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
public:
GetMaxValue(BasicValueFactory &BVF) : BVF(BVF) {}
std::optional<RangeInt> operator()(QualType Ty) {
- return BVF.getMaxValue(Ty).getLimitedValue();
+ return BVF.getMaxValue(Ty)->getLimitedValue();
}
std::optional<RangeInt> operator()(std::optional<QualType> Ty) {
if (Ty) {
@@ -1687,11 +1687,11 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
const QualType SizePtrTy = getPointerTy(SizeTy);
const QualType SizePtrRestrictTy = getRestrictTy(SizePtrTy);
- const RangeInt IntMax = BVF.getMaxValue(IntTy).getLimitedValue();
+ const RangeInt IntMax = BVF.getMaxValue(IntTy)->getLimitedValue();
const RangeInt UnsignedIntMax =
- BVF.getMaxValue(UnsignedIntTy).getLimitedValue();
- const RangeInt LongMax = BVF.getMaxValue(LongTy).getLimitedValue();
- const RangeInt SizeMax = BVF.getMaxValue(SizeTy).getLimitedValue();
+ BVF.getMaxValue(UnsignedIntTy)->getLimitedValue();
+ const RangeInt LongMax = BVF.getMaxValue(LongTy)->getLimitedValue();
+ const RangeInt SizeMax = BVF.getMaxValue(SizeTy)->getLimitedValue();
// Set UCharRangeMax to min of int or uchar maximum value.
// The C standard states that the arguments of functions like isalpha must
@@ -1700,7 +1700,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
// to be true for commonly used and well tested instruction set
// architectures, but not for others.
const RangeInt UCharRangeMax =
- std::min(BVF.getMaxValue(ACtx.UnsignedCharTy).getLimitedValue(), IntMax);
+ std::min(BVF.getMaxValue(ACtx.UnsignedCharTy)->getLimitedValue(), IntMax);
// Get platform dependent values of some macros.
// Try our best to parse this from the Preprocessor, otherwise fallback to a
@@ -3704,7 +3704,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
// Functions for testing.
if (AddTestFunctions) {
- const RangeInt IntMin = BVF.getMinValue(IntTy).getLimitedValue();
+ const RangeInt IntMin = BVF.getMinValue(IntTy)->getLimitedValue();
addToFunctionSummaryMap(
"__not_null", Signature(ArgTypes{IntPtrTy}, RetType{IntTy}),