[clang] [clang][analyzer][NFC] Simplify EOF involved ranges in StdLibraryFunctionsChecker (PR #78886)
Ben Shi via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 21 03:43:11 PST 2024
https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/78886
>From c3f97bd20af18c7bef98408b11d9e92cea614dc6 Mon Sep 17 00:00:00 2001
From: Ben Shi <bennshi at tencent.com>
Date: Sun, 21 Jan 2024 15:20:24 +0800
Subject: [PATCH] [clang][analyzer][NFC] Simplify ranges in
StdLibraryFunctionsChecker
---
.../Checkers/StdLibraryFunctionsChecker.cpp | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d0eb5091444f6b..fcd907a9bb0da0 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