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;
46struct CheckerRegistryData;
51struct EvalCallOptions;
53class NodeBuilderContext;
55class RegionAndSymbolInvalidationTraits;
61template <
typename RET,
typename... Ps>
63 using Func = RET (*)(
void *, Ps...);
108 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);
174 return *RegistryData;
185 StringRef OptionName,
186 StringRef ExpectedValueDesc)
const;
198 template <
typename CHECKER,
typename... AT>
202 std::unique_ptr<CheckerBackend> &Ref = CheckerTags[Tag];
204 std::unique_ptr<CHECKER>
Checker =
205 std::make_unique<CHECKER>(std::forward<AT>(Args)...);
206 CHECKER::_register(
Checker.get(), *
this);
210 return static_cast<CHECKER *
>(Ref.get());
217 template <
typename CHECKER,
typename... AT>
219 CHECKER *Chk = getChecker<CHECKER>(std::forward<AT>(Args)...);
225 return CheckerTags.contains(getTag<CHECKER>());
267 bool wasInlined =
false) {
275 bool wasInlined =
false);
290 bool wasInlined =
false) {
309 bool wasInlined =
false);
320 bool wasInlined =
false) {
329 bool wasInlined =
false);
441 SVal Cond,
bool Assumption);
466 const char *NL =
"\n",
467 unsigned int Space = 0,
468 bool IsDot =
false)
const;
602 template <
typename EVENT>
604 EventInfo &info = Events[&EVENT::Tag];
605 info.Checkers.push_back(checkfn);
608 template <
typename EVENT>
610 EventInfo &info = Events[&EVENT::Tag];
611 info.HasDispatcher =
true;
614 template <
typename EVENT>
616 EventsTy::const_iterator I = Events.find(&EVENT::Tag);
617 if (I == Events.end())
619 const EventInfo &info = I->second;
620 for (
const auto &
Checker : info.Checkers)
629 template <
typename T>
630 static void *getTag() {
static int tag;
return &tag; }
632 llvm::DenseMap<CheckerTag, std::unique_ptr<CheckerBackend>> CheckerTags;
634 struct DeclCheckerInfo {
638 std::vector<DeclCheckerInfo> DeclCheckers;
640 std::vector<CheckDeclFunc> BodyCheckers;
642 using CachedDeclCheckers = SmallVector<CheckDeclFunc, 4>;
643 using CachedDeclCheckersMapTy = llvm::DenseMap<unsigned, CachedDeclCheckers>;
644 CachedDeclCheckersMapTy CachedDeclCheckersMap;
646 struct StmtCheckerInfo {
651 std::vector<StmtCheckerInfo> StmtCheckers;
653 using CachedStmtCheckers = SmallVector<CheckStmtFunc, 4>;
654 using CachedStmtCheckersMapTy = llvm::DenseMap<unsigned, CachedStmtCheckers>;
655 CachedStmtCheckersMapTy CachedStmtCheckersMap;
657 const CachedStmtCheckers &getCachedStmtCheckersFor(
const Stmt *S,
662 const std::vector<CheckObjCMessageFunc> &
665 std::vector<CheckObjCMessageFunc> PreObjCMessageCheckers;
666 std::vector<CheckObjCMessageFunc> PostObjCMessageCheckers;
667 std::vector<CheckObjCMessageFunc> ObjCMessageNilCheckers;
669 std::vector<CheckCallFunc> PreCallCheckers;
670 std::vector<CheckCallFunc> PostCallCheckers;
672 std::vector<CheckLocationFunc> LocationCheckers;
674 std::vector<CheckBindFunc> BindCheckers;
676 std::vector<CheckBlockEntranceFunc> BlockEntranceCheckers;
678 std::vector<CheckEndAnalysisFunc> EndAnalysisCheckers;
680 std::vector<CheckBeginFunctionFunc> BeginFunctionCheckers;
681 std::vector<CheckEndFunctionFunc> EndFunctionCheckers;
683 std::vector<CheckBranchConditionFunc> BranchConditionCheckers;
685 std::vector<CheckNewAllocatorFunc> NewAllocatorCheckers;
687 std::vector<CheckLiveSymbolsFunc> LiveSymbolsCheckers;
689 std::vector<CheckDeadSymbolsFunc> DeadSymbolsCheckers;
691 std::vector<CheckRegionChangesFunc> RegionChangesCheckers;
693 std::vector<CheckPointerEscapeFunc> PointerEscapeCheckers;
695 std::vector<EvalAssumeFunc> EvalAssumeCheckers;
697 std::vector<EvalCallFunc> EvalCallCheckers;
699 std::vector<CheckEndOfTranslationUnit> EndOfTranslationUnitCheckers;
702 SmallVector<CheckEventFunc, 4> Checkers;
703 bool HasDispatcher =
false;
705 EventInfo() =
default;
708 using EventsTy = llvm::DenseMap<EventTag, EventInfo>;
Defines the Diagnostic-related interfaces.
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN)
enum clang::sema::@1840::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.
CheckerBackend is an abstract base class that serves as the common ancestor of all the Checker<....
CheckerFn(CheckerBackend *checker, Func fn)
RET operator()(Ps... ps) const
A CheckerFrontend instance is what the user recognizes as "one checker": it has a public canonical na...
void _registerForLiveSymbols(CheckLiveSymbolsFunc checkfn)
void _registerForEndOfTranslationUnit(CheckEndOfTranslationUnit checkfn)
const AnalyzerOptions & getAnalyzerOptions() const
void _registerForBeginFunction(CheckBeginFunctionFunc checkfn)
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 _registerForObjCMessageNil(CheckObjCMessageFunc checkfn)
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 _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)
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
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 runCheckersForBind(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, SVal location, SVal val, const Stmt *S, bool AtDeclInit, ExprEngine &Eng, const ProgramPoint &PP)
Run checkers for binding of a value to a location.
void reportInvalidCheckerOptionValue(const CheckerFrontend *Checker, StringRef OptionName, StringRef ExpectedValueDesc) const
Emits an error through a DiagnosticsEngine about an invalid user supplied checker option value.
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 runCheckersForBlockEntrance(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const BlockEntrance &Entrance, ExprEngine &Eng) const
Run checkers after taking a control flow edge.
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 _registerForBlockEntrance(CheckBlockEntranceFunc checkfn)
void _registerDispatcherForEvent()
void runCheckersForBranchCondition(const Stmt *condition, ExplodedNodeSet &Dst, ExplodedNode *Pred, ExprEngine &Eng)
Run checkers for branch condition.
CheckerNameRef getCurrentCheckerName() const
bool isRegisteredChecker()
CHECKER * getChecker(AT &&...Args)
If the the singleton instance of a checker class is not yet constructed, then construct it (with the ...
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 ...
Manages a set of available checkers for running a static analysis.
Simple checker classes that implement one frontend (i.e.
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.
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
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.
int const char * function
Hints for figuring out of a call should be inlined during evalCall().