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...);
89 friend class ::clang::ento::CheckerRegistry;
90 explicit CheckName(StringRef Name) : Name(Name) {}
94 StringRef
getName()
const {
return Name; }
110 : LangOpts(langOpts), AOptions(std::move(AOptions)) {}
135 template <
typename CHECKER>
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>
155 return static_cast<CHECKER *
>(ref);
158 checker->Name = CurrentCheckName;
159 CheckerDtors.push_back(
CheckerDtor(checker, destruct<CHECKER>));
160 CHECKER::_register(checker, *
this);
204 bool wasInlined =
false) {
212 bool wasInlined =
false);
227 bool wasInlined =
false) {
247 bool wasInlined =
false);
258 bool wasInlined =
false) {
267 bool wasInlined =
false);
370 SVal Cond,
bool Assumption);
393 const char *NL,
const char *Sep);
465 const SVal &cond,
bool assumption)>
524 template <
typename EVENT>
526 EventInfo &info = Events[getTag<EVENT>()];
527 info.Checkers.push_back(checkfn);
530 template <
typename EVENT>
532 EventInfo &info = Events[getTag<EVENT>()];
533 info.HasDispatcher =
true;
536 template <
typename EVENT>
538 EventsTy::const_iterator
I = Events.find(getTag<EVENT>());
539 if (I == Events.end())
541 const EventInfo &info = I->second;
542 for (
unsigned i = 0, e = info.Checkers.size(); i != e; ++i)
543 info.Checkers[i](&event);
551 template <
typename CHECKER>
552 static void destruct(
void *obj) {
delete static_cast<CHECKER *
>(obj); }
554 template <
typename T>
555 static void *getTag() {
static int tag;
return &tag; }
557 llvm::DenseMap<CheckerTag, CheckerRef> CheckerTags;
559 std::vector<CheckerDtor> CheckerDtors;
561 struct DeclCheckerInfo {
565 std::vector<DeclCheckerInfo> DeclCheckers;
567 std::vector<CheckDeclFunc> BodyCheckers;
569 typedef SmallVector<CheckDeclFunc, 4> CachedDeclCheckers;
570 typedef llvm::DenseMap<unsigned, CachedDeclCheckers> CachedDeclCheckersMapTy;
571 CachedDeclCheckersMapTy CachedDeclCheckersMap;
573 struct StmtCheckerInfo {
578 std::vector<StmtCheckerInfo> StmtCheckers;
580 typedef SmallVector<CheckStmtFunc, 4> CachedStmtCheckers;
581 typedef llvm::DenseMap<unsigned, CachedStmtCheckers> CachedStmtCheckersMapTy;
582 CachedStmtCheckersMapTy CachedStmtCheckersMap;
584 const CachedStmtCheckers &getCachedStmtCheckersFor(
const Stmt *
S,
589 const std::vector<CheckObjCMessageFunc> &
592 std::vector<CheckObjCMessageFunc> PreObjCMessageCheckers;
593 std::vector<CheckObjCMessageFunc> PostObjCMessageCheckers;
594 std::vector<CheckObjCMessageFunc> ObjCMessageNilCheckers;
596 std::vector<CheckCallFunc> PreCallCheckers;
597 std::vector<CheckCallFunc> PostCallCheckers;
599 std::vector<CheckLocationFunc> LocationCheckers;
601 std::vector<CheckBindFunc> BindCheckers;
603 std::vector<CheckEndAnalysisFunc> EndAnalysisCheckers;
605 std::vector<CheckBeginFunctionFunc> BeginFunctionCheckers;
606 std::vector<CheckEndFunctionFunc> EndFunctionCheckers;
608 std::vector<CheckBranchConditionFunc> BranchConditionCheckers;
610 std::vector<CheckLiveSymbolsFunc> LiveSymbolsCheckers;
612 std::vector<CheckDeadSymbolsFunc> DeadSymbolsCheckers;
614 struct RegionChangesCheckerInfo {
618 std::vector<RegionChangesCheckerInfo> RegionChangesCheckers;
620 std::vector<CheckPointerEscapeFunc> PointerEscapeCheckers;
622 std::vector<EvalAssumeFunc> EvalAssumeCheckers;
624 std::vector<EvalCallFunc> EvalCallCheckers;
626 std::vector<CheckEndOfTranslationUnit> EndOfTranslationUnitCheckers;
629 SmallVector<CheckEventFunc, 4> Checkers;
631 EventInfo() : HasDispatcher(
false) { }
634 typedef llvm::DenseMap<EventTag, EventInfo> EventsTy;
CheckerManager(const LangOptions &langOpts, AnalyzerOptionsRef AOptions)
bool(* HandlesDeclFunc)(const Decl *D)
void _registerForRegionChanges(CheckRegionChangesFunc checkfn, WantsRegionChangeUpdateFunc wantUpdateFn)
void _registerForDeadSymbols(CheckDeadSymbolsFunc checkfn)
Information about invalidation for a particular region/symbol.
CheckerFn< void(const SVal &location, const SVal &val, const Stmt *S, CheckerContext &)> CheckBindFunc
void runCheckersForEndFunction(NodeBuilderContext &BC, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers on end of function.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
CheckerFn< bool(ProgramStateRef)> WantsRegionChangeUpdateFunc
The pointer has been passed to a function indirectly.
StringRef getName() const
void _registerForBeginFunction(CheckEndFunctionFunc checkfn)
CheckerFn< ProgramStateRef(ProgramStateRef, const InvalidatedSymbols *symbols, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const CallEvent *Call)> CheckRegionChangesFunc
bool(* HandlesStmtFunc)(const Stmt *D)
void _registerForObjCMessageNil(CheckObjCMessageFunc checkfn)
void finishedCheckerRegistration()
CheckerFn< void(CheckerContext &)> CheckEndFunctionFunc
void runCheckersForLocation(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, SVal location, bool isLoad, const Stmt *NodeEx, const Stmt *BoundEx, ExprEngine &Eng)
Run checkers for load/store of a location.
ProgramStateRef runCheckersForPointerEscape(ProgramStateRef State, const InvalidatedSymbols &Escaped, const CallEvent *Call, PointerEscapeKind Kind, RegionAndSymbolInvalidationTraits *ITraits)
Run checkers when pointers escape.
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...
void _registerForPreCall(CheckCallFunc checkfn)
void runCheckersForLiveSymbols(ProgramStateRef state, SymbolReaper &SymReaper)
Run checkers for live symbols.
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
void _registerForEndOfTranslationUnit(CheckEndOfTranslationUnit checkfn)
#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
void _registerForLiveSymbols(CheckLiveSymbolsFunc checkfn)
CheckerFn< void(ProgramStateRef, SymbolReaper &)> CheckLiveSymbolsFunc
bool wantsRegionChangeUpdate(ProgramStateRef state)
True if at least one checker wants to check region changes.
bool hasPathSensitiveCheckers() const
void runCheckersForPostCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting obj-c messages.
void runCheckersOnASTDecl(const Decl *D, AnalysisManager &mgr, BugReporter &BR)
Run checkers handling Decls.
detail::InMemoryDirectory::const_iterator I
CheckerFn(CheckerBase *checker, Func fn)
CheckerFn< ProgramStateRef(ProgramStateRef, const InvalidatedSymbols &Escaped, const CallEvent *Call, PointerEscapeKind Kind, RegionAndSymbolInvalidationTraits *ITraits)> CheckPointerEscapeFunc
void runCheckersForPrintState(raw_ostream &Out, ProgramStateRef State, const char *NL, const char *Sep)
Run checkers for debug-printing a ProgramState.
void runCheckersForBind(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, SVal location, SVal val, const Stmt *S, ExprEngine &Eng, const ProgramPoint &PP)
Run checkers for binding of a value to a location.
void _registerForBody(CheckDeclFunc checkfn)
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.
CheckName getCurrentCheckName() const
CheckerFn< void(const ObjCMethodCall &, CheckerContext &)> CheckObjCMessageFunc
void _registerForEndAnalysis(CheckEndAnalysisFunc checkfn)
void runCheckersForPreObjCMessage(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
void _registerForLocation(CheckLocationFunc checkfn)
The pointer has been passed to a function call directly.
CheckerFn< void(const Stmt *, CheckerContext &)> CheckBranchConditionFunc
void _registerForPointerEscape(CheckPointerEscapeFunc checkfn)
The reason for pointer escape is unknown.
void runCheckersForEvalCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &CE, ExprEngine &Eng)
Run checkers for evaluating a call.
CheckerFn< void(CheckerContext &)> CheckBeginFunctionFunc
void _registerForPostCall(CheckCallFunc checkfn)
BugReporter is a utility class for generating PathDiagnostics for analysis.
void _registerForPreObjCMessage(CheckObjCMessageFunc checkfn)
CHECKER * registerChecker()
Used to register checkers.
void _registerListenerForEvent(CheckEventFunc checkfn)
void runCheckersForBranchCondition(const Stmt *condition, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers for branch condition.
CheckerFn< bool(const CallExpr *, CheckerContext &)> EvalCallFunc
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
void _registerForBranchCondition(CheckBranchConditionFunc checkfn)
ProgramStateRef runCheckersForEvalAssume(ProgramStateRef state, SVal Cond, bool Assumption)
Run checkers for handling assumptions on symbolic values.
void runCheckersForObjCMessage(ObjCMessageVisitKind visitKind, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting obj-c messages.
A class responsible for cleaning up unused symbols.
void runCheckersOnASTBody(const Decl *D, AnalysisManager &mgr, BugReporter &BR)
Run checkers handling Decls containing a Stmt body.
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
const LangOptions & getLangOpts() const
CheckerFn< void(const Decl *, AnalysisManager &, BugReporter &)> CheckDeclFunc
void runCheckersForDeadSymbols(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, SymbolReaper &SymReaper, const Stmt *S, ExprEngine &Eng, ProgramPoint::Kind K)
Run checkers for dead symbols.
RET operator()(Ps...ps) const
void runCheckersForStmt(bool isPreVisit, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting Stmts.
void _registerForDecl(CheckDeclFunc checkfn, HandlesDeclFunc isForDeclFn)
void _registerForPostObjCMessage(CheckObjCMessageFunc checkfn)
Represents an abstract call to a function or method along a particular path.
AnalyzerOptions & getAnalyzerOptions()
void _registerForEndFunction(CheckEndFunctionFunc checkfn)
void _registerForEvalAssume(EvalAssumeFunc checkfn)
void _registerForPostStmt(CheckStmtFunc checkfn, HandlesStmtFunc isForStmtFn)
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
void runCheckersForCallEvent(bool isPreVisit, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting obj-c messages.
void runCheckersForEndAnalysis(ExplodedGraph &G, BugReporter &BR, ExprEngine &Eng)
Run checkers for end of analysis.
CheckerFn< void(SymbolReaper &, CheckerContext &)> CheckDeadSymbolsFunc
CheckerFn< void(const SVal &location, bool isLoad, const Stmt *S, CheckerContext &)> CheckLocationFunc
void _registerForEvalCall(EvalCallFunc checkfn)
CHECKER * registerChecker(AnalyzerOptions &AOpts)
ProgramStateRef runCheckersForRegionChanges(ProgramStateRef state, const InvalidatedSymbols *invalidated, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const CallEvent *Call)
Run checkers for region changes.
void runCheckersForBeginFunction(ExplodedNodeSet &Dst, const BlockEdge &L, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers on begining of function.
TranslationUnitDecl - The top declaration context.
void _registerForConstPointerEscape(CheckPointerEscapeFunc checkfn)
void runCheckersOnEndOfTranslationUnit(const TranslationUnitDecl *TU, AnalysisManager &mgr, BugReporter &BR)
Run checkers for the entire Translation Unit.
void _registerForPreStmt(CheckStmtFunc checkfn, HandlesStmtFunc isForStmtFn)
void _registerForBind(CheckBindFunc checkfn)
void _dispatchEvent(const EVENT &event) const
CheckerFn< void()> CheckerDtor