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(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);
368 SVal Cond,
bool Assumption);
391 const char *NL,
const char *Sep);
462 const SVal &cond,
bool assumption)>
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 {
561 std::vector<DeclCheckerInfo> DeclCheckers;
563 std::vector<CheckDeclFunc> BodyCheckers;
565 typedef SmallVector<CheckDeclFunc, 4> CachedDeclCheckers;
566 typedef llvm::DenseMap<unsigned, CachedDeclCheckers> CachedDeclCheckersMapTy;
567 CachedDeclCheckersMapTy CachedDeclCheckersMap;
569 struct StmtCheckerInfo {
574 std::vector<StmtCheckerInfo> StmtCheckers;
576 typedef SmallVector<CheckStmtFunc, 4> CachedStmtCheckers;
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;
621 SmallVector<CheckEventFunc, 4> Checkers;
623 EventInfo() : HasDispatcher(
false) { }
626 typedef llvm::DenseMap<EventTag, EventInfo> EventsTy;
bool(* HandlesDeclFunc)(const Decl *D)
void _registerForDeadSymbols(CheckDeadSymbolsFunc checkfn)
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.
void runCheckersForEndFunction(NodeBuilderContext &BC, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers on end of function.
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 ...
StringRef getName() const
void _registerForBeginFunction(CheckEndFunctionFunc checkfn)
void _registerForRegionChanges(CheckRegionChangesFunc checkfn)
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 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)
ProgramStateRef runCheckersForRegionChanges(ProgramStateRef state, const InvalidatedSymbols *invalidated, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const LocationContext *LCtx, const CallEvent *Call)
Run checkers for region changes.
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.
CheckerManager(const LangOptions &langOpts, AnalyzerOptions &AOptions)
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)
CheckerFn< ProgramStateRef(ProgramStateRef, const InvalidatedSymbols *symbols, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const LocationContext *LCtx, const CallEvent *Call)> CheckRegionChangesFunc
void runCheckersForBeginFunction(ExplodedNodeSet &Dst, const BlockEdge &L, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers on beginning 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