AnalysisManager.h revision e62f048960645b79363408fdead53fec2a063c52
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 23namespace clang { 24 25namespace idx { 26 class Indexer; 27 class TranslationUnit; 28} 29 30namespace ento { 31 class CheckerManager; 32 33class AnalysisManager : public BugReporterData { 34 virtual void anchor(); 35 AnalysisDeclContextManager AnaCtxMgr; 36 37 ASTContext &Ctx; 38 DiagnosticsEngine &Diags; 39 const LangOptions &LangOpts; 40 41 OwningPtr<PathDiagnosticConsumer> PD; 42 43 // Configurable components creators. 44 StoreManagerCreator CreateStoreMgr; 45 ConstraintManagerCreator CreateConstraintMgr; 46 47 CheckerManager *CheckerMgr; 48 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. 52 idx::Indexer *Idxer; 53 54 enum AnalysisScope { ScopeTU, ScopeDecl } AScope; 55 56 /// \brief The maximum number of exploded nodes the analyzer will generate. 57 unsigned MaxNodes; 58 59 /// \brief The maximum number of times the analyzer visits a block. 60 unsigned MaxVisit; 61 62 bool VisualizeEGDot; 63 bool VisualizeEGUbi; 64 AnalysisPurgeMode PurgeDead; 65 66 /// \brief The flag regulates if we should eagerly assume evaluations of 67 /// conditionals, thus, bifurcating the path. 68 /// 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 75 /// bifurcates paths. 76 bool EagerlyAssume; 77 bool TrimGraph; 78 bool EagerlyTrimEGraph; 79 80public: 81 // \brief inter-procedural analysis mode. 82 AnalysisIPAMode IPAMode; 83 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; 91 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; 95 96public: 97 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 98 const LangOptions &lang, PathDiagnosticConsumer *pd, 99 StoreManagerCreator storemgr, 100 ConstraintManagerCreator constraintmgr, 101 CheckerManager *checkerMgr, 102 idx::Indexer *idxer, 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, 109 AnalysisIPAMode ipa, 110 unsigned inlineMaxStack, 111 unsigned inlineMaxFunctionSize, 112 AnalysisInliningMode inliningMode, 113 bool NoRetry); 114 115 /// Construct a clone of the given AnalysisManager with the given ASTContext 116 /// and DiagnosticsEngine. 117 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 118 AnalysisManager &ParentAM); 119 120 ~AnalysisManager() { FlushDiagnostics(); } 121 122 void ClearContexts() { 123 AnaCtxMgr.clear(); 124 } 125 126 AnalysisDeclContextManager& getAnalysisDeclContextManager() { 127 return AnaCtxMgr; 128 } 129 130 StoreManagerCreator getStoreManagerCreator() { 131 return CreateStoreMgr; 132 } 133 134 ConstraintManagerCreator getConstraintManagerCreator() { 135 return CreateConstraintMgr; 136 } 137 138 CheckerManager *getCheckerManager() const { return CheckerMgr; } 139 140 idx::Indexer *getIndexer() const { return Idxer; } 141 142 virtual ASTContext &getASTContext() { 143 return Ctx; 144 } 145 146 virtual SourceManager &getSourceManager() { 147 return getASTContext().getSourceManager(); 148 } 149 150 virtual DiagnosticsEngine &getDiagnostic() { 151 return Diags; 152 } 153 154 const LangOptions &getLangOpts() const { 155 return LangOpts; 156 } 157 158 virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() { 159 return PD.get(); 160 } 161 162 void FlushDiagnostics() { 163 if (PD.get()) 164 PD->FlushDiagnostics(0); 165 } 166 167 unsigned getMaxNodes() const { return MaxNodes; } 168 169 unsigned getMaxVisit() const { return MaxVisit; } 170 171 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; } 172 173 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; } 174 175 bool shouldVisualize() const { 176 return VisualizeEGDot || VisualizeEGUbi; 177 } 178 179 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; } 180 181 bool shouldTrimGraph() const { return TrimGraph; } 182 183 AnalysisPurgeMode getPurgeMode() const { return PurgeDead; } 184 185 bool shouldEagerlyAssume() const { return EagerlyAssume; } 186 187 bool shouldInlineCall() const { return (IPAMode == Inlining); } 188 189 bool hasIndexer() const { return Idxer != 0; } 190 191 AnalysisDeclContext *getAnalysisDeclContextInAnotherTU(const Decl *D); 192 193 CFG *getCFG(Decl const *D) { 194 return AnaCtxMgr.getContext(D)->getCFG(); 195 } 196 197 template <typename T> 198 T *getAnalysis(Decl const *D) { 199 return AnaCtxMgr.getContext(D)->getAnalysis<T>(); 200 } 201 202 ParentMap &getParentMap(Decl const *D) { 203 return AnaCtxMgr.getContext(D)->getParentMap(); 204 } 205 206 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) { 207 return AnaCtxMgr.getContext(D); 208 } 209 210 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) { 211 return AnaCtxMgr.getContext(D, TU); 212 } 213 214}; 215 216} // enAnaCtxMgrspace 217 218} // end clang namespace 219 220#endif 221