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"
22 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
29 class AnalysisManager : public BugReporterData {
30 virtual void anchor();
31 AnalysisDeclContextManager AnaCtxMgr;
34 DiagnosticsEngine &Diags;
35 const LangOptions &LangOpts;
36 PathDiagnosticConsumers PathConsumers;
38 // Configurable components creators.
39 StoreManagerCreator CreateStoreMgr;
40 ConstraintManagerCreator CreateConstraintMgr;
42 CheckerManager *CheckerMgr;
44 /// \brief The maximum number of exploded nodes the analyzer will generate.
47 /// \brief The maximum number of times the analyzer visits a block.
52 AnalysisPurgeMode PurgeDead;
54 /// \brief The flag regulates if we should eagerly assume evaluations of
55 /// conditionals, thus, bifurcating the path.
57 /// EagerlyAssume - A flag indicating how the engine should handle
58 /// expressions such as: 'x = (y != 0)'. When this flag is true then
59 /// the subexpression 'y != 0' will be eagerly assumed to be true or false,
60 /// thus evaluating it to the integers 0 or 1 respectively. The upside
61 /// is that this can increase analysis precision until we have a better way
62 /// to lazily evaluate such logic. The downside is that it eagerly
66 bool EagerlyTrimEGraph;
69 // \brief inter-procedural analysis mode.
70 AnalysisIPAMode IPAMode;
72 // Settings for inlining tuning.
73 /// \brief The inlining stack depth limit.
74 unsigned InlineMaxStackDepth;
75 /// \brief The max number of basic blocks in a function being inlined.
76 unsigned InlineMaxFunctionSize;
77 /// \brief The mode of function selection used during inlining.
78 AnalysisInliningMode InliningMode;
80 /// \brief Do not re-analyze paths leading to exhausted nodes with a different
81 /// strategy. We get better code coverage when retry is enabled.
82 bool NoRetryExhausted;
85 AnalysisManager(ASTContext &ctx,DiagnosticsEngine &diags,
86 const LangOptions &lang,
87 const PathDiagnosticConsumers &Consumers,
88 StoreManagerCreator storemgr,
89 ConstraintManagerCreator constraintmgr,
90 CheckerManager *checkerMgr,
91 unsigned maxnodes, unsigned maxvisit,
92 bool vizdot, bool vizubi, AnalysisPurgeMode purge,
93 bool eager, bool trim,
94 bool useUnoptimizedCFG,
95 bool addImplicitDtors,
96 bool eagerlyTrimEGraph,
98 unsigned inlineMaxStack,
99 unsigned inlineMaxFunctionSize,
100 AnalysisInliningMode inliningMode,
105 void ClearContexts() {
109 AnalysisDeclContextManager& getAnalysisDeclContextManager() {
113 StoreManagerCreator getStoreManagerCreator() {
114 return CreateStoreMgr;
117 ConstraintManagerCreator getConstraintManagerCreator() {
118 return CreateConstraintMgr;
121 CheckerManager *getCheckerManager() const { return CheckerMgr; }
123 virtual ASTContext &getASTContext() {
127 virtual SourceManager &getSourceManager() {
128 return getASTContext().getSourceManager();
131 virtual DiagnosticsEngine &getDiagnostic() {
135 const LangOptions &getLangOpts() const {
139 ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() {
140 return PathConsumers;
143 void FlushDiagnostics();
145 unsigned getMaxNodes() const { return MaxNodes; }
147 unsigned getMaxVisit() const { return MaxVisit; }
149 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
151 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
153 bool shouldVisualize() const {
154 return VisualizeEGDot || VisualizeEGUbi;
157 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; }
159 bool shouldTrimGraph() const { return TrimGraph; }
161 AnalysisPurgeMode getPurgeMode() const { return PurgeDead; }
163 bool shouldEagerlyAssume() const { return EagerlyAssume; }
165 bool shouldInlineCall() const { return (IPAMode != None); }
167 CFG *getCFG(Decl const *D) {
168 return AnaCtxMgr.getContext(D)->getCFG();
171 template <typename T>
172 T *getAnalysis(Decl const *D) {
173 return AnaCtxMgr.getContext(D)->getAnalysis<T>();
176 ParentMap &getParentMap(Decl const *D) {
177 return AnaCtxMgr.getContext(D)->getParentMap();
180 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
181 return AnaCtxMgr.getContext(D);
186 } // enAnaCtxMgrspace
188 } // end clang namespace