AnalysisManager.h revision 7b73e0832b20af1f43601a3d19e76d02d9f4dce5
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_GR_ANALYSISMANAGER_H 16#define LLVM_CLANG_GR_ANALYSISMANAGER_H 17 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" 23 24namespace clang { 25 26namespace ento { 27 class CheckerManager; 28 29class AnalysisManager : public BugReporterData { 30 virtual void anchor(); 31 AnalysisDeclContextManager AnaCtxMgr; 32 33 ASTContext &Ctx; 34 DiagnosticsEngine &Diags; 35 const LangOptions &LangOpts; 36 PathDiagnosticConsumers PathConsumers; 37 38 // Configurable components creators. 39 StoreManagerCreator CreateStoreMgr; 40 ConstraintManagerCreator CreateConstraintMgr; 41 42 CheckerManager *CheckerMgr; 43 44 /// \brief The maximum number of exploded nodes the analyzer will generate. 45 unsigned MaxNodes; 46 47 /// \brief The maximum number of times the analyzer visits a block. 48 unsigned MaxVisit; 49 50 bool VisualizeEGDot; 51 bool VisualizeEGUbi; 52 AnalysisPurgeMode PurgeDead; 53 54 /// \brief The flag regulates if we should eagerly assume evaluations of 55 /// conditionals, thus, bifurcating the path. 56 /// 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 63 /// bifurcates paths. 64 bool EagerlyAssume; 65 bool TrimGraph; 66 bool EagerlyTrimEGraph; 67 68public: 69 // \brief inter-procedural analysis mode. 70 AnalysisIPAMode IPAMode; 71 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; 79 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; 83 84 typedef llvm::StringMap<std::string> ConfigTable; 85 86 /// \brief A key-value table of use-specified configuration values. 87 const ConfigTable &Config; 88 89public: 90 AnalysisManager(ASTContext &ctx,DiagnosticsEngine &diags, 91 const LangOptions &lang, 92 const PathDiagnosticConsumers &Consumers, 93 StoreManagerCreator storemgr, 94 ConstraintManagerCreator constraintmgr, 95 CheckerManager *checkerMgr, 96 const ConfigTable &Config, 97 unsigned maxnodes, unsigned maxvisit, 98 bool vizdot, bool vizubi, AnalysisPurgeMode purge, 99 bool eager, bool trim, 100 bool useUnoptimizedCFG, 101 bool addImplicitDtors, 102 bool eagerlyTrimEGraph, 103 AnalysisIPAMode ipa, 104 unsigned inlineMaxStack, 105 unsigned inlineMaxFunctionSize, 106 AnalysisInliningMode inliningMode, 107 bool NoRetry); 108 109 ~AnalysisManager(); 110 111 void ClearContexts() { 112 AnaCtxMgr.clear(); 113 } 114 115 AnalysisDeclContextManager& getAnalysisDeclContextManager() { 116 return AnaCtxMgr; 117 } 118 119 StoreManagerCreator getStoreManagerCreator() { 120 return CreateStoreMgr; 121 } 122 123 ConstraintManagerCreator getConstraintManagerCreator() { 124 return CreateConstraintMgr; 125 } 126 127 CheckerManager *getCheckerManager() const { return CheckerMgr; } 128 129 virtual ASTContext &getASTContext() { 130 return Ctx; 131 } 132 133 virtual SourceManager &getSourceManager() { 134 return getASTContext().getSourceManager(); 135 } 136 137 virtual DiagnosticsEngine &getDiagnostic() { 138 return Diags; 139 } 140 141 const LangOptions &getLangOpts() const { 142 return LangOpts; 143 } 144 145 ArrayRef<PathDiagnosticConsumer*> getPathDiagnosticConsumers() { 146 return PathConsumers; 147 } 148 149 void FlushDiagnostics(); 150 151 unsigned getMaxNodes() const { return MaxNodes; } 152 153 unsigned getMaxVisit() const { return MaxVisit; } 154 155 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; } 156 157 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; } 158 159 bool shouldVisualize() const { 160 return VisualizeEGDot || VisualizeEGUbi; 161 } 162 163 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; } 164 165 bool shouldTrimGraph() const { return TrimGraph; } 166 167 AnalysisPurgeMode getPurgeMode() const { return PurgeDead; } 168 169 bool shouldEagerlyAssume() const { return EagerlyAssume; } 170 171 bool shouldInlineCall() const { return (IPAMode != None); } 172 173 CFG *getCFG(Decl const *D) { 174 return AnaCtxMgr.getContext(D)->getCFG(); 175 } 176 177 template <typename T> 178 T *getAnalysis(Decl const *D) { 179 return AnaCtxMgr.getContext(D)->getAnalysis<T>(); 180 } 181 182 ParentMap &getParentMap(Decl const *D) { 183 return AnaCtxMgr.getContext(D)->getParentMap(); 184 } 185 186 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) { 187 return AnaCtxMgr.getContext(D); 188 } 189 190}; 191 192} // enAnaCtxMgrspace 193 194} // end clang namespace 195 196#endif 197