AnalysisManager.h revision 4e4d08403ca5cfd4d558fa2936215d3a4e5a528d
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 33typedef llvm::SmallPtrSet<const Decl*,24> SetOfDecls; 34 35class AnalysisManager : public BugReporterData { 36 virtual void anchor(); 37 AnalysisDeclContextManager AnaCtxMgr; 38 39 ASTContext &Ctx; 40 DiagnosticsEngine &Diags; 41 const LangOptions &LangOpts; 42 43 OwningPtr<PathDiagnosticConsumer> PD; 44 45 // Configurable components creators. 46 StoreManagerCreator CreateStoreMgr; 47 ConstraintManagerCreator CreateConstraintMgr; 48 49 CheckerManager *CheckerMgr; 50 51 /// \brief Provide function definitions in other translation units. This is 52 /// NULL if we don't have multiple translation units. AnalysisManager does 53 /// not own the Indexer. 54 idx::Indexer *Idxer; 55 56 enum AnalysisScope { ScopeTU, ScopeDecl } AScope; 57 58 /// \brief The maximum number of exploded nodes the analyzer will generate. 59 unsigned MaxNodes; 60 61 /// \brief The maximum number of times the analyzer visits a block. 62 unsigned MaxVisit; 63 64 bool VisualizeEGDot; 65 bool VisualizeEGUbi; 66 AnalysisPurgeMode PurgeDead; 67 68 /// \brief The flag regulates if we should eagerly assume evaluations of 69 /// conditionals, thus, bifurcating the path. 70 /// 71 /// EagerlyAssume - A flag indicating how the engine should handle 72 /// expressions such as: 'x = (y != 0)'. When this flag is true then 73 /// the subexpression 'y != 0' will be eagerly assumed to be true or false, 74 /// thus evaluating it to the integers 0 or 1 respectively. The upside 75 /// is that this can increase analysis precision until we have a better way 76 /// to lazily evaluate such logic. The downside is that it eagerly 77 /// bifurcates paths. 78 bool EagerlyAssume; 79 bool TrimGraph; 80 bool EagerlyTrimEGraph; 81 82public: 83 // \brief inter-procedural analysis mode. 84 AnalysisIPAMode IPAMode; 85 86 // Settings for inlining tuning. 87 /// \brief The inlining stack depth limit. 88 unsigned InlineMaxStackDepth; 89 /// \brief The max number of basic blocks in a function being inlined. 90 unsigned InlineMaxFunctionSize; 91 /// \brief The mode of function selection used during inlining. 92 AnalysisInliningMode InliningMode; 93 94public: 95 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 96 const LangOptions &lang, PathDiagnosticConsumer *pd, 97 StoreManagerCreator storemgr, 98 ConstraintManagerCreator constraintmgr, 99 CheckerManager *checkerMgr, 100 idx::Indexer *idxer, 101 unsigned maxnodes, unsigned maxvisit, 102 bool vizdot, bool vizubi, AnalysisPurgeMode purge, 103 bool eager, bool trim, 104 bool useUnoptimizedCFG, 105 bool addImplicitDtors, bool addInitializers, 106 bool eagerlyTrimEGraph, 107 AnalysisIPAMode ipa, 108 unsigned inlineMaxStack, 109 unsigned inlineMaxFunctionSize, 110 AnalysisInliningMode inliningMode); 111 112 /// Construct a clone of the given AnalysisManager with the given ASTContext 113 /// and DiagnosticsEngine. 114 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 115 AnalysisManager &ParentAM); 116 117 ~AnalysisManager() { FlushDiagnostics(); } 118 119 void ClearContexts() { 120 AnaCtxMgr.clear(); 121 } 122 123 AnalysisDeclContextManager& getAnalysisDeclContextManager() { 124 return AnaCtxMgr; 125 } 126 127 StoreManagerCreator getStoreManagerCreator() { 128 return CreateStoreMgr; 129 } 130 131 ConstraintManagerCreator getConstraintManagerCreator() { 132 return CreateConstraintMgr; 133 } 134 135 CheckerManager *getCheckerManager() const { return CheckerMgr; } 136 137 idx::Indexer *getIndexer() const { return Idxer; } 138 139 virtual ASTContext &getASTContext() { 140 return Ctx; 141 } 142 143 virtual SourceManager &getSourceManager() { 144 return getASTContext().getSourceManager(); 145 } 146 147 virtual DiagnosticsEngine &getDiagnostic() { 148 return Diags; 149 } 150 151 const LangOptions &getLangOpts() const { 152 return LangOpts; 153 } 154 155 virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() { 156 return PD.get(); 157 } 158 159 void FlushDiagnostics() { 160 if (PD.get()) 161 PD->FlushDiagnostics(0); 162 } 163 164 unsigned getMaxNodes() const { return MaxNodes; } 165 166 unsigned getMaxVisit() const { return MaxVisit; } 167 168 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; } 169 170 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; } 171 172 bool shouldVisualize() const { 173 return VisualizeEGDot || VisualizeEGUbi; 174 } 175 176 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; } 177 178 bool shouldTrimGraph() const { return TrimGraph; } 179 180 AnalysisPurgeMode getPurgeMode() const { return PurgeDead; } 181 182 bool shouldEagerlyAssume() const { return EagerlyAssume; } 183 184 bool shouldInlineCall() const { return (IPAMode == Inlining); } 185 186 bool hasIndexer() const { return Idxer != 0; } 187 188 AnalysisDeclContext *getAnalysisDeclContextInAnotherTU(const Decl *D); 189 190 CFG *getCFG(Decl const *D) { 191 return AnaCtxMgr.getContext(D)->getCFG(); 192 } 193 194 template <typename T> 195 T *getAnalysis(Decl const *D) { 196 return AnaCtxMgr.getContext(D)->getAnalysis<T>(); 197 } 198 199 ParentMap &getParentMap(Decl const *D) { 200 return AnaCtxMgr.getContext(D)->getParentMap(); 201 } 202 203 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) { 204 return AnaCtxMgr.getContext(D); 205 } 206 207 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) { 208 return AnaCtxMgr.getContext(D, TU); 209 } 210 211}; 212 213} // enAnaCtxMgrspace 214 215} // end clang namespace 216 217#endif 218