clang  7.0.0svn
AnalysisManager.h
Go to the documentation of this file.
1 //== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the AnalysisManager class that manages the data and policy
11 // for path sensitive analysis.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
16 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_ANALYSISMANAGER_H
17 
23 
24 namespace clang {
25 
26 class CodeInjector;
27 
28 namespace ento {
29  class CheckerManager;
30 
32  virtual void anchor();
34 
35  ASTContext &Ctx;
36  DiagnosticsEngine &Diags;
37  const LangOptions &LangOpts;
38  PathDiagnosticConsumers PathConsumers;
39 
40  // Configurable components creators.
41  StoreManagerCreator CreateStoreMgr;
42  ConstraintManagerCreator CreateConstraintMgr;
43 
44  CheckerManager *CheckerMgr;
45 
46 public:
48 
50  const LangOptions &lang,
51  const PathDiagnosticConsumers &Consumers,
52  StoreManagerCreator storemgr,
53  ConstraintManagerCreator constraintmgr,
54  CheckerManager *checkerMgr,
55  AnalyzerOptions &Options,
56  CodeInjector* injector = nullptr);
57 
58  ~AnalysisManager() override;
59 
60  void ClearContexts() {
61  AnaCtxMgr.clear();
62  }
63 
65  return AnaCtxMgr;
66  }
67 
69  return CreateStoreMgr;
70  }
71 
73  return options;
74  }
75 
77  return CreateConstraintMgr;
78  }
79 
80  CheckerManager *getCheckerManager() const { return CheckerMgr; }
81 
82  ASTContext &getASTContext() override {
83  return Ctx;
84  }
85 
88  }
89 
91  return Diags;
92  }
93 
94  const LangOptions &getLangOpts() const {
95  return LangOpts;
96  }
97 
99  return PathConsumers;
100  }
101 
102  void FlushDiagnostics();
103 
104  bool shouldVisualize() const {
105  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 
130  static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
131  if (SM.isInMainFile(SL))
132  return true;
133 
134  // Support the "unified sources" compilation method (eg. WebKit) that
135  // involves producing non-header files that include other non-header files.
136  // We should be included directly from a UnifiedSource* file
137  // and we shouldn't be a header - which is a very safe defensive check.
138  SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
139  if (!IL.isValid() || !SM.isInMainFile(IL))
140  return false;
141  // Should rather be "file name starts with", but the current .getFilename
142  // includes the full path.
143  if (SM.getFilename(IL).contains("UnifiedSource")) {
144  // It might be great to reuse FrontendOptions::getInputKindForExtension()
145  // but for now it doesn't discriminate between code and header files.
146  return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
147  .Cases("c", "m", "mm", "C", "cc", "cp", true)
148  .Cases("cpp", "CPP", "c++", "cxx", "cppm", true)
149  .Default(false);
150  }
151 
152  return false;
153  }
154 
157  return isInCodeFile(SL, SM);
158  }
159 };
160 
161 } // enAnaCtxMgrspace
162 
163 } // end clang namespace
164 
165 #endif
AnalysisDeclContextManager & getAnalysisDeclContextManager()
CheckerManager * getCheckerManager() const
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
unsigned visualizeExplodedGraphWithGraphViz
Perform only intra-procedural analysis.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:150
AnalysisDeclContext contains the context data for the function or method under analysis.
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
Definition: ProgramState.h:44
static bool isInCodeFile(SourceLocation SL, const SourceManager &SM)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
T * getAnalysis()
Return the specified analysis object, lazily running the analysis if necessary.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
ArrayRef< PathDiagnosticConsumer * > getPathDiagnosticConsumers() override
ASTContext & getASTContext() override
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
StoreManagerCreator getStoreManagerCreator()
std::unique_ptr< ConstraintManager >(* ConstraintManagerCreator)(ProgramStateManager &, SubEngine *)
Definition: ProgramState.h:42
AnalysisDeclContext * getContext(const Decl *D)
IPAKind getIPAMode()
Returns the inter-procedural analysis mode.
CFG - Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
Definition: CFG.h:1002
const FunctionProtoType * T
AnalyzerOptions & getAnalyzerOptions() override
ConstraintManagerCreator getConstraintManagerCreator()
CFG * getCFG(Decl const *D)
const SourceManager & SM
Definition: Format.cpp:1468
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
Encodes a location in the source.
std::vector< PathDiagnosticConsumer * > PathDiagnosticConsumers
unsigned visualizeExplodedGraphWithUbiGraph
ParentMap & getParentMap(Decl const *D)
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
bool isInCodeFile(SourceLocation SL)
SourceManager & getSourceManager() override
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
CodeInjector is an interface which is responsible for injecting AST of function definitions that may ...
Definition: CodeInjector.h:36
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include&#39;d file otherwise it returns an invalid location...
const LangOptions & getLangOpts() const
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, const LangOptions &lang, const PathDiagnosticConsumers &Consumers, StoreManagerCreator storemgr, ConstraintManagerCreator constraintmgr, CheckerManager *checkerMgr, AnalyzerOptions &Options, CodeInjector *injector=nullptr)
SourceManager & getSourceManager()
Definition: ASTContext.h:644
DiagnosticsEngine & getDiagnostic() override
void clear()
Discard all previously created AnalysisDeclContexts.
T * getAnalysis(Decl const *D)
This class handles loading and caching of source files into memory.