[clang] 1d9a65b - [clang][analyzer][NFC] Simplify ranges in StdLibraryFunctionsChecker (#78886)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 21 17:31:37 PST 2024
Author: Ben Shi
Date: 2024-01-22T09:31:32+08:00
New Revision: 1d9a65b220a92b59b0556ba8b3195b5346e71170
URL: https://github.com/llvm/llvm-project/commit/1d9a65b220a92b59b0556ba8b3195b5346e71170
DIFF: https://github.com/llvm/llvm-project/commit/1d9a65b220a92b59b0556ba8b3195b5346e71170.diff
LOG: [clang][analyzer][NFC] Simplify ranges in StdLibraryFunctionsChecker (#78886)
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d0eb5091444f6b6..fcd907a9bb0da02 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2146,6 +2146,8 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(0))};
const auto ReturnsMinusOne =
ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(-1))};
+ const auto ReturnsEOF =
+ ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(EOFv))};
const auto ReturnsNonnegative =
ConstraintSet{ReturnValueCondition(WithinRange, Range(0, IntMax))};
const auto ReturnsNonZero =
@@ -2207,8 +2209,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
"fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
Summary(NoEvalCall)
.Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
- .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
- ErrnoNEZeroIrrelevant, GenericFailureMsg)
+ .Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg)
.ArgConstraint(NotNull(ArgNo(0))));
// int ungetc(int c, FILE *stream);
@@ -2219,7 +2220,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
ErrnoMustNotBeChecked, GenericSuccessMsg)
.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
- ArgumentCondition(0, WithinRange, {{EOFv, EOFv}})},
+ ArgumentCondition(0, WithinRange, SingleValue(EOFv))},
ErrnoNEZeroIrrelevant,
"Assuming that 'ungetc' fails because EOF was passed as "
"character")
@@ -2287,8 +2288,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
"fflush", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
Summary(NoEvalCall)
.Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
- .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
- ErrnoNEZeroIrrelevant, GenericFailureMsg));
+ .Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg));
// long ftell(FILE *stream);
// From 'The Open Group Base Specifications Issue 7, 2018 edition':
@@ -3002,8 +3002,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
"execv",
Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
Summary(NoEvalCall)
- .Case({ReturnValueCondition(WithinRange, SingleValue(-1))},
- ErrnoIrrelevant)
+ .Case(ReturnsMinusOne, ErrnoIrrelevant)
.ArgConstraint(NotNull(ArgNo(0))));
// int execvp(const char *file, char *const argv[]);
@@ -3011,8 +3010,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
"execvp",
Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
Summary(NoEvalCall)
- .Case({ReturnValueCondition(WithinRange, SingleValue(-1))},
- ErrnoIrrelevant)
+ .Case(ReturnsMinusOne, ErrnoIrrelevant)
.ArgConstraint(NotNull(ArgNo(0))));
// int getopt(int argc, char * const argv[], const char *optstring);
More information about the cfe-commits
mailing list