1 //== AnalysisManager.h - Path sensitive analysis data manager ------*- C++ -*-//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the AnalysisManager class that manages the data and policy
11 // for path sensitive analysis.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_GR_ANALYSISMANAGER_H
16 #define LLVM_CLANG_GR_ANALYSISMANAGER_H
18 #include "clang/Analysis/AnalysisContext.h"
19 #include "clang/Frontend/AnalyzerOptions.h"
20 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
21 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
27 class TranslationUnit;
33 class AnalysisManager : public BugReporterData {
34 virtual void anchor();
35 AnalysisDeclContextManager AnaCtxMgr;
38 DiagnosticsEngine &Diags;
39 const LangOptions &LangOpts;
41 OwningPtr<PathDiagnosticConsumer> PD;
43 // Configurable components creators.
44 StoreManagerCreator CreateStoreMgr;
45 ConstraintManagerCreator CreateConstraintMgr;
47 CheckerManager *CheckerMgr;
49 /// \brief Provide function definitions in other translation units. This is
50 /// NULL if we don't have multiple translation units. AnalysisManager does
51 /// not own the Indexer.
54 enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
56 /// \brief The maximum number of exploded nodes the analyzer will generate.
59 /// \brief The maximum number of times the analyzer visits a block.
64 AnalysisPurgeMode PurgeDead;
66 /// \brief The flag regulates if we should eagerly assume evaluations of
67 /// conditionals, thus, bifurcating the path.
69 /// EagerlyAssume - A flag indicating how the engine should handle
70 /// expressions such as: 'x = (y != 0)'. When this flag is true then
71 /// the subexpression 'y != 0' will be eagerly assumed to be true or false,
72 /// thus evaluating it to the integers 0 or 1 respectively. The upside
73 /// is that this can increase analysis precision until we have a better way
74 /// to lazily evaluate such logic. The downside is that it eagerly
78 bool EagerlyTrimEGraph;
81 // \brief inter-procedural analysis mode.
82 AnalysisIPAMode IPAMode;
84 // Settings for inlining tuning.
85 /// \brief The inlining stack depth limit.
86 unsigned InlineMaxStackDepth;
87 /// \brief The max number of basic blocks in a function being inlined.
88 unsigned InlineMaxFunctionSize;
89 /// \brief The mode of function selection used during inlining.
90 AnalysisInliningMode InliningMode;
92 /// \brief Do not re-analyze paths leading to exhausted nodes with a different
93 /// strategy. We get better code coverage when retry is enabled.
94 bool NoRetryExhausted;
97 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
98 const LangOptions &lang, PathDiagnosticConsumer *pd,
99 StoreManagerCreator storemgr,
100 ConstraintManagerCreator constraintmgr,
101 CheckerManager *checkerMgr,
103 unsigned maxnodes, unsigned maxvisit,
104 bool vizdot, bool vizubi, AnalysisPurgeMode purge,
105 bool eager, bool trim,
106 bool useUnoptimizedCFG,
107 bool addImplicitDtors, bool addInitializers,
108 bool eagerlyTrimEGraph,
110 unsigned inlineMaxStack,
111 unsigned inlineMaxFunctionSize,
112 AnalysisInliningMode inliningMode,
115 /// Construct a clone of the given AnalysisManager with the given ASTContext
116 /// and DiagnosticsEngine.
117 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
118 AnalysisManager &ParentAM);
120 ~AnalysisManager() { FlushDiagnostics(); }
122 void ClearContexts() {
126 AnalysisDeclContextManager& getAnalysisDeclContextManager() {
130 StoreManagerCreator getStoreManagerCreator() {
131 return CreateStoreMgr;
134 ConstraintManagerCreator getConstraintManagerCreator() {
135 return CreateConstraintMgr;
138 CheckerManager *getCheckerManager() const { return CheckerMgr; }
140 idx::Indexer *getIndexer() const { return Idxer; }
142 virtual ASTContext &getASTContext() {
146 virtual SourceManager &getSourceManager() {
147 return getASTContext().getSourceManager();
150 virtual DiagnosticsEngine &getDiagnostic() {
154 const LangOptions &getLangOpts() const {
158 virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() {
162 void FlushDiagnostics() {
164 PD->FlushDiagnostics(0);
167 unsigned getMaxNodes() const { return MaxNodes; }
169 unsigned getMaxVisit() const { return MaxVisit; }
171 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
173 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
175 bool shouldVisualize() const {
176 return VisualizeEGDot || VisualizeEGUbi;
179 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; }
181 bool shouldTrimGraph() const { return TrimGraph; }
183 AnalysisPurgeMode getPurgeMode() const { return PurgeDead; }
185 bool shouldEagerlyAssume() const { return EagerlyAssume; }
187 bool shouldInlineCall() const { return (IPAMode == Inlining); }
189 bool hasIndexer() const { return Idxer != 0; }
191 AnalysisDeclContext *getAnalysisDeclContextInAnotherTU(const Decl *D);
193 CFG *getCFG(Decl const *D) {
194 return AnaCtxMgr.getContext(D)->getCFG();
197 template <typename T>
198 T *getAnalysis(Decl const *D) {
199 return AnaCtxMgr.getContext(D)->getAnalysis<T>();
202 ParentMap &getParentMap(Decl const *D) {
203 return AnaCtxMgr.getContext(D)->getParentMap();
206 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
207 return AnaCtxMgr.getContext(D);
210 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) {
211 return AnaCtxMgr.getContext(D, TU);
216 } // enAnaCtxMgrspace
218 } // end clang namespace