clang  8.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 PathDiagnosticConsumers &Consumers,
51  StoreManagerCreator storemgr,
52  ConstraintManagerCreator constraintmgr,
53  CheckerManager *checkerMgr, AnalyzerOptions &Options,
54  CodeInjector *injector = nullptr);
55 
56  ~AnalysisManager() override;
57 
58  void ClearContexts() {
59  AnaCtxMgr.clear();
60  }
61 
63  return AnaCtxMgr;
64  }
65 
67  return CreateStoreMgr;
68  }
69 
71  return options;
72  }
73 
75  return CreateConstraintMgr;
76  }
77 
78  CheckerManager *getCheckerManager() const { return CheckerMgr; }
79 
80  ASTContext &getASTContext() override {
81  return Ctx;
82  }
83 
86  }
87 
89  return Diags;
90  }
91 
92  const LangOptions &getLangOpts() const {
93  return LangOpts;
94  }
95 
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
AnalysisDeclContextManager & getAnalysisDeclContextManager()
CheckerManager * getCheckerManager() const
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
unsigned visualizeExplodedGraphWithGraphViz
Perform only intra-procedural analysis.
AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, const PathDiagnosticConsumers &Consumers, StoreManagerCreator storemgr, ConstraintManagerCreator constraintmgr, CheckerManager *checkerMgr, AnalyzerOptions &Options, CodeInjector *injector=nullptr)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
AnalysisDeclContext contains the context data for the function or method under analysis.
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
Definition: ProgramState.h:45
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:43
AnalysisDeclContext * getContext(const Decl *D)
IPAKind getIPAMode()
Returns the inter-procedural analysis mode.
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
Definition: CFG.h:1003
AnalyzerOptions & getAnalyzerOptions() override
ConstraintManagerCreator getConstraintManagerCreator()
CFG * getCFG(Decl const *D)
const SourceManager & SM
Definition: Format.cpp:1490
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
Encodes a location in the source.
std::vector< PathDiagnosticConsumer * > PathDiagnosticConsumers
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.
SourceManager & getSourceManager()
Definition: ASTContext.h:671
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.