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#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/SmallVector.h"
25
26namespace clang {
27
28class CodeInjector;
29class Preprocessor;
30
31namespace ento {
32 class CheckerManager;
33
35 virtual void anchor();
37
38 ASTContext &Ctx;
39 Preprocessor &PP;
40 const LangOptions &LangOpts;
41 PathDiagnosticConsumers PathConsumers;
42
43 // Configurable components creators.
44 StoreManagerCreator CreateStoreMgr;
45 ConstraintManagerCreator CreateConstraintMgr;
46
47 CheckerManager *CheckerMgr;
48 SmallVector<StringRef> UnityBuildFileExtensions;
49
50public:
52
55 StoreManagerCreator storemgr,
56 ConstraintManagerCreator constraintmgr,
57 CheckerManager *checkerMgr, AnalyzerOptions &Options,
58 std::unique_ptr<CodeInjector> injector = nullptr);
59
60 ~AnalysisManager() override;
61
63 AnaCtxMgr.clear();
64 }
65
69
70 Preprocessor &getPreprocessor() override { return PP; }
71
73 return CreateStoreMgr;
74 }
75
77 return options;
78 }
79
81 return CreateConstraintMgr;
82 }
83
84 CheckerManager *getCheckerManager() const { return CheckerMgr; }
85
87 return Ctx;
88 }
89
93
94 const LangOptions &getLangOpts() const {
95 return LangOpts;
96 }
97
100 return PathConsumers;
101 }
102
103 void FlushDiagnostics();
104
105 bool shouldVisualize() const {
106 return options.visualizeExplodedGraphWithGraphViz;
107 }
108
109 bool shouldInlineCall() const {
110 return options.getIPAMode() != IPAK_None;
111 }
112
113 CFG *getCFG(Decl const *D) {
114 return AnaCtxMgr.getContext(D)->getCFG();
115 }
116
117 template <typename T>
118 T *getAnalysis(Decl const *D) {
119 return AnaCtxMgr.getContext(D)->getAnalysis<T>();
120 }
121
123 return AnaCtxMgr.getContext(D)->getParentMap();
124 }
125
127 return AnaCtxMgr.getContext(D);
128 }
129
131 const SourceManager &SM = Ctx.getSourceManager();
132 if (SM.isInMainFile(SL))
133 return true;
134
135 // Treat configured included source files #include "foo.cpp" same as the
136 // main file.
137 StringRef FileName = SM.getFilename(SL);
138 for (StringRef Extension : UnityBuildFileExtensions)
139 if (FileName.ends_with(Extension))
140 return true;
141
142 // Support the "unified sources" compilation method (eg. WebKit) that
143 // involves producing non-header files that include other non-header files.
144 // We should be included directly from a UnifiedSource* file
145 // and we shouldn't be a header - which is a very safe defensive check.
146 SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
147 if (!IL.isValid() || !SM.isInMainFile(IL))
148 return false;
149 // Should rather be "file name starts with", but the current .getFilename
150 // includes the full path.
151 if (SM.getFilename(IL).contains("UnifiedSource")) {
152 // It might be great to reuse FrontendOptions::getInputKindForExtension()
153 // but for now it doesn't discriminate between code and header files.
154 return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
155 .Cases({"c", "m", "mm", "C", "cc", "cp"}, true)
156 .Cases({"cpp", "CPP", "c++", "cxx", "cppm"}, true)
157 .Default(false);
158 }
159
160 return false;
161 }
162};
163
164} // enAnaCtxMgrspace
165
166} // end clang namespace
167
168#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:916
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()
bool isInCodeFile(SourceLocation SL) const
ASTContext & getASTContext() override
Preprocessor & getPreprocessor() override
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