AnalysisManager.h revision 5903a373db3d27794c90b25687e0dd6adb0e497d
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 94 /// \brief Re-analyze paths leading to exhausted nodes with a different 95 /// strategy for better code coverage. 96 bool RetryExhausted; 97 98public: 99 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 100 const LangOptions &lang, PathDiagnosticConsumer *pd, 101 StoreManagerCreator storemgr, 102 ConstraintManagerCreator constraintmgr, 103 CheckerManager *checkerMgr, 104 idx::Indexer *idxer, 105 unsigned maxnodes, unsigned maxvisit, 106 bool vizdot, bool vizubi, AnalysisPurgeMode purge, 107 bool eager, bool trim, 108 bool useUnoptimizedCFG, 109 bool addImplicitDtors, bool addInitializers, 110 bool eagerlyTrimEGraph, 111 AnalysisIPAMode ipa, 112 unsigned inlineMaxStack, 113 unsigned inlineMaxFunctionSize, 114 AnalysisInliningMode inliningMode, 115 bool retry); 116 117 /// Construct a clone of the given AnalysisManager with the given ASTContext 118 /// and DiagnosticsEngine. 119 AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags, 120 AnalysisManager &ParentAM); 121 122 ~AnalysisManager() { FlushDiagnostics(); } 123 124 void ClearContexts() { 125 AnaCtxMgr.clear(); 126 } 127 128 AnalysisDeclContextManager& getAnalysisDeclContextManager() { 129 return AnaCtxMgr; 130 } 131 132 StoreManagerCreator getStoreManagerCreator() { 133 return CreateStoreMgr; 134 } 135 136 ConstraintManagerCreator getConstraintManagerCreator() { 137 return CreateConstraintMgr; 138 } 139 140 CheckerManager *getCheckerManager() const { return CheckerMgr; } 141 142 idx::Indexer *getIndexer() const { return Idxer; } 143 144 virtual ASTContext &getASTContext() { 145 return Ctx; 146 } 147 148 virtual SourceManager &getSourceManager() { 149 return getASTContext().getSourceManager(); 150 } 151 152 virtual DiagnosticsEngine &getDiagnostic() { 153 return Diags; 154 } 155 156 const LangOptions &getLangOpts() const { 157 return LangOpts; 158 } 159 160 virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() { 161 return PD.get(); 162 } 163 164 void FlushDiagnostics() { 165 if (PD.get()) 166 PD->FlushDiagnostics(0); 167 } 168 169 unsigned getMaxNodes() const { return MaxNodes; } 170 171 unsigned getMaxVisit() const { return MaxVisit; } 172 173 bool shouldVisualizeGraphviz() const { return VisualizeEGDot; } 174 175 bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; } 176 177 bool shouldVisualize() const { 178 return VisualizeEGDot || VisualizeEGUbi; 179 } 180 181 bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; } 182 183 bool shouldTrimGraph() const { return TrimGraph; } 184 185 AnalysisPurgeMode getPurgeMode() const { return PurgeDead; } 186 187 bool shouldEagerlyAssume() const { return EagerlyAssume; } 188 189 bool shouldInlineCall() const { return (IPAMode == Inlining); } 190 191 bool hasIndexer() const { return Idxer != 0; } 192 193 AnalysisDeclContext *getAnalysisDeclContextInAnotherTU(const Decl *D); 194 195 CFG *getCFG(Decl const *D) { 196 return AnaCtxMgr.getContext(D)->getCFG(); 197 } 198 199 template <typename T> 200 T *getAnalysis(Decl const *D) { 201 return AnaCtxMgr.getContext(D)->getAnalysis<T>(); 202 } 203 204 ParentMap &getParentMap(Decl const *D) { 205 return AnaCtxMgr.getContext(D)->getParentMap(); 206 } 207 208 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) { 209 return AnaCtxMgr.getContext(D); 210 } 211 212 AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) { 213 return AnaCtxMgr.getContext(D, TU); 214 } 215 216}; 217 218} // enAnaCtxMgrspace 219 220} // end clang namespace 221 222#endif 223