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...);
98 friend class ::clang::ento::CheckerRegistry;
102 explicit CheckName(StringRef Name) : Name(Name) {}
124 : Context(Context), LangOpts(Context.getLangOpts()), AOptions(AOptions) {}
131 bool hasPathSensitiveCheckers()
const;
133 void finishedCheckerRegistration();
141 void reportInvalidCheckerOptionValue(
const CheckerBase *C,
142 StringRef OptionName,
143 StringRef ExpectedValueDesc);
158 template <
typename CHECKER,
typename... AT>
162 assert(!ref &&
"Checker already registered, use getChecker!");
165 checker->Name = CurrentCheckName;
166 CheckerDtors.push_back(
CheckerDtor(checker, destruct<CHECKER>));
167 CHECKER::_register(checker, *
this);
172 template <
typename CHECKER>
175 assert(CheckerTags.count(tag) != 0 &&
176 "Requested checker is not registered! Maybe you should add it as a " 177 "dependency in Checkers.td?");
178 return static_cast<CHECKER *
>(CheckerTags[tag]);
207 runCheckersForStmt(
true, Dst, Src, S, Eng);
220 bool wasInlined =
false) {
221 runCheckersForStmt(
false, Dst, Src, S, Eng, wasInlined);
225 void runCheckersForStmt(
bool isPreVisit,
228 bool wasInlined =
false);
243 bool wasInlined =
false) {
262 bool wasInlined =
false);
267 runCheckersForCallEvent(
true, Dst, Src, Call, Eng);
273 bool wasInlined =
false) {
274 runCheckersForCallEvent(
false, Dst, Src, Call, Eng,
282 bool wasInlined =
false);
318 void runCheckersForBranchCondition(
const Stmt *condition,
327 bool wasInlined =
false);
391 SVal Cond,
bool Assumption);
415 void runCheckersForPrintStateJson(raw_ostream &Out,
ProgramStateRef State,
416 const char *NL =
"\n",
417 unsigned int Space = 0,
418 bool IsDot =
false)
const;
550 template <
typename EVENT>
552 EventInfo &info = Events[&EVENT::Tag];
553 info.Checkers.push_back(checkfn);
556 template <
typename EVENT>
558 EventInfo &info = Events[&EVENT::Tag];
559 info.HasDispatcher =
true;
562 template <
typename EVENT>
564 EventsTy::const_iterator I = Events.find(&EVENT::Tag);
565 if (I == Events.end())
567 const EventInfo &info = I->second;
568 for (
const auto Checker : info.Checkers)
577 template <
typename CHECKER>
578 static void destruct(
void *obj) {
delete static_cast<CHECKER *
>(obj); }
580 template <
typename T>
581 static void *getTag() {
static int tag;
return &tag; }
583 llvm::DenseMap<CheckerTag, CheckerRef> CheckerTags;
585 std::vector<CheckerDtor> CheckerDtors;
587 struct DeclCheckerInfo {
591 std::vector<DeclCheckerInfo> DeclCheckers;
593 std::vector<CheckDeclFunc> BodyCheckers;
596 using CachedDeclCheckersMapTy = llvm::DenseMap<unsigned, CachedDeclCheckers>;
597 CachedDeclCheckersMapTy CachedDeclCheckersMap;
599 struct StmtCheckerInfo {
604 std::vector<StmtCheckerInfo> StmtCheckers;
607 using CachedStmtCheckersMapTy = llvm::DenseMap<unsigned, CachedStmtCheckers>;
608 CachedStmtCheckersMapTy CachedStmtCheckersMap;
615 const std::vector<CheckObjCMessageFunc> &
618 std::vector<CheckObjCMessageFunc> PreObjCMessageCheckers;
619 std::vector<CheckObjCMessageFunc> PostObjCMessageCheckers;
620 std::vector<CheckObjCMessageFunc> ObjCMessageNilCheckers;
622 std::vector<CheckCallFunc> PreCallCheckers;
623 std::vector<CheckCallFunc> PostCallCheckers;
625 std::vector<CheckLocationFunc> LocationCheckers;
627 std::vector<CheckBindFunc> BindCheckers;
629 std::vector<CheckEndAnalysisFunc> EndAnalysisCheckers;
631 std::vector<CheckBeginFunctionFunc> BeginFunctionCheckers;
632 std::vector<CheckEndFunctionFunc> EndFunctionCheckers;
634 std::vector<CheckBranchConditionFunc> BranchConditionCheckers;
636 std::vector<CheckNewAllocatorFunc> NewAllocatorCheckers;
638 std::vector<CheckLiveSymbolsFunc> LiveSymbolsCheckers;
640 std::vector<CheckDeadSymbolsFunc> DeadSymbolsCheckers;
642 std::vector<CheckRegionChangesFunc> RegionChangesCheckers;
644 std::vector<CheckPointerEscapeFunc> PointerEscapeCheckers;
646 std::vector<EvalAssumeFunc> EvalAssumeCheckers;
648 std::vector<EvalCallFunc> EvalCallCheckers;
650 std::vector<CheckEndOfTranslationUnit> EndOfTranslationUnitCheckers;
654 bool HasDispatcher =
false;
656 EventInfo() =
default;
659 using EventsTy = llvm::DenseMap<EventTag, EventInfo>;
667 #endif // LLVM_CLANG_STATICANALYZER_CORE_CHECKERMANAGER_H
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)
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 setCurrentCheckName(CheckName name)
void runCheckersForPostCall(ExplodedNodeSet &Dst, const ExplodedNodeSet &Src, const CallEvent &Call, ExprEngine &Eng, bool wasInlined=false)
Run checkers for post-visiting obj-c messages.
CheckName getCurrentCheckName() const
CheckerFn(CheckerBase *checker, Func fn)
StringRef getName() 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.
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