Go to the documentation of this file.
13 #ifndef LLVM_CLANG_STATICANALYZER_CORE_CHECKERMANAGER_H
14 #define LLVM_CLANG_STATICANALYZER_CORE_CHECKERMANAGER_H
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringRef.h"
29 class AnalyzerOptions;
32 class LocationContext;
34 class TranslationUnitDecl;
38 class AnalysisManager;
39 class CXXAllocatorCall;
44 class CheckerRegistry;
45 struct CheckerRegistryData;
48 class ExplodedNodeSet;
50 struct EvalCallOptions;
52 struct NodeBuilderContext;
54 class RegionAndSymbolInvalidationTraits;
60 template <
typename RET,
typename... Ps>
62 using Func = RET (*)(
void *, Ps...);
107 friend class ::clang::ento::CheckerRegistry;
117 operator StringRef()
const {
return Name; }
133 std::unique_ptr<CheckerRegistryData> RegistryData;
157 CheckerManager(AnalyzerOptions &AOptions,
const LangOptions &LangOpts,
158 DiagnosticsEngine &Diags, ArrayRef<std::string> plugins);
176 return *RegistryData;
187 StringRef OptionName,
188 StringRef ExpectedValueDesc)
const;
203 template <
typename CHECKER,
typename... AT>
207 assert(!ref &&
"Checker already registered, use getChecker!");
210 checker->Name = CurrentCheckerName;
211 CheckerDtors.push_back(
CheckerDtor(checker, destruct<CHECKER>));
212 CHECKER::_register(checker, *
this);
217 template <
typename CHECKER>
220 assert(CheckerTags.count(tag) != 0 &&
221 "Requested checker is not registered! Maybe you should add it as a "
222 "dependency in Checkers.td?");
223 return static_cast<CHECKER *
>(CheckerTags[tag]);
265 bool wasInlined =
false) {
273 bool wasInlined =
false);
288 bool wasInlined =
false) {
307 bool wasInlined =
false);
318 bool wasInlined =
false) {
327 bool wasInlined =
false);
434 SVal Cond,
bool Assumption);
459 const char *NL =
"\n",
460 unsigned int Space = 0,
461 bool IsDot =
false)
const;
593 template <
typename EVENT>
595 EventInfo &info = Events[&EVENT::Tag];
596 info.Checkers.push_back(checkfn);
599 template <
typename EVENT>
601 EventInfo &info = Events[&EVENT::Tag];
602 info.HasDispatcher =
true;
605 template <
typename EVENT>
607 EventsTy::const_iterator I = Events.find(&EVENT::Tag);
608 if (I == Events.end())
610 const EventInfo &info = I->second;
611 for (
const auto &
Checker : info.Checkers)
620 template <
typename CHECKER>
621 static void destruct(
void *obj) {
delete static_cast<CHECKER *
>(obj); }
623 template <
typename T>
624 static void *getTag() {
static int tag;
return &tag; }
626 llvm::DenseMap<CheckerTag, CheckerRef> CheckerTags;
628 std::vector<CheckerDtor> CheckerDtors;
630 struct DeclCheckerInfo {
634 std::vector<DeclCheckerInfo> DeclCheckers;
636 std::vector<CheckDeclFunc> BodyCheckers;
638 using CachedDeclCheckers = SmallVector<CheckDeclFunc, 4>;
639 using CachedDeclCheckersMapTy = llvm::DenseMap<unsigned, CachedDeclCheckers>;
640 CachedDeclCheckersMapTy CachedDeclCheckersMap;
642 struct StmtCheckerInfo {
647 std::vector<StmtCheckerInfo> StmtCheckers;
649 using CachedStmtCheckers = SmallVector<CheckStmtFunc, 4>;
650 using CachedStmtCheckersMapTy = llvm::DenseMap<unsigned, CachedStmtCheckers>;
651 CachedStmtCheckersMapTy CachedStmtCheckersMap;
653 const CachedStmtCheckers &getCachedStmtCheckersFor(
const Stmt *S,
658 const std::vector<CheckObjCMessageFunc> &
661 std::vector<CheckObjCMessageFunc> PreObjCMessageCheckers;
662 std::vector<CheckObjCMessageFunc> PostObjCMessageCheckers;
663 std::vector<CheckObjCMessageFunc> ObjCMessageNilCheckers;
665 std::vector<CheckCallFunc> PreCallCheckers;
666 std::vector<CheckCallFunc> PostCallCheckers;
668 std::vector<CheckLocationFunc> LocationCheckers;
670 std::vector<CheckBindFunc> BindCheckers;
672 std::vector<CheckEndAnalysisFunc> EndAnalysisCheckers;
674 std::vector<CheckBeginFunctionFunc> BeginFunctionCheckers;
675 std::vector<CheckEndFunctionFunc> EndFunctionCheckers;
677 std::vector<CheckBranchConditionFunc> BranchConditionCheckers;
679 std::vector<CheckNewAllocatorFunc> NewAllocatorCheckers;
681 std::vector<CheckLiveSymbolsFunc> LiveSymbolsCheckers;
683 std::vector<CheckDeadSymbolsFunc> DeadSymbolsCheckers;
685 std::vector<CheckRegionChangesFunc> RegionChangesCheckers;
687 std::vector<CheckPointerEscapeFunc> PointerEscapeCheckers;
689 std::vector<EvalAssumeFunc> EvalAssumeCheckers;
691 std::vector<EvalCallFunc> EvalCallCheckers;
693 std::vector<CheckEndOfTranslationUnit> EndOfTranslationUnitCheckers;
696 SmallVector<CheckEventFunc, 4> Checkers;
697 bool HasDispatcher =
false;
699 EventInfo() =
default;
702 using EventsTy = llvm::DenseMap<EventTag, EventInfo>;
710 #endif // LLVM_CLANG_STATICANALYZER_CORE_CHECKERMANAGER_H
void runCheckersForObjCMessageNil(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng)
Run checkers for visiting an obj-c message to nil.
void runCheckersOnASTBody(const Decl *D, AnalysisManager &mgr, BugReporter &BR)
Run checkers handling Decls containing a Stmt body.
@ PSK_DirectEscapeOnCall
The pointer has been passed to a function call directly.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
void runCheckersForPreObjCMessage(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
void runCheckersForBeginFunction(ExplodedNodeSet &Dst, const BlockEdge &L, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers on beginning of function.
void _registerForConstPointerEscape(CheckPointerEscapeFunc checkfn)
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
CheckerNameRef getCurrentCheckerName() const
void runCheckersForLiveSymbols(ProgramStateRef state, SymbolReaper &SymReaper)
Run checkers for live symbols.
const LangOptions & getLangOpts() const
RET operator()(Ps... ps) const
void _registerForBranchCondition(CheckBranchConditionFunc checkfn)
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const AnalyzerOptions & getAnalyzerOptions() const
void runCheckersForObjCMessage(ObjCMessageVisitKind visitKind, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting obj-c messages.
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.
void runCheckersForEndFunction(NodeBuilderContext &BC, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng, const ReturnStmt *RS)
Run checkers on end of function.
Concrete class used by the front-end to report problems and issues.
CheckerFn< void()> CheckerDtor
void runCheckersForEvalCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &CE, ExprEngine &Eng, const EvalCallOptions &CallOpts)
Run checkers for evaluating a call.
void runCheckersForBranchCondition(const Stmt *condition, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers for branch condition.
void _registerForRegionChanges(CheckRegionChangesFunc checkfn)
void _registerForObjCMessageNil(CheckObjCMessageFunc checkfn)
void _registerForBody(CheckDeclFunc checkfn)
void runCheckersForPostCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting obj-c messages.
void runCheckersForPrintStateJson(raw_ostream &Out, ProgramStateRef State, const char *NL="\n", unsigned int Space=0, bool IsDot=false) const
Run checkers for debug-printing a ProgramState.
void setCurrentCheckerName(CheckerNameRef name)
const CheckerRegistryData & getCheckerRegistryData() const
void _dispatchEvent(const EVENT &event) const
void _registerForBind(CheckBindFunc checkfn)
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
void runCheckersForEndAnalysis(ExplodedGraph &G, BugReporter &BR, ExprEngine &Eng)
Run checkers for end of analysis.
The top declaration context.
Hints for figuring out of a call should be inlined during evalCall().
CheckerFn< void(const Stmt *, CheckerContext &)> CheckStmtFunc
void _registerForPointerEscape(CheckPointerEscapeFunc checkfn)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN)
void _registerForEndOfTranslationUnit(CheckEndOfTranslationUnit checkfn)
bool hasPathSensitiveCheckers() const
@ PSK_EscapeOutParameters
Escape for a new symbol that was generated into a region that the analyzer cannot follow during a con...
void _registerForEvalCall(EvalCallFunc checkfn)
void runCheckersForNewAllocator(const CXXAllocatorCall &Call, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng, bool wasInlined=false)
Run checkers between C++ operator new and constructor calls.
void runCheckersForStmt(bool isPreVisit, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting Stmts.
This wrapper is used to ensure that only StringRefs originating from the CheckerRegistry are used as ...
void _registerForLocation(CheckLocationFunc checkfn)
Represents the memory allocation call in a C++ new-expression.
void _registerForPreStmt(CheckStmtFunc checkfn, HandlesStmtFunc isForStmtFn)
A class responsible for cleaning up unused symbols.
void _registerForNewAllocator(CheckNewAllocatorFunc checkfn)
void runCheckersForCallEvent(bool isPreVisit, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting obj-c messages.
BugReporter is a utility class for generating PathDiagnostics for analysis.
void _registerForPreCall(CheckCallFunc checkfn)
void runCheckersForPreCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
and static some checkers Checker The latter are built on top of the former via the Checker and CheckerVisitor and attempts to isolate them from much of the gore of the internal analysis the analyzer is basically a source code simulator that traces out possible paths of execution The state of the and the combination of state and program point is a node in an exploded which has the entry program point and initial state
void _registerForPostStmt(CheckStmtFunc checkfn, HandlesStmtFunc isForStmtFn)
ASTContext & getASTContext() const
const Preprocessor & getPreprocessor() const
@ PSK_EscapeOther
The reason for pointer escape is unknown.
DiagnosticsEngine & getDiagnostics() const
void _registerForPostObjCMessage(CheckObjCMessageFunc checkfn)
bool(*)(const Stmt *D) HandlesStmtFunc
void runCheckersForPostStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting Stmts.
Decl - This represents one declaration (or definition), e.g.
void _registerForDeadSymbols(CheckDeadSymbolsFunc checkfn)
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.
Stores options for the analyzer from the command line.
void runCheckersForDeadSymbols(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, SymbolReaper &SymReaper, const Stmt *S, ExprEngine &Eng, ProgramPoint::Kind K)
Run checkers for dead symbols.
void runCheckersOnASTDecl(const Decl *D, AnalysisManager &mgr, BugReporter &BR)
Run checkers handling Decls.
Represents any expression that calls an Objective-C method.
void reportInvalidCheckerOptionValue(const CheckerBase *C, StringRef OptionName, StringRef ExpectedValueDesc) const
Emits an error through a DiagnosticsEngine about an invalid user supplied checker option value.
@ PSK_IndirectEscapeOnCall
The pointer has been passed to a function indirectly.
void _registerForEvalAssume(EvalAssumeFunc checkfn)
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.
void _registerForEndFunction(CheckEndFunctionFunc checkfn)
StringRef getName() const
CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions, const Preprocessor &PP)
Constructs a CheckerManager that ignores all non TblGen-generated checkers.
void _registerForBeginFunction(CheckBeginFunctionFunc checkfn)
Stmt - This represents one statement.
CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions, const Preprocessor &PP, ArrayRef< std::string > plugins, ArrayRef< std::function< void(CheckerRegistry &)>> checkerRegistrationFns)
Represents an abstract call to a function or method along a particular path.
ProgramStateRef runCheckersForEvalAssume(ProgramStateRef state, SVal Cond, bool Assumption)
Run checkers for handling assumptions on symbolic values.
CheckerFn< void(const Decl *, AnalysisManager &, BugReporter &)> CheckDeclFunc
@ PSK_EscapeOnBind
A pointer escapes due to binding its value to a location that the analyzer cannot track.
void _registerDispatcherForEvent()
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.
void _registerForPostCall(CheckCallFunc checkfn)
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
void finishedCheckerRegistration()
CheckerFn(CheckerBase *checker, Func fn)
Information about invalidation for a particular region/symbol.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void runCheckersOnEndOfTranslationUnit(const TranslationUnitDecl *TU, AnalysisManager &mgr, BugReporter &BR)
Run checkers for the entire Translation Unit.
ProgramStateRef runCheckersForPointerEscape(ProgramStateRef State, const InvalidatedSymbols &Escaped, const CallEvent *Call, PointerEscapeKind Kind, RegionAndSymbolInvalidationTraits *ITraits)
Run checkers when pointers escape.
void runCheckersForPreStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng)
Run checkers for pre-visiting Stmts.
void _registerListenerForEvent(CheckEventFunc checkfn)
void _registerForLiveSymbols(CheckLiveSymbolsFunc checkfn)
bool(*)(const Decl *D) HandlesDeclFunc
void _registerForEndAnalysis(CheckEndAnalysisFunc checkfn)
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.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Manages a set of available checkers for running a static analysis.
void _registerForDecl(CheckDeclFunc checkfn, HandlesDeclFunc isForDeclFn)
void _registerForPreObjCMessage(CheckObjCMessageFunc checkfn)