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"
34class TranslationUnitDecl;
39class CXXAllocatorCall;
45struct CheckerRegistryData;
50struct EvalCallOptions;
52class NodeBuilderContext;
54class RegionAndSymbolInvalidationTraits;
60template <
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;
590 template <
typename EVENT>
592 EventInfo &info = Events[&EVENT::Tag];
593 info.Checkers.push_back(checkfn);
596 template <
typename EVENT>
598 EventInfo &info = Events[&EVENT::Tag];
599 info.HasDispatcher =
true;
602 template <
typename EVENT>
604 EventsTy::const_iterator I = Events.find(&EVENT::Tag);
605 if (I == Events.end())
607 const EventInfo &info = I->second;
608 for (
const auto &
Checker : info.Checkers)
617 template <
typename CHECKER>
618 static void destruct(
void *obj) {
delete static_cast<CHECKER *
>(obj); }
620 template <
typename T>
621 static void *getTag() {
static int tag;
return &tag; }
623 llvm::DenseMap<CheckerTag, CheckerRef> CheckerTags;
625 std::vector<CheckerDtor> CheckerDtors;
627 struct DeclCheckerInfo {
631 std::vector<DeclCheckerInfo> DeclCheckers;
633 std::vector<CheckDeclFunc> BodyCheckers;
635 using CachedDeclCheckers = SmallVector<CheckDeclFunc, 4>;
636 using CachedDeclCheckersMapTy = llvm::DenseMap<unsigned, CachedDeclCheckers>;
637 CachedDeclCheckersMapTy CachedDeclCheckersMap;
639 struct StmtCheckerInfo {
644 std::vector<StmtCheckerInfo> StmtCheckers;
646 using CachedStmtCheckers = SmallVector<CheckStmtFunc, 4>;
647 using CachedStmtCheckersMapTy = llvm::DenseMap<unsigned, CachedStmtCheckers>;
648 CachedStmtCheckersMapTy CachedStmtCheckersMap;
650 const CachedStmtCheckers &getCachedStmtCheckersFor(
const Stmt *S,
655 const std::vector<CheckObjCMessageFunc> &
658 std::vector<CheckObjCMessageFunc> PreObjCMessageCheckers;
659 std::vector<CheckObjCMessageFunc> PostObjCMessageCheckers;
660 std::vector<CheckObjCMessageFunc> ObjCMessageNilCheckers;
662 std::vector<CheckCallFunc> PreCallCheckers;
663 std::vector<CheckCallFunc> PostCallCheckers;
665 std::vector<CheckLocationFunc> LocationCheckers;
667 std::vector<CheckBindFunc> BindCheckers;
669 std::vector<CheckEndAnalysisFunc> EndAnalysisCheckers;
671 std::vector<CheckBeginFunctionFunc> BeginFunctionCheckers;
672 std::vector<CheckEndFunctionFunc> EndFunctionCheckers;
674 std::vector<CheckBranchConditionFunc> BranchConditionCheckers;
676 std::vector<CheckNewAllocatorFunc> NewAllocatorCheckers;
678 std::vector<CheckLiveSymbolsFunc> LiveSymbolsCheckers;
680 std::vector<CheckDeadSymbolsFunc> DeadSymbolsCheckers;
682 std::vector<CheckRegionChangesFunc> RegionChangesCheckers;
684 std::vector<CheckPointerEscapeFunc> PointerEscapeCheckers;
686 std::vector<EvalAssumeFunc> EvalAssumeCheckers;
688 std::vector<EvalCallFunc> EvalCallCheckers;
690 std::vector<CheckEndOfTranslationUnit> EndOfTranslationUnitCheckers;
693 SmallVector<CheckEventFunc, 4> Checkers;
694 bool HasDispatcher =
false;
696 EventInfo() =
default;
699 using EventsTy = llvm::DenseMap<EventTag, EventInfo>;
Defines the Diagnostic-related interfaces.
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN)
enum clang::sema::@1653::IndirectLocalPathEntry::EntryKind Kind
Defines the clang::LangOptions interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Stores options for the analyzer from the command line.
Decl - This represents one declaration (or definition), e.g.
Concrete class used by the front-end to report problems and issues.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Stmt - This represents one statement.
The top declaration context.
BugReporter is a utility class for generating PathDiagnostics for analysis.
Represents the memory allocation call in a C++ new-expression.
Represents an abstract call to a function or method along a particular path.
CheckerFn(CheckerBase *checker, Func fn)
RET operator()(Ps... ps) const
void _registerForLiveSymbols(CheckLiveSymbolsFunc checkfn)
void _registerForEndOfTranslationUnit(CheckEndOfTranslationUnit checkfn)
const AnalyzerOptions & getAnalyzerOptions() const
void _registerForBeginFunction(CheckBeginFunctionFunc 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.
void _registerForNewAllocator(CheckNewAllocatorFunc checkfn)
void runCheckersForPreObjCMessage(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
void _registerForPreCall(CheckCallFunc checkfn)
void finishedCheckerRegistration()
void _registerForObjCMessageNil(CheckObjCMessageFunc checkfn)
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
bool(*)(const Decl *D) HandlesDeclFunc
void runCheckersForObjCMessage(ObjCMessageVisitKind visitKind, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting obj-c messages.
void runCheckersOnASTDecl(const Decl *D, AnalysisManager &mgr, BugReporter &BR)
Run checkers handling Decls.
void reportInvalidCheckerOptionValue(const CheckerBase *C, StringRef OptionName, StringRef ExpectedValueDesc) const
Emits an error through a DiagnosticsEngine about an invalid user supplied checker option value.
void _registerForDecl(CheckDeclFunc checkfn, HandlesDeclFunc isForDeclFn)
void _registerForPreObjCMessage(CheckObjCMessageFunc checkfn)
void runCheckersOnEndOfTranslationUnit(const TranslationUnitDecl *TU, AnalysisManager &mgr, BugReporter &BR)
Run checkers for the entire Translation Unit.
void runCheckersForEndFunction(NodeBuilderContext &BC, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng, const ReturnStmt *RS)
Run checkers on end of function.
ASTContext & getASTContext() const
void _registerListenerForEvent(CheckEventFunc checkfn)
void _registerForEvalAssume(EvalAssumeFunc checkfn)
void _registerForEndAnalysis(CheckEndAnalysisFunc checkfn)
void _registerForBody(CheckDeclFunc checkfn)
DiagnosticsEngine & getDiagnostics() const
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.
const CheckerRegistryData & getCheckerRegistryData() const
CheckerFn< void(const Stmt *, CheckerContext &)> CheckStmtFunc
void runCheckersForEndAnalysis(ExplodedGraph &G, BugReporter &BR, ExprEngine &Eng)
Run checkers for end of analysis.
CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions, const Preprocessor &PP)
Constructs a CheckerManager that ignores all non TblGen-generated checkers.
void runCheckersForPreCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
CheckerFn< void(const Decl *, AnalysisManager &, BugReporter &)> CheckDeclFunc
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 _registerForDeadSymbols(CheckDeadSymbolsFunc checkfn)
void runCheckersForDeadSymbols(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, SymbolReaper &SymReaper, const Stmt *S, ExprEngine &Eng, ProgramPoint::Kind K)
Run checkers for dead symbols.
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 _registerForPostObjCMessage(CheckObjCMessageFunc checkfn)
void _registerForRegionChanges(CheckRegionChangesFunc checkfn)
bool hasPathSensitiveCheckers() const
void _registerForBind(CheckBindFunc checkfn)
void runCheckersForLiveSymbols(ProgramStateRef state, SymbolReaper &SymReaper)
Run checkers for live symbols.
void _registerForPointerEscape(CheckPointerEscapeFunc checkfn)
void _registerForPreStmt(CheckStmtFunc checkfn, HandlesStmtFunc isForStmtFn)
void runCheckersForEvalCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &CE, ExprEngine &Eng, const EvalCallOptions &CallOpts)
Run checkers for evaluating a call.
void _registerForPostStmt(CheckStmtFunc checkfn, HandlesStmtFunc isForStmtFn)
void runCheckersForPostObjCMessage(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting obj-c messages.
void runCheckersForBeginFunction(ExplodedNodeSet &Dst, const BlockEdge &L, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers on beginning of function.
void runCheckersForPostStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting Stmts.
void runCheckersForNewAllocator(const CXXAllocatorCall &Call, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng, bool wasInlined=false)
Run checkers between C++ operator new and constructor calls.
void runCheckersForPreStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng)
Run checkers for pre-visiting Stmts.
void _registerForBranchCondition(CheckBranchConditionFunc checkfn)
void runCheckersForObjCMessageNil(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng)
Run checkers for visiting an obj-c message to nil.
void _dispatchEvent(const EVENT &event) const
void runCheckersForStmt(bool isPreVisit, ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng, bool wasInlined=false)
Run checkers for visiting Stmts.
const LangOptions & getLangOpts() const
void _registerForEvalCall(EvalCallFunc checkfn)
void _registerForEndFunction(CheckEndFunctionFunc checkfn)
void _registerDispatcherForEvent()
void runCheckersForBranchCondition(const Stmt *condition, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers for branch condition.
CheckerNameRef getCurrentCheckerName() const
CheckerFn< void()> CheckerDtor
void _registerForLocation(CheckLocationFunc checkfn)
ProgramStateRef runCheckersForPointerEscape(ProgramStateRef State, const InvalidatedSymbols &Escaped, const CallEvent *Call, PointerEscapeKind Kind, RegionAndSymbolInvalidationTraits *ITraits)
Run checkers when pointers escape.
void _registerForConstPointerEscape(CheckPointerEscapeFunc 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.
bool(*)(const Stmt *D) HandlesStmtFunc
void _registerForPostCall(CheckCallFunc checkfn)
void runCheckersOnASTBody(const Decl *D, AnalysisManager &mgr, BugReporter &BR)
Run checkers handling Decls containing a Stmt body.
void runCheckersForPostCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting obj-c messages.
void setCurrentCheckerName(CheckerNameRef name)
ProgramStateRef runCheckersForEvalAssume(ProgramStateRef state, SVal Cond, bool Assumption)
Run checkers for handling assumptions on symbolic values.
const Preprocessor & getPreprocessor() const
This wrapper is used to ensure that only StringRefs originating from the CheckerRegistry are used as ...
StringRef getName() const
Manages a set of available checkers for running a static analysis.
Represents any expression that calls an Objective-C method.
Information about invalidation for a particular region/symbol.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
A class responsible for cleaning up unused symbols.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.
@ PSK_DirectEscapeOnCall
The pointer has been passed to a function call directly.
@ PSK_EscapeOnBind
A pointer escapes due to binding its value to a location that the analyzer cannot track.
@ PSK_IndirectEscapeOnCall
The pointer has been passed to a function indirectly.
@ PSK_EscapeOther
The reason for pointer escape is unknown.
@ PSK_EscapeOutParameters
Escape for a new symbol that was generated into a region that the analyzer cannot follow during a con...
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
llvm::DenseSet< SymbolRef > InvalidatedSymbols
The JSON file list parser is used to communicate input to InstallAPI.
Hints for figuring out of a call should be inlined during evalCall().