Home | History | Annotate | Download | only in PathSensitive
      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 
     23 namespace clang {
     24 
     25 namespace ento {
     26   class CheckerManager;
     27 
     28 class AnalysisManager : public BugReporterData {
     29   virtual void anchor();
     30   AnalysisDeclContextManager AnaCtxMgr;
     31 
     32   ASTContext &Ctx;
     33   DiagnosticsEngine &Diags;
     34   const LangOptions &LangOpts;
     35 
     36   OwningPtr<PathDiagnosticConsumer> PD;
     37 
     38   // Configurable components creators.
     39   StoreManagerCreator CreateStoreMgr;
     40   ConstraintManagerCreator CreateConstraintMgr;
     41 
     42   CheckerManager *CheckerMgr;
     43 
     44   enum AnalysisScope { ScopeTU, ScopeDecl } AScope;
     45 
     46   /// \brief The maximum number of exploded nodes the analyzer will generate.
     47   unsigned MaxNodes;
     48 
     49   /// \brief The maximum number of times the analyzer visits a block.
     50   unsigned MaxVisit;
     51 
     52   bool VisualizeEGDot;
     53   bool VisualizeEGUbi;
     54   AnalysisPurgeMode PurgeDead;
     55 
     56   /// \brief The flag regulates if we should eagerly assume evaluations of
     57   /// conditionals, thus, bifurcating the path.
     58   ///
     59   /// EagerlyAssume - A flag indicating how the engine should handle
     60   ///   expressions such as: 'x = (y != 0)'.  When this flag is true then
     61   ///   the subexpression 'y != 0' will be eagerly assumed to be true or false,
     62   ///   thus evaluating it to the integers 0 or 1 respectively.  The upside
     63   ///   is that this can increase analysis precision until we have a better way
     64   ///   to lazily evaluate such logic.  The downside is that it eagerly
     65   ///   bifurcates paths.
     66   bool EagerlyAssume;
     67   bool TrimGraph;
     68   bool EagerlyTrimEGraph;
     69 
     70 public:
     71   // \brief inter-procedural analysis mode.
     72   AnalysisIPAMode IPAMode;
     73 
     74   // Settings for inlining tuning.
     75   /// \brief The inlining stack depth limit.
     76   unsigned InlineMaxStackDepth;
     77   /// \brief The max number of basic blocks in a function being inlined.
     78   unsigned InlineMaxFunctionSize;
     79   /// \brief The mode of function selection used during inlining.
     80   AnalysisInliningMode InliningMode;
     81 
     82   /// \brief Do not re-analyze paths leading to exhausted nodes with a different
     83   /// strategy. We get better code coverage when retry is enabled.
     84   bool NoRetryExhausted;
     85 
     86 public:
     87   AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
     88                   const LangOptions &lang, PathDiagnosticConsumer *pd,
     89                   StoreManagerCreator storemgr,
     90                   ConstraintManagerCreator constraintmgr,
     91                   CheckerManager *checkerMgr,
     92                   unsigned maxnodes, unsigned maxvisit,
     93                   bool vizdot, bool vizubi, AnalysisPurgeMode purge,
     94                   bool eager, bool trim,
     95                   bool useUnoptimizedCFG,
     96                   bool addImplicitDtors, bool addInitializers,
     97                   bool eagerlyTrimEGraph,
     98                   AnalysisIPAMode ipa,
     99                   unsigned inlineMaxStack,
    100                   unsigned inlineMaxFunctionSize,
    101                   AnalysisInliningMode inliningMode,
    102                   bool NoRetry);
    103 
    104   /// Construct a clone of the given AnalysisManager with the given ASTContext
    105   /// and DiagnosticsEngine.
    106   AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
    107                   AnalysisManager &ParentAM);
    108 
    109   ~AnalysisManager() { FlushDiagnostics(); }
    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   virtual PathDiagnosticConsumer *getPathDiagnosticConsumer() {
    146     return PD.get();
    147   }
    148 
    149   void FlushDiagnostics() {
    150     if (PD.get())
    151       PD->FlushDiagnostics(0);
    152   }
    153 
    154   unsigned getMaxNodes() const { return MaxNodes; }
    155 
    156   unsigned getMaxVisit() const { return MaxVisit; }
    157 
    158   bool shouldVisualizeGraphviz() const { return VisualizeEGDot; }
    159 
    160   bool shouldVisualizeUbigraph() const { return VisualizeEGUbi; }
    161 
    162   bool shouldVisualize() const {
    163     return VisualizeEGDot || VisualizeEGUbi;
    164   }
    165 
    166   bool shouldEagerlyTrimExplodedGraph() const { return EagerlyTrimEGraph; }
    167 
    168   bool shouldTrimGraph() const { return TrimGraph; }
    169 
    170   AnalysisPurgeMode getPurgeMode() const { return PurgeDead; }
    171 
    172   bool shouldEagerlyAssume() const { return EagerlyAssume; }
    173 
    174   bool shouldInlineCall() const { return (IPAMode == Inlining); }
    175 
    176   CFG *getCFG(Decl const *D) {
    177     return AnaCtxMgr.getContext(D)->getCFG();
    178   }
    179 
    180   template <typename T>
    181   T *getAnalysis(Decl const *D) {
    182     return AnaCtxMgr.getContext(D)->getAnalysis<T>();
    183   }
    184 
    185   ParentMap &getParentMap(Decl const *D) {
    186     return AnaCtxMgr.getContext(D)->getParentMap();
    187   }
    188 
    189   AnalysisDeclContext *getAnalysisDeclContext(const Decl *D) {
    190     return AnaCtxMgr.getContext(D);
    191   }
    192 
    193   AnalysisDeclContext *getAnalysisDeclContext(const Decl *D, idx::TranslationUnit *TU) {
    194     return AnaCtxMgr.getContext(D, TU);
    195   }
    196 
    197 };
    198 
    199 } // enAnaCtxMgrspace
    200 
    201 } // end clang namespace
    202 
    203 #endif
    204