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"
28 class AnalysisManager : public BugReporterData {
29 virtual void anchor();
30 AnalysisDeclContextManager AnaCtxMgr;
33 DiagnosticsEngine &Diags;
34 const LangOptions &LangOpts;
36 OwningPtr<PathDiagnosticConsumer> PD;
38 // Configurable components creators.
39 StoreManagerCreator CreateStoreMgr;
40 ConstraintManagerCreator CreateConstraintMgr;
42 CheckerManager *CheckerMgr;
44 enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
46 /// \brief The maximum number of exploded nodes the analyzer will generate.
49 /// \brief The maximum number of times the analyzer visits a block.
54 AnalysisPurgeMode PurgeDead;
56 /// \brief The flag regulates if we should eagerly assume evaluations of
57 /// conditionals, thus, bifurcating the path.
59 /// EagerlyAssume - A flag indicating how the engine should handle
60 /// expressions such as: 'x = (y != 0)'. When this flag is true then
61 /// the subexpression 'y != 0' will be eagerly assumed to be true or false,
62 /// thus evaluating it to the integers 0 or 1 respectively. The upside
63 /// is that this can increase analysis precision until we have a better way
64 /// to lazily evaluate such logic. The downside is that it eagerly
68 bool EagerlyTrimEGraph;
71 // \brief inter-procedural analysis mode.
72 AnalysisIPAMode IPAMode;
74 // Settings for inlining tuning.
75 /// \brief The inlining stack depth limit.
76 unsigned InlineMaxStackDepth;
77 /// \brief The max number of basic blocks in a function being inlined.
78 unsigned InlineMaxFunctionSize;
79 /// \brief The mode of function selection used during inlining.
80 AnalysisInliningMode InliningMode;
82 /// \brief Do not re-analyze paths leading to exhausted nodes with a different
83 /// strategy. We get better code coverage when retry is enabled.
84 bool NoRetryExhausted;
87 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
88 const LangOptions &lang, PathDiagnosticConsumer *pd,
89 StoreManagerCreator storemgr,
90 ConstraintManagerCreator constraintmgr,
91 CheckerManager *checkerMgr,
92 unsigned maxnodes, unsigned maxvisit,
93 bool vizdot, bool vizubi, AnalysisPurgeMode purge,
94 bool eager, bool trim,
95 bool useUnoptimizedCFG,
96 bool addImplicitDtors, bool addInitializers,
97 bool eagerlyTrimEGraph,
99 unsigned inlineMaxStack,
100 unsigned inlineMaxFunctionSize,
101 AnalysisInliningMode inliningMode,
104 /// Construct a clone of the given AnalysisManager with the given ASTContext
105 /// and DiagnosticsEngine.
106 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
107 AnalysisManager &ParentAM);
109 ~AnalysisManager() { FlushDiagnostics(); }
111 void ClearContexts() {
115 AnalysisDeclContextManager& getAnalysisDeclContextManager() {
119 StoreManagerCreator getStoreManagerCreator() {
120 return CreateStoreMgr;
123 ConstraintManagerCreator getConstraintManagerCreator() {
124 return CreateConstraintMgr;
127 CheckerManager *getCheckerManager() const { return CheckerMgr; }
129 virtual ASTContext &getASTContext() {
133 virtual SourceManager &getSourceManager() {
134 return getASTContext().getSourceManager();
137 virtual DiagnosticsEngine &getDiagnostic() {
141 const LangOptions &getLangOpts() const {
145 virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() {
149 void FlushDiagnostics() {
151 PD->FlushDiagnostics(0);
154 unsigned getMaxNodes() const { return MaxNodes; }
156 unsigned getMaxVisit() const { return MaxVisit; }
158 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
160 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
162 bool shouldVisualize() const {
163 return VisualizeEGDot || VisualizeEGUbi;
166 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; }
168 bool shouldTrimGraph() const { return TrimGraph; }
170 AnalysisPurgeMode getPurgeMode() const { return PurgeDead; }
172 bool shouldEagerlyAssume() const { return EagerlyAssume; }
174 bool shouldInlineCall() const { return (IPAMode == Inlining); }
176 CFG *getCFG(Decl const *D) {
177 return AnaCtxMgr.getContext(D)->getCFG();
180 template <typename T>
181 T *getAnalysis(Decl const *D) {
182 return AnaCtxMgr.getContext(D)->getAnalysis<T>();
185 ParentMap &getParentMap(Decl const *D) {
186 return AnaCtxMgr.getContext(D)->getParentMap();
189 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
190 return AnaCtxMgr.getContext(D);
193 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) {
194 return AnaCtxMgr.getContext(D, TU);
199 } // enAnaCtxMgrspace
201 } // end clang namespace