[clang] b293a72 - [analyzer][StreamChecker] Using function description objects - NFC.
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 2 03:36:57 PST 2020
Author: Balázs Kéri
Date: 2020-03-02T12:35:07+01:00
New Revision: b293a7217bae22aa8a5f5e9aab025143c0f744e8
URL: https://github.com/llvm/llvm-project/commit/b293a7217bae22aa8a5f5e9aab025143c0f744e8
DIFF: https://github.com/llvm/llvm-project/commit/b293a7217bae22aa8a5f5e9aab025143c0f744e8.diff
LOG: [analyzer][StreamChecker] Using function description objects - NFC.
Summary:
Have a description object for the stream functions
that can store different aspects of a single stream operation.
I plan to extend the structure with other members,
for example pre-callback and index of the stream argument.
Reviewers: Szelethus, baloghadamsoftware, NoQ, martong, Charusso, xazax.hun
Reviewed By: Szelethus
Subscribers: rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gamesh411, Charusso, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75158
Added:
Modified:
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index ab4c9fafae1d..64412442a528 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -49,6 +49,15 @@ struct StreamState {
}
};
+class StreamChecker;
+
+using FnCheck = std::function<void(const StreamChecker *, const CallEvent &,
+ CheckerContext &)>;
+
+struct FnDescription {
+ FnCheck EvalFn;
+};
+
class StreamChecker : public Checker<eval::Call,
check::DeadSymbols > {
mutable std::unique_ptr<BuiltinBug> BT_nullfp, BT_illegalwhence,
@@ -59,35 +68,33 @@ class StreamChecker : public Checker<eval::Call,
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
private:
- using FnCheck = std::function<void(const StreamChecker *, const CallEvent &,
- CheckerContext &)>;
-
- CallDescriptionMap<FnCheck> Callbacks = {
- {{"fopen"}, &StreamChecker::evalFopen},
- {{"freopen", 3}, &StreamChecker::evalFreopen},
- {{"tmpfile"}, &StreamChecker::evalFopen},
- {{"fclose", 1}, &StreamChecker::evalFclose},
+
+ CallDescriptionMap<FnDescription> FnDescriptions = {
+ {{"fopen"}, {&StreamChecker::evalFopen}},
+ {{"freopen", 3}, {&StreamChecker::evalFreopen}},
+ {{"tmpfile"}, {&StreamChecker::evalFopen}},
+ {{"fclose", 1}, {&StreamChecker::evalFclose}},
{{"fread", 4},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
{{"fwrite", 4},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)},
- {{"fseek", 3}, &StreamChecker::evalFseek},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 3)}},
+ {{"fseek", 3}, {&StreamChecker::evalFseek}},
{{"ftell", 1},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
{{"rewind", 1},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
{{"fgetpos", 2},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
{{"fsetpos", 2},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
{{"clearerr", 1},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
{{"feof", 1},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
{{"ferror", 1},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
{{"fileno", 1},
- std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)},
+ {std::bind(&StreamChecker::checkArgNullStream, _1, _2, _3, 0)}},
};
void evalFopen(const CallEvent &Call, CheckerContext &C) const;
@@ -125,11 +132,11 @@ bool StreamChecker::evalCall(const CallEvent &Call, CheckerContext &C) const {
return false;
}
- const FnCheck *Callback = Callbacks.lookup(Call);
- if (!Callback)
+ const FnDescription *Description = FnDescriptions.lookup(Call);
+ if (!Description)
return false;
- (*Callback)(this, Call, C);
+ (Description->EvalFn)(this, Call, C);
return C.isDifferent();
}
More information about the cfe-commits
mailing list