14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_CHECKERMANAGER_H 15 #define LLVM_CLANG_STATICANALYZER_CORE_CHECKERMANAGER_H 21 #include "llvm/ADT/DenseMap.h" 22 #include "llvm/ADT/SmallVector.h" 33 class CheckerRegistry;
35 class AnalysisManager;
41 class ExplodedNodeSet;
45 struct NodeBuilderContext;
51 template <
typename RET,
typename... Ps>
53 typedef RET (*Func)(
void *, Ps...);
59 return Fn(Checker, ps...);
89 friend class ::clang::ento::CheckerRegistry;
90 explicit CheckName(StringRef Name) : Name(Name) {}
94 StringRef
getName()
const {
return Name; }
110 : LangOpts(langOpts), AOptions(AOptions) {}
117 bool hasPathSensitiveCheckers()
const;
119 void finishedCheckerRegistration();
135 template <
typename CHECKER>
137 CheckerTag tag = getTag<CHECKER>();
138 CheckerRef &ref = CheckerTags[tag];
140 return static_cast<CHECKER *
>(ref);
143 checker->Name = CurrentCheckName;
144 CheckerDtors.push_back(CheckerDtor(checker, destruct<CHECKER>));
145 CHECKER::_register(checker, *
this);
150 template <
typename CHECKER>
152 CheckerTag tag = getTag<CHECKER>();
153 CheckerRef &ref = CheckerTags[tag];
155 return static_cast<CHECKER *
>(ref);
158 checker->Name = CurrentCheckName;
159 CheckerDtors.push_back(CheckerDtor(checker, destruct<CHECKER>));
160 CHECKER::_register(checker, *
this);
191 runCheckersForStmt(
true, Dst, Src, S, Eng);
204 bool wasInlined =
false) {
205 runCheckersForStmt(
false, Dst, Src, S, Eng, wasInlined);
209 void runCheckersForStmt(
bool isPreVisit,
212 bool wasInlined =
false);
227 bool wasInlined =
false) {
247 bool wasInlined =
false);
252 runCheckersForCallEvent(
true, Dst, Src, Call, Eng);
258 bool wasInlined =
false) {
259 runCheckersForCallEvent(
false, Dst, Src, Call, Eng,
267 bool wasInlined =
false);
302 void runCheckersForBranchCondition(
const Stmt *condition,
368 SVal Cond,
bool Assumption);
391 const char *NL,
const char *Sep);
404 void _registerForDecl(
CheckDeclFunc checkfn, HandlesDeclFunc isForDeclFn);
462 const SVal &cond,
bool assumption)>
473 void _registerForPreStmt(CheckStmtFunc checkfn,
474 HandlesStmtFunc isForStmtFn);
475 void _registerForPostStmt(CheckStmtFunc checkfn,
476 HandlesStmtFunc isForStmtFn);
497 void _registerForLiveSymbols(CheckLiveSymbolsFunc checkfn);
520 template <
typename EVENT>
522 EventInfo &info = Events[getTag<EVENT>()];
523 info.Checkers.push_back(checkfn);
526 template <
typename EVENT>
528 EventInfo &info = Events[getTag<EVENT>()];
529 info.HasDispatcher =
true;
532 template <
typename EVENT>
534 EventsTy::const_iterator I = Events.find(getTag<EVENT>());
535 if (I == Events.end())
537 const EventInfo &info = I->second;
538 for (
unsigned i = 0, e = info.Checkers.size(); i != e; ++i)
539 info.Checkers[i](&event);
547 template <
typename CHECKER>
548 static void destruct(
void *obj) {
delete static_cast<CHECKER *
>(obj); }
550 template <
typename T>
551 static void *getTag() {
static int tag;
return &tag; }
553 llvm::DenseMap<CheckerTag, CheckerRef> CheckerTags;
555 std::vector<CheckerDtor> CheckerDtors;
557 struct DeclCheckerInfo {
559 HandlesDeclFunc IsForDeclFn;
561 std::vector<DeclCheckerInfo> DeclCheckers;
563 std::vector<CheckDeclFunc> BodyCheckers;
566 typedef llvm::DenseMap<unsigned, CachedDeclCheckers> CachedDeclCheckersMapTy;
567 CachedDeclCheckersMapTy CachedDeclCheckersMap;
569 struct StmtCheckerInfo {
570 CheckStmtFunc CheckFn;
571 HandlesStmtFunc IsForStmtFn;
574 std::vector<StmtCheckerInfo> StmtCheckers;
577 typedef llvm::DenseMap<unsigned, CachedStmtCheckers> CachedStmtCheckersMapTy;
578 CachedStmtCheckersMapTy CachedStmtCheckersMap;
580 const CachedStmtCheckers &getCachedStmtCheckersFor(
const Stmt *S,
585 const std::vector<CheckObjCMessageFunc> &
588 std::vector<CheckObjCMessageFunc> PreObjCMessageCheckers;
589 std::vector<CheckObjCMessageFunc> PostObjCMessageCheckers;
590 std::vector<CheckObjCMessageFunc> ObjCMessageNilCheckers;
592 std::vector<CheckCallFunc> PreCallCheckers;
593 std::vector<CheckCallFunc> PostCallCheckers;
595 std::vector<CheckLocationFunc> LocationCheckers;
597 std::vector<CheckBindFunc> BindCheckers;
599 std::vector<CheckEndAnalysisFunc> EndAnalysisCheckers;
601 std::vector<CheckBeginFunctionFunc> BeginFunctionCheckers;
602 std::vector<CheckEndFunctionFunc> EndFunctionCheckers;
604 std::vector<CheckBranchConditionFunc> BranchConditionCheckers;
606 std::vector<CheckLiveSymbolsFunc> LiveSymbolsCheckers;
608 std::vector<CheckDeadSymbolsFunc> DeadSymbolsCheckers;
610 std::vector<CheckRegionChangesFunc> RegionChangesCheckers;
612 std::vector<CheckPointerEscapeFunc> PointerEscapeCheckers;
614 std::vector<EvalAssumeFunc> EvalAssumeCheckers;
616 std::vector<EvalCallFunc> EvalCallCheckers;
618 std::vector<CheckEndOfTranslationUnit> EndOfTranslationUnitCheckers;
623 EventInfo() : HasDispatcher(
false) { }
626 typedef llvm::DenseMap<EventTag, EventInfo> EventsTy;
void _dispatchEvent(const EVENT &event) const
Stmt - This represents one statement.
Information about invalidation for a particular region/symbol.
CheckerFn< void(const SVal &location, const SVal &val, const Stmt *S, CheckerContext &)> CheckBindFunc
Decl - This represents one declaration (or definition), e.g.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
The pointer has been passed to a function indirectly.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
CheckerFn< void(CheckerContext &)> CheckEndFunctionFunc
void runCheckersForObjCMessageNil(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng)
Run checkers for visiting an obj-c message to nil.
A pointer escapes due to binding its value to a location that the analyzer cannot track...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
void runCheckersForPostObjCMessage(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting obj-c messages.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
#define CHECKER(FULLNAME, CLASS, DESCFILE, HELPTEXT, GROUPINDEX, HIDDEN)
Represents any expression that calls an Objective-C method.
void runCheckersForPreCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
void setCurrentCheckName(CheckName name)
CheckerFn< void(const Stmt *, CheckerContext &)> CheckStmtFunc
CheckerFn< void(ProgramStateRef, SymbolReaper &)> CheckLiveSymbolsFunc
void runCheckersForPostCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting obj-c messages.
CheckName getCurrentCheckName() const
CheckerFn(CheckerBase *checker, Func fn)
CheckerFn< ProgramStateRef(ProgramStateRef, const InvalidatedSymbols &Escaped, const CallEvent *Call, PointerEscapeKind Kind, RegionAndSymbolInvalidationTraits *ITraits)> CheckPointerEscapeFunc
StringRef getName() const
void runCheckersForPostStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting Stmts.
Defines the clang::LangOptions interface.
CheckerFn< void(const ObjCMethodCall &, CheckerContext &)> CheckObjCMessageFunc
void runCheckersForPreObjCMessage(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
The pointer has been passed to a function call directly.
RET operator()(Ps... ps) const
CheckerFn< void(const Stmt *, CheckerContext &)> CheckBranchConditionFunc
The reason for pointer escape is unknown.
CheckerFn< void(CheckerContext &)> CheckBeginFunctionFunc
BugReporter is a utility class for generating PathDiagnostics for analysis.
CHECKER * registerChecker()
Used to register checkers.
void _registerListenerForEvent(CheckEventFunc checkfn)
CheckerFn< bool(const CallExpr *, CheckerContext &)> EvalCallFunc
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
CheckerManager(const LangOptions &langOpts, AnalyzerOptions &AOptions)
A class responsible for cleaning up unused symbols.
void _registerDispatcherForEvent()
void runCheckersForPreStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng)
Run checkers for pre-visiting Stmts.
CheckerFn< void(const TranslationUnitDecl *, AnalysisManager &, BugReporter &)> CheckEndOfTranslationUnit
CheckerFn< void(const CallEvent &, CheckerContext &)> CheckCallFunc
CheckerFn< void(const void *event)> CheckEventFunc
CheckerFn< void(const Decl *, AnalysisManager &, BugReporter &)> CheckDeclFunc
Dataflow Directional Tag Classes.
Represents an abstract call to a function or method along a particular path.
AnalyzerOptions & getAnalyzerOptions()
CheckerFn< void(ExplodedGraph &, BugReporter &, ExprEngine &)> CheckEndAnalysisFunc
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.
CheckerFn< ProgramStateRef(ProgramStateRef, const SVal &cond, bool assumption)> EvalAssumeFunc
CheckerFn< void(SymbolReaper &, CheckerContext &)> CheckDeadSymbolsFunc
CheckerFn< void(const SVal &location, bool isLoad, const Stmt *S, CheckerContext &)> CheckLocationFunc
CHECKER * registerChecker(AnalyzerOptions &AOpts)
CheckerFn< ProgramStateRef(ProgramStateRef, const InvalidatedSymbols *symbols, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const LocationContext *LCtx, const CallEvent *Call)> CheckRegionChangesFunc
TranslationUnitDecl - The top declaration context.
const LangOptions & getLangOpts() const
CheckerFn< void()> CheckerDtor