Home | History | Annotate | Download | only in Core
      1 //===--- AnalyzerOptions.h - Analysis Engine Options ------------*- 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 header defines various options for the static analyzer that are set
     11 // by the frontend and are consulted throughout the analyzer.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_CLANG_ANALYZEROPTIONS_H
     16 #define LLVM_CLANG_ANALYZEROPTIONS_H
     17 
     18 #include <string>
     19 #include <vector>
     20 #include "clang/Basic/LLVM.h"
     21 #include "llvm/ADT/StringMap.h"
     22 #include "llvm/ADT/Optional.h"
     23 #include "llvm/ADT/IntrusiveRefCntPtr.h"
     24 
     25 namespace clang {
     26 class ASTConsumer;
     27 class DiagnosticsEngine;
     28 class Preprocessor;
     29 class LangOptions;
     30 
     31 /// Analysis - Set of available source code analyses.
     32 enum Analyses {
     33 #define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE) NAME,
     34 #include "clang/StaticAnalyzer/Core/Analyses.def"
     35 NumAnalyses
     36 };
     37 
     38 /// AnalysisStores - Set of available analysis store models.
     39 enum AnalysisStores {
     40 #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) NAME##Model,
     41 #include "clang/StaticAnalyzer/Core/Analyses.def"
     42 NumStores
     43 };
     44 
     45 /// AnalysisConstraints - Set of available constraint models.
     46 enum AnalysisConstraints {
     47 #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) NAME##Model,
     48 #include "clang/StaticAnalyzer/Core/Analyses.def"
     49 NumConstraints
     50 };
     51 
     52 /// AnalysisDiagClients - Set of available diagnostic clients for rendering
     53 ///  analysis results.
     54 enum AnalysisDiagClients {
     55 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREAT) PD_##NAME,
     56 #include "clang/StaticAnalyzer/Core/Analyses.def"
     57 NUM_ANALYSIS_DIAG_CLIENTS
     58 };
     59 
     60 /// AnalysisPurgeModes - Set of available strategies for dead symbol removal.
     61 enum AnalysisPurgeMode {
     62 #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) NAME,
     63 #include "clang/StaticAnalyzer/Core/Analyses.def"
     64 NumPurgeModes
     65 };
     66 
     67 /// AnalysisIPAMode - Set of inter-procedural modes.
     68 enum AnalysisIPAMode {
     69 #define ANALYSIS_IPA(NAME, CMDFLAG, DESC) NAME,
     70 #include "clang/StaticAnalyzer/Core/Analyses.def"
     71 NumIPAModes
     72 };
     73 
     74 /// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics.
     75 enum AnalysisInliningMode {
     76 #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME,
     77 #include "clang/StaticAnalyzer/Core/Analyses.def"
     78 NumInliningModes
     79 };
     80 
     81 /// \brief Describes the different kinds of C++ member functions which can be
     82 /// considered for inlining by the analyzer.
     83 ///
     84 /// These options are cumulative; enabling one kind of member function will
     85 /// enable all kinds with lower enum values.
     86 enum CXXInlineableMemberKind {
     87   // Uninitialized = 0,
     88 
     89   /// A dummy mode in which no C++ inlining is enabled.
     90   CIMK_None = 1,
     91 
     92   /// Refers to regular member function and operator calls.
     93   CIMK_MemberFunctions,
     94 
     95   /// Refers to constructors (implicit or explicit).
     96   ///
     97   /// Note that a constructor will not be inlined if the corresponding
     98   /// destructor is non-trivial.
     99   CIMK_Constructors,
    100 
    101   /// Refers to destructors (implicit or explicit).
    102   CIMK_Destructors
    103 };
    104 
    105 
    106 class AnalyzerOptions : public llvm::RefCountedBase<AnalyzerOptions> {
    107 public:
    108   typedef llvm::StringMap<std::string> ConfigTable;
    109 
    110   /// \brief Pair of checker name and enable/disable.
    111   std::vector<std::pair<std::string, bool> > CheckersControlList;
    112 
    113   /// \brief A key-value table of use-specified configuration values.
    114   ConfigTable Config;
    115   AnalysisStores AnalysisStoreOpt;
    116   AnalysisConstraints AnalysisConstraintsOpt;
    117   AnalysisDiagClients AnalysisDiagOpt;
    118   AnalysisPurgeMode AnalysisPurgeOpt;
    119 
    120   // \brief The interprocedural analysis mode.
    121   AnalysisIPAMode IPAMode;
    122 
    123   std::string AnalyzeSpecificFunction;
    124 
    125   /// \brief The maximum number of exploded nodes the analyzer will generate.
    126   unsigned MaxNodes;
    127 
    128   /// \brief The maximum number of times the analyzer visits a block.
    129   unsigned maxBlockVisitOnPath;
    130 
    131 
    132   unsigned ShowCheckerHelp : 1;
    133   unsigned AnalyzeAll : 1;
    134   unsigned AnalyzerDisplayProgress : 1;
    135   unsigned AnalyzeNestedBlocks : 1;
    136 
    137   /// \brief The flag regulates if we should eagerly assume evaluations of
    138   /// conditionals, thus, bifurcating the path.
    139   ///
    140   /// This flag indicates how the engine should handle expressions such as: 'x =
    141   /// (y != 0)'.  When this flag is true then the subexpression 'y != 0' will be
    142   /// eagerly assumed to be true or false, thus evaluating it to the integers 0
    143   /// or 1 respectively.  The upside is that this can increase analysis
    144   /// precision until we have a better way to lazily evaluate such logic.  The
    145   /// downside is that it eagerly bifurcates paths.
    146   unsigned eagerlyAssumeBinOpBifurcation : 1;
    147 
    148   unsigned TrimGraph : 1;
    149   unsigned visualizeExplodedGraphWithGraphViz : 1;
    150   unsigned visualizeExplodedGraphWithUbiGraph : 1;
    151   unsigned UnoptimizedCFG : 1;
    152   unsigned eagerlyTrimExplodedGraph : 1;
    153   unsigned PrintStats : 1;
    154 
    155   /// \brief Do not re-analyze paths leading to exhausted nodes with a different
    156   /// strategy. We get better code coverage when retry is enabled.
    157   unsigned NoRetryExhausted : 1;
    158 
    159   /// \brief The inlining stack depth limit.
    160   unsigned InlineMaxStackDepth;
    161 
    162   /// \brief The mode of function selection used during inlining.
    163   unsigned InlineMaxFunctionSize;
    164 
    165   /// \brief The mode of function selection used during inlining.
    166   AnalysisInliningMode InliningMode;
    167 
    168 private:
    169   /// Controls which C++ member functions will be considered for inlining.
    170   CXXInlineableMemberKind CXXMemberInliningMode;
    171 
    172   /// \sa includeTemporaryDtorsInCFG
    173   llvm::Optional<bool> IncludeTemporaryDtorsInCFG;
    174 
    175   /// \sa mayInlineCXXStandardLibrary
    176   llvm::Optional<bool> InlineCXXStandardLibrary;
    177 
    178   /// \sa mayInlineTemplateFunctions
    179   llvm::Optional<bool> InlineTemplateFunctions;
    180 
    181   /// Interprets an option's string value as a boolean.
    182   ///
    183   /// Accepts the strings "true" and "false".
    184   /// If an option value is not provided, returns the given \p DefaultVal.
    185   bool getBooleanOption(StringRef Name, bool DefaultVal) const;
    186 
    187 public:
    188   /// Returns the option controlling which C++ member functions will be
    189   /// considered for inlining.
    190   ///
    191   /// This is controlled by the 'c++-inlining' config option.
    192   ///
    193   /// \sa CXXMemberInliningMode
    194   bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const;
    195 
    196   /// Returns whether or not the destructors for C++ temporary objects should
    197   /// be included in the CFG.
    198   ///
    199   /// This is controlled by the 'cfg-temporary-dtors' config option, which
    200   /// accepts the values "true" and "false".
    201   bool includeTemporaryDtorsInCFG() const;
    202 
    203   /// Returns whether or not C++ standard library functions may be considered
    204   /// for inlining.
    205   ///
    206   /// This is controlled by the 'c++-stdlib-inlining' config option, which
    207   /// accepts the values "true" and "false".
    208   bool mayInlineCXXStandardLibrary() const;
    209 
    210   /// Returns whether or not templated functions may be considered for inlining.
    211   ///
    212   /// This is controlled by the 'c++-template-inlining' config option, which
    213   /// accepts the values "true" and "false".
    214   bool mayInlineTemplateFunctions() const;
    215 
    216 public:
    217   AnalyzerOptions() : CXXMemberInliningMode() {
    218     AnalysisStoreOpt = RegionStoreModel;
    219     AnalysisConstraintsOpt = RangeConstraintsModel;
    220     AnalysisDiagOpt = PD_HTML;
    221     AnalysisPurgeOpt = PurgeStmt;
    222     IPAMode = DynamicDispatchBifurcate;
    223     ShowCheckerHelp = 0;
    224     AnalyzeAll = 0;
    225     AnalyzerDisplayProgress = 0;
    226     AnalyzeNestedBlocks = 0;
    227     eagerlyAssumeBinOpBifurcation = 0;
    228     TrimGraph = 0;
    229     visualizeExplodedGraphWithGraphViz = 0;
    230     visualizeExplodedGraphWithUbiGraph = 0;
    231     UnoptimizedCFG = 0;
    232     eagerlyTrimExplodedGraph = 0;
    233     PrintStats = 0;
    234     NoRetryExhausted = 0;
    235     // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
    236     InlineMaxStackDepth = 5;
    237     InlineMaxFunctionSize = 200;
    238     InliningMode = NoRedundancy;
    239   }
    240 };
    241 
    242 typedef llvm::IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef;
    243 
    244 }
    245 
    246 #endif
    247