clang 24.0.0git
AnalysisManager.h
Go to the documentation of this file.
1//== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the AnalysisManager class that manages the data and policy
10// for path sensitive analysis.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
15#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
16
23
24namespace clang {
25
26class CodeInjector;
27class Preprocessor;
28
29namespace ento {
30 class CheckerManager;
31
33 virtual void anchor();
35
36 ASTContext &Ctx;
37 Preprocessor &PP;
38 const LangOptions &LangOpts;
39 PathDiagnosticConsumers PathConsumers;
40
41 // Configurable components creators.
42 StoreManagerCreator CreateStoreMgr;
43 ConstraintManagerCreator CreateConstraintMgr;
44
45 CheckerManager *CheckerMgr;
46
47public:
49
52 StoreManagerCreator storemgr,
53 ConstraintManagerCreator constraintmgr,
54 CheckerManager *checkerMgr, AnalyzerOptions &Options,
55 std::unique_ptr<CodeInjector> injector = nullptr);
56
57 ~AnalysisManager() override;
58
60 AnaCtxMgr.clear();
61 }
62
66
67 Preprocessor &getPreprocessor() override { return PP; }
68
70 return CreateStoreMgr;
71 }
72
74 return options;
75 }
76
78 return CreateConstraintMgr;
79 }
80
81 CheckerManager *getCheckerManager() const { return CheckerMgr; }
82
84 return Ctx;
85 }
86
90
91 const LangOptions &getLangOpts() const {
92 return LangOpts;
93 }
94
97 return PathConsumers;
98 }
99
100 void FlushDiagnostics();
101
102 bool shouldVisualize() const {
103 return options.visualizeExplodedGraphWithGraphViz;
104 }
105
106 bool shouldInlineCall() const {
107 return options.getIPAMode() != IPAK_None;
108 }
109
110 CFG *getCFG(Decl const *D) {
111 return AnaCtxMgr.getContext(D)->getCFG();
112 }
113
114 template <typename T>
115 T *getAnalysis(Decl const *D) {
116 return AnaCtxMgr.getContext(D)->getAnalysis<T>();
117 }
118
120 return AnaCtxMgr.getContext(D)->getParentMap();
121 }
122
124 return AnaCtxMgr.getContext(D);
125 }
126
127 static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
128 if (SM.isInMainFile(SL))
129 return true;
130
131 // Support the "unified sources" compilation method (eg. WebKit) that
132 // involves producing non-header files that include other non-header files.
133 // We should be included directly from a UnifiedSource* file
134 // and we shouldn't be a header - which is a very safe defensive check.
135 SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
136 if (!IL.isValid() || !SM.isInMainFile(IL))
137 return false;
138 // Should rather be "file name starts with", but the current .getFilename
139 // includes the full path.
140 if (SM.getFilename(IL).contains("UnifiedSource")) {
141 // It might be great to reuse FrontendOptions::getInputKindForExtension()
142 // but for now it doesn't discriminate between code and header files.
143 return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
144 .Cases({"c", "m", "mm", "C", "cc", "cp"}, true)
145 .Cases({"cpp", "CPP", "c++", "cxx", "cppm"}, true)
146 .Default(false);
147 }
148
149 return false;
150 }
151
154 return isInCodeFile(SL, SM);
155 }
156};
157
158} // enAnaCtxMgrspace
159
160} // end clang namespace
161
162#endif
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
SourceManager & getSourceManager()
Definition ASTContext.h:913
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Stores options for the analyzer from the command line.
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition CFG.h:1294
CodeInjector is an interface which is responsible for injecting AST of function definitions that may ...
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include'd file otherwise it returns an invalid location.
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
const LangOptions & getLangOpts() const
ConstraintManagerCreator getConstraintManagerCreator()
ASTContext & getASTContext() override
Preprocessor & getPreprocessor() override
static bool isInCodeFile(SourceLocation SL, const SourceManager &SM)
bool isInCodeFile(SourceLocation SL)
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
AnalysisDeclContextManager & getAnalysisDeclContextManager()
SourceManager & getSourceManager() override
ArrayRef< std::unique_ptr< PathDiagnosticConsumer > > getPathDiagnosticConsumers() override
StoreManagerCreator getStoreManagerCreator()
ParentMap & getParentMap(Decl const *D)
CheckerManager * getCheckerManager() const
CFG * getCFG(Decl const *D)
AnalyzerOptions & getAnalyzerOptions() override
AnalysisManager(ASTContext &ctx, Preprocessor &PP, PathDiagnosticConsumers Consumers, StoreManagerCreator storemgr, ConstraintManagerCreator constraintmgr, CheckerManager *checkerMgr, AnalyzerOptions &Options, std::unique_ptr< CodeInjector > injector=nullptr)
std::unique_ptr< ConstraintManager >(* ConstraintManagerCreator)(ProgramStateManager &, ExprEngine *)
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
std::vector< std::unique_ptr< PathDiagnosticConsumer > > PathDiagnosticConsumers
Top level wrappers for InstallAPI frontend operations.
@ IPAK_None
Perform only intra-procedural analysis.
@ Default
Set to the current date and time.
const FunctionProtoType * T