clang  10.0.0svn
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 
22 
23 namespace clang {
24 
25 class CodeInjector;
26 
27 namespace ento {
28  class CheckerManager;
29 
31  virtual void anchor();
33 
34  ASTContext &Ctx;
35  const LangOptions &LangOpts;
36  PathDiagnosticConsumers PathConsumers;
37 
38  // Configurable components creators.
39  StoreManagerCreator CreateStoreMgr;
40  ConstraintManagerCreator CreateConstraintMgr;
41 
42  CheckerManager *CheckerMgr;
43 
44 public:
46 
48  const PathDiagnosticConsumers &Consumers,
49  StoreManagerCreator storemgr,
50  ConstraintManagerCreator constraintmgr,
51  CheckerManager *checkerMgr, AnalyzerOptions &Options,
52  CodeInjector *injector = nullptr);
53 
54  ~AnalysisManager() override;
55 
56  void ClearContexts() {
57  AnaCtxMgr.clear();
58  }
59 
61  return AnaCtxMgr;
62  }
63 
65  return CreateStoreMgr;
66  }
67 
69  return options;
70  }
71 
73  return CreateConstraintMgr;
74  }
75 
76  CheckerManager *getCheckerManager() const { return CheckerMgr; }
77 
78  ASTContext &getASTContext() override {
79  return Ctx;
80  }
81 
84  }
85 
86  const LangOptions &getLangOpts() const {
87  return LangOpts;
88  }
89 
91  return PathConsumers;
92  }
93 
94  void FlushDiagnostics();
95 
96  bool shouldVisualize() const {
98  }
99 
100  bool shouldInlineCall() const {
101  return options.getIPAMode() != IPAK_None;
102  }
103 
104  CFG *getCFG(Decl const *D) {
105  return AnaCtxMgr.getContext(D)->getCFG();
106  }
107 
108  template <typename T>
109  T *getAnalysis(Decl const *D) {
110  return AnaCtxMgr.getContext(D)->getAnalysis<T>();
111  }
112 
114  return AnaCtxMgr.getContext(D)->getParentMap();
115  }
116 
118  return AnaCtxMgr.getContext(D);
119  }
120 
121  static bool isInCodeFile(SourceLocation SL, const SourceManager &SM) {
122  if (SM.isInMainFile(SL))
123  return true;
124 
125  // Support the "unified sources" compilation method (eg. WebKit) that
126  // involves producing non-header files that include other non-header files.
127  // We should be included directly from a UnifiedSource* file
128  // and we shouldn't be a header - which is a very safe defensive check.
129  SourceLocation IL = SM.getIncludeLoc(SM.getFileID(SL));
130  if (!IL.isValid() || !SM.isInMainFile(IL))
131  return false;
132  // Should rather be "file name starts with", but the current .getFilename
133  // includes the full path.
134  if (SM.getFilename(IL).contains("UnifiedSource")) {
135  // It might be great to reuse FrontendOptions::getInputKindForExtension()
136  // but for now it doesn't discriminate between code and header files.
137  return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
138  .Cases("c", "m", "mm", "C", "cc", "cp", true)
139  .Cases("cpp", "CPP", "c++", "cxx", "cppm", true)
140  .Default(false);
141  }
142 
143  return false;
144  }
145 
148  return isInCodeFile(SL, SM);
149  }
150 };
151 
152 } // enAnaCtxMgrspace
153 
154 } // end clang namespace
155 
156 #endif
AnalysisDeclContextManager & getAnalysisDeclContextManager()
AnalysisManager(ASTContext &ctx, const PathDiagnosticConsumers &Consumers, StoreManagerCreator storemgr, ConstraintManagerCreator constraintmgr, CheckerManager *checkerMgr, AnalyzerOptions &Options, CodeInjector *injector=nullptr)
CheckerManager * getCheckerManager() const
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
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:160
AnalysisDeclContext contains the context data for the function or method under analysis.
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
Definition: ProgramState.h:43
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:49
T * getAnalysis()
Return the specified analysis object, lazily running the analysis if necessary.
ArrayRef< PathDiagnosticConsumer * > getPathDiagnosticConsumers() override
ASTContext & getASTContext() override
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
StoreManagerCreator getStoreManagerCreator()
std::unique_ptr< ConstraintManager >(* ConstraintManagerCreator)(ProgramStateManager &, SubEngine *)
Definition: ProgramState.h:41
AnalysisDeclContext * getContext(const Decl *D)
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
Definition: CFG.h:1225
AnalyzerOptions & getAnalyzerOptions() override
ConstraintManagerCreator getConstraintManagerCreator()
CFG * getCFG(Decl const *D)
const SourceManager & SM
Definition: Format.cpp:1616
IPAKind getIPAMode() const
Returns the inter-procedural analysis mode.
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:35
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.
Stores options for the analyzer from the command line.
SourceManager & getSourceManager()
Definition: ASTContext.h:675
void clear()
Discard all previously created AnalysisDeclContexts.
T * getAnalysis(Decl const *D)
This class handles loading and caching of source files into memory.