aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
diff options
context:
space:
mode:
authorBalázs Kéri <balazs.keri@ericsson.com>2023-06-01 09:20:36 +0200
committerBalázs Kéri <balazs.keri@ericsson.com>2023-06-01 09:54:35 +0200
commit4f0436dd1532d7534d77e6fc211a7a50bbdd0c49 (patch)
tree6e5d4e72c8da1a233cf197236b55b75085740fbe /clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
parentdfb369399d2a54c8dd8752c47ecbf7a8c3c11421 (diff)
downloadllvm-4f0436dd1532d7534d77e6fc211a7a50bbdd0c49.zip
llvm-4f0436dd1532d7534d77e6fc211a7a50bbdd0c49.tar.gz
llvm-4f0436dd1532d7534d77e6fc211a7a50bbdd0c49.tar.bz2
[clang][analyzer] Merge apiModeling.StdCLibraryFunctions and StdCLibraryFunctionArgs checkers into one.
Main reason for this change is that these checkers were implemented in the same class but had different dependency ordering. (NonNullParamChecker should run before StdCLibraryFunctionArgs to get more special warning about null arguments, but the apiModeling.StdCLibraryFunctions was a modeling checker that should run before other non-modeling checkers. The modeling checker changes state in a way that makes it impossible to detect a null argument by NonNullParamChecker.) To make it more simple, the modeling part is removed as separate checker and can be only used if checker StdCLibraryFunctions is turned on, that produces the warnings too. Modeling the functions without bug detection (for invalid argument) is not possible. The modeling of standard functions does not happen by default from this change on. Reviewed By: Szelethus Differential Revision: https://reviews.llvm.org/D151225
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp43
1 files changed, 16 insertions, 27 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 1d6f97f..57d3c99 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -790,13 +790,8 @@ public:
void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
bool evalCall(const CallEvent &Call, CheckerContext &C) const;
- enum CheckKind {
- CK_StdCLibraryFunctionArgsChecker,
- CK_StdCLibraryFunctionsTesterChecker,
- CK_NumCheckKinds
- };
- bool ChecksEnabled[CK_NumCheckKinds] = {false};
- CheckerNameRef CheckNames[CK_NumCheckKinds];
+ CheckerNameRef CheckName;
+ bool AddTestFunctions = false;
bool DisplayLoadedSummaries = false;
bool ModelPOSIX = false;
@@ -813,8 +808,6 @@ private:
void reportBug(const CallEvent &Call, ExplodedNode *N,
const ValueConstraint *VC, const ValueConstraint *NegatedVC,
const Summary &Summary, CheckerContext &C) const {
- if (!ChecksEnabled[CK_StdCLibraryFunctionArgsChecker])
- return;
assert(Call.getDecl() &&
"Function found in summary must have a declaration available");
SmallString<256> Msg;
@@ -834,8 +827,8 @@ private:
Msg[0] = toupper(Msg[0]);
if (!BT_InvalidArg)
BT_InvalidArg = std::make_unique<BugType>(
- CheckNames[CK_StdCLibraryFunctionArgsChecker],
- "Function call with invalid argument", categories::LogicError);
+ CheckName, "Function call with invalid argument",
+ categories::LogicError);
auto R = std::make_unique<PathSensitiveBugReport>(*BT_InvalidArg, Msg, N);
for (ArgNo ArgN : VC->getArgsToTrack()) {
@@ -1423,6 +1416,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
CheckerContext &C) const {
if (SummariesInitialized)
return;
+ SummariesInitialized = true;
SValBuilder &SVB = C.getSValBuilder();
BasicValueFactory &BVF = SVB.getBasicValueFactory();
@@ -3370,7 +3364,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
}
// Functions for testing.
- if (ChecksEnabled[CK_StdCLibraryFunctionsTesterChecker]) {
+ if (AddTestFunctions) {
const RangeInt IntMin = BVF.getMinValue(IntTy).getLimitedValue();
addToFunctionSummaryMap(
@@ -3594,12 +3588,11 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
ReturnValueCondition(WithinRange, SingleValue(4))},
ErrnoIrrelevant));
}
-
- SummariesInitialized = true;
}
void ento::registerStdCLibraryFunctionsChecker(CheckerManager &mgr) {
auto *Checker = mgr.registerChecker<StdLibraryFunctionsChecker>();
+ Checker->CheckName = mgr.getCurrentCheckerName();
const AnalyzerOptions &Opts = mgr.getAnalyzerOptions();
Checker->DisplayLoadedSummaries =
Opts.getCheckerBooleanOption(Checker, "DisplayLoadedSummaries");
@@ -3613,16 +3606,12 @@ bool ento::shouldRegisterStdCLibraryFunctionsChecker(
return true;
}
-#define REGISTER_CHECKER(name) \
- void ento::register##name(CheckerManager &mgr) { \
- StdLibraryFunctionsChecker *checker = \
- mgr.getChecker<StdLibraryFunctionsChecker>(); \
- checker->ChecksEnabled[StdLibraryFunctionsChecker::CK_##name] = true; \
- checker->CheckNames[StdLibraryFunctionsChecker::CK_##name] = \
- mgr.getCurrentCheckerName(); \
- } \
- \
- bool ento::shouldRegister##name(const CheckerManager &mgr) { return true; }
-
-REGISTER_CHECKER(StdCLibraryFunctionArgsChecker)
-REGISTER_CHECKER(StdCLibraryFunctionsTesterChecker)
+void ento::registerStdCLibraryFunctionsTesterChecker(CheckerManager &mgr) {
+ auto *Checker = mgr.getChecker<StdLibraryFunctionsChecker>();
+ Checker->AddTestFunctions = true;
+}
+
+bool ento::shouldRegisterStdCLibraryFunctionsTesterChecker(
+ const CheckerManager &mgr) {
+ return true;
+}