13 #ifndef LLVM_CLANG_STATICANALYZER_CORE_CHECKERMANAGER_H 14 #define LLVM_CLANG_STATICANALYZER_CORE_CHECKERMANAGER_H 20 #include "llvm/ADT/ArrayRef.h" 21 #include "llvm/ADT/DenseMap.h" 22 #include "llvm/ADT/SmallVector.h" 23 #include "llvm/ADT/StringRef.h" 28 class AnalyzerOptions;
32 class LocationContext;
34 class TranslationUnitDecl;
38 class AnalysisManager;
43 class CheckerRegistry;
46 class ExplodedNodeSet;
49 struct NodeBuilderContext;
51 class RegionAndSymbolInvalidationTraits;
57 template <
typename RET,
typename... Ps>
59 using Func = RET (*)(
void *, Ps...);
69 return Fn(Checker, ps...);
104 friend class ::clang::ento::CheckerRegistry;
114 operator StringRef()
const {
return Name; }
131 : Context(Context), LangOpts(Context.getLangOpts()), AOptions(AOptions) {}
138 bool hasPathSensitiveCheckers()
const;
140 void finishedCheckerRegistration();
148 void reportInvalidCheckerOptionValue(
const CheckerBase *C,
149 StringRef OptionName,
150 StringRef ExpectedValueDesc);
165 template <
typename CHECKER,
typename... AT>
169 assert(!ref &&
"Checker already registered, use getChecker!");
172 checker->Name = CurrentCheckerName;
173 CheckerDtors.push_back(
CheckerDtor(checker, destruct<CHECKER>));
174 CHECKER::_register(checker, *
this);
179 template <
typename CHECKER>
182 assert(CheckerTags.count(tag) != 0 &&
183 "Requested checker is not registered! Maybe you should add it as a " 184 "dependency in Checkers.td?");
185 return static_cast<CHECKER *
>(CheckerTags[tag]);
214 runCheckersForStmt(
true, Dst, Src, S, Eng);
227 bool wasInlined =
false) {
228 runCheckersForStmt(
false, Dst, Src, S, Eng, wasInlined);
232 void runCheckersForStmt(
bool isPreVisit,
235 bool wasInlined =
false);
250 bool wasInlined =
false) {
269 bool wasInlined =
false);
274 runCheckersForCallEvent(
true, Dst, Src, Call, Eng);
280 bool wasInlined =
false) {
281 runCheckersForCallEvent(
false, Dst, Src, Call, Eng,
289 bool wasInlined =
false);
325 void runCheckersForBranchCondition(
const Stmt *condition,
334 bool wasInlined =
false);
398 SVal Cond,
bool Assumption);
422 void runCheckersForPrintStateJson(raw_ostream &Out,
ProgramStateRef State,
423 const char *NL =
"\n",
424 unsigned int Space = 0,
425 bool IsDot =
false)
const;
557 template <
typename EVENT>
559 EventInfo &info = Events[&EVENT::Tag];
560 info.Checkers.push_back(checkfn);
563 template <
typename EVENT>
565 EventInfo &info = Events[&EVENT::Tag];
566 info.HasDispatcher =
true;
569 template <
typename EVENT>
571 EventsTy::const_iterator I = Events.find(&EVENT::Tag);
572 if (I == Events.end())
574 const EventInfo &info = I->second;
575 for (
const auto &
Checker : info.Checkers)
584 template <
typename CHECKER>
585 static void destruct(
void *obj) {
delete static_cast<CHECKER *
>(obj); }
587 template <
typename T>
588 static void *getTag() {
static int tag;
return &tag; }
590 llvm::DenseMap<CheckerTag, CheckerRef> CheckerTags;
592 std::vector<CheckerDtor> CheckerDtors;
594 struct DeclCheckerInfo {
598 std::vector<DeclCheckerInfo> DeclCheckers;
600 std::vector<CheckDeclFunc> BodyCheckers;
603 using CachedDeclCheckersMapTy = llvm::DenseMap<unsigned, CachedDeclCheckers>;
604 CachedDeclCheckersMapTy CachedDeclCheckersMap;
606 struct StmtCheckerInfo {
611 std::vector<StmtCheckerInfo> StmtCheckers;
614 using CachedStmtCheckersMapTy = llvm::DenseMap<unsigned, CachedStmtCheckers>;
615 CachedStmtCheckersMapTy CachedStmtCheckersMap;
622 const std::vector<CheckObjCMessageFunc> &
625 std::vector<CheckObjCMessageFunc> PreObjCMessageCheckers;
626 std::vector<CheckObjCMessageFunc> PostObjCMessageCheckers;
627 std::vector<CheckObjCMessageFunc> ObjCMessageNilCheckers;
629 std::vector<CheckCallFunc> PreCallCheckers;
630 std::vector<CheckCallFunc> PostCallCheckers;
632 std::vector<CheckLocationFunc> LocationCheckers;
634 std::vector<CheckBindFunc> BindCheckers;
636 std::vector<CheckEndAnalysisFunc> EndAnalysisCheckers;
638 std::vector<CheckBeginFunctionFunc> BeginFunctionCheckers;
639 std::vector<CheckEndFunctionFunc> EndFunctionCheckers;
641 std::vector<CheckBranchConditionFunc> BranchConditionCheckers;
643 std::vector<CheckNewAllocatorFunc> NewAllocatorCheckers;
645 std::vector<CheckLiveSymbolsFunc> LiveSymbolsCheckers;
647 std::vector<CheckDeadSymbolsFunc> DeadSymbolsCheckers;
649 std::vector<CheckRegionChangesFunc> RegionChangesCheckers;
651 std::vector<CheckPointerEscapeFunc> PointerEscapeCheckers;
653 std::vector<EvalAssumeFunc> EvalAssumeCheckers;
655 std::vector<EvalCallFunc> EvalCallCheckers;
657 std::vector<CheckEndOfTranslationUnit> EndOfTranslationUnitCheckers;
661 bool HasDispatcher =
false;
663 EventInfo() =
default;
666 using EventsTy = llvm::DenseMap<EventTag, EventInfo>;
674 #endif // LLVM_CLANG_STATICANALYZER_CORE_CHECKERMANAGER_H
This wrapper is used to ensure that only StringRefs originating from the CheckerRegistry are used as ...
void _dispatchEvent(const EVENT &event) const
Stmt - This represents one statement.
Information about invalidation for a particular region/symbol.
#define CHECKER(FULLNAME, CLASS, HELPTEXT, DOC_URI, IS_HIDDEN)
void setCurrentCheckerName(CheckerNameRef name)
Decl - This represents one declaration (or definition), e.g.
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 ...
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...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions)
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
Represents any expression that calls an Objective-C method.
bool(*)(const Stmt *D) HandlesStmtFunc
void runCheckersForPreCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
void runCheckersForPostCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting obj-c messages.
Escape for a new symbol that was generated into a region that the analyzer cannot follow during a con...
StringRef getName() const
CheckerFn(CheckerBase *checker, Func fn)
CheckerNameRef getCurrentCheckerName() const
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.
void runCheckersForPreObjCMessage(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const ObjCMethodCall &msg, ExprEngine &Eng)
Run checkers for pre-visiting obj-c messages.
The pointer has been passed to a function call directly.
RET operator()(Ps... ps) const
The reason for pointer escape is unknown.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
BugReporter is a utility class for generating PathDiagnostics for analysis.
void _registerListenerForEvent(CheckEventFunc checkfn)
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
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.
void _registerDispatcherForEvent()
void runCheckersForPreStmt(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const Stmt *S, ExprEngine &Eng)
Run checkers for pre-visiting Stmts.
Dataflow Directional Tag Classes.
bool NE(InterpState &S, CodePtr OpPC)
Represents an abstract call to a function or method along a particular path.
AnalyzerOptions & getAnalyzerOptions()
PointerEscapeKind
Describes the different reasons a pointer escapes during analysis.
Stores options for the analyzer from the command line.
bool(*)(const Decl *D) HandlesDeclFunc
The top declaration context.
ASTContext & getASTContext()
const LangOptions & getLangOpts() const