AnalyzerOptions.h revision 7959671d456c916706a5f61af609d8f1fc95decf
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 "clang/Basic/LLVM.h" 19#include "llvm/ADT/IntrusiveRefCntPtr.h" 20#include "llvm/ADT/Optional.h" 21#include "llvm/ADT/StringMap.h" 22#include <string> 23#include <vector> 24 25namespace clang { 26class ASTConsumer; 27class DiagnosticsEngine; 28class Preprocessor; 29class LangOptions; 30 31/// Analysis - Set of available source code analyses. 32enum Analyses { 33#define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE) NAME, 34#include "clang/StaticAnalyzer/Core/Analyses.def" 35NumAnalyses 36}; 37 38/// AnalysisStores - Set of available analysis store models. 39enum AnalysisStores { 40#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) NAME##Model, 41#include "clang/StaticAnalyzer/Core/Analyses.def" 42NumStores 43}; 44 45/// AnalysisConstraints - Set of available constraint models. 46enum AnalysisConstraints { 47#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) NAME##Model, 48#include "clang/StaticAnalyzer/Core/Analyses.def" 49NumConstraints 50}; 51 52/// AnalysisDiagClients - Set of available diagnostic clients for rendering 53/// analysis results. 54enum AnalysisDiagClients { 55#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREAT) PD_##NAME, 56#include "clang/StaticAnalyzer/Core/Analyses.def" 57NUM_ANALYSIS_DIAG_CLIENTS 58}; 59 60/// AnalysisPurgeModes - Set of available strategies for dead symbol removal. 61enum AnalysisPurgeMode { 62#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) NAME, 63#include "clang/StaticAnalyzer/Core/Analyses.def" 64NumPurgeModes 65}; 66 67/// AnalysisIPAMode - Set of inter-procedural modes. 68enum AnalysisIPAMode { 69#define ANALYSIS_IPA(NAME, CMDFLAG, DESC) NAME, 70#include "clang/StaticAnalyzer/Core/Analyses.def" 71NumIPAModes 72}; 73 74/// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics. 75enum AnalysisInliningMode { 76#define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME, 77#include "clang/StaticAnalyzer/Core/Analyses.def" 78NumInliningModes 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. 86enum 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 106class AnalyzerOptions : public llvm::RefCountedBase<AnalyzerOptions> { 107public: 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 PrintStats : 1; 153 154 /// \brief Do not re-analyze paths leading to exhausted nodes with a different 155 /// strategy. We get better code coverage when retry is enabled. 156 unsigned NoRetryExhausted : 1; 157 158 /// \brief The inlining stack depth limit. 159 unsigned InlineMaxStackDepth; 160 161 /// \brief The mode of function selection used during inlining. 162 unsigned InlineMaxFunctionSize; 163 164 /// \brief The mode of function selection used during inlining. 165 AnalysisInliningMode InliningMode; 166 167private: 168 /// Controls which C++ member functions will be considered for inlining. 169 CXXInlineableMemberKind CXXMemberInliningMode; 170 171 /// \sa includeTemporaryDtorsInCFG 172 llvm::Optional<bool> IncludeTemporaryDtorsInCFG; 173 174 /// \sa mayInlineCXXStandardLibrary 175 llvm::Optional<bool> InlineCXXStandardLibrary; 176 177 /// \sa mayInlineTemplateFunctions 178 llvm::Optional<bool> InlineTemplateFunctions; 179 180 /// \sa mayInlineObjCMethod 181 llvm::Optional<bool> ObjCInliningMode; 182 183 // Cache of the "ipa-always-inline-size" setting. 184 // \sa getAlwaysInlineSize 185 llvm::Optional<unsigned> AlwaysInlineSize; 186 187 /// \sa shouldPruneNullReturnPaths 188 llvm::Optional<bool> PruneNullReturnPaths; 189 190 /// \sa shouldAvoidSuppressingNullArgumentPaths 191 llvm::Optional<bool> AvoidSuppressingNullArgumentPaths; 192 193 /// \sa getGraphTrimInterval 194 llvm::Optional<unsigned> GraphTrimInterval; 195 196 /// \sa getMaxTimesInlineLarge 197 llvm::Optional<unsigned> MaxTimesInlineLarge; 198 199 /// Interprets an option's string value as a boolean. 200 /// 201 /// Accepts the strings "true" and "false". 202 /// If an option value is not provided, returns the given \p DefaultVal. 203 bool getBooleanOption(StringRef Name, bool DefaultVal); 204 205 /// Variant that accepts a Optional value to cache the result. 206 bool getBooleanOption(llvm::Optional<bool> &V, StringRef Name, 207 bool DefaultVal); 208 209 /// Interprets an option's string value as an integer value. 210 int getOptionAsInteger(llvm::StringRef Name, int DefaultVal); 211 212public: 213 /// Returns the option controlling which C++ member functions will be 214 /// considered for inlining. 215 /// 216 /// This is controlled by the 'c++-inlining' config option. 217 /// 218 /// \sa CXXMemberInliningMode 219 bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K); 220 221 /// Returns true if ObjectiveC inlining is enabled, false otherwise. 222 bool mayInlineObjCMethod(); 223 224 /// Returns whether or not the destructors for C++ temporary objects should 225 /// be included in the CFG. 226 /// 227 /// This is controlled by the 'cfg-temporary-dtors' config option, which 228 /// accepts the values "true" and "false". 229 bool includeTemporaryDtorsInCFG(); 230 231 /// Returns whether or not C++ standard library functions may be considered 232 /// for inlining. 233 /// 234 /// This is controlled by the 'c++-stdlib-inlining' config option, which 235 /// accepts the values "true" and "false". 236 bool mayInlineCXXStandardLibrary(); 237 238 /// Returns whether or not templated functions may be considered for inlining. 239 /// 240 /// This is controlled by the 'c++-template-inlining' config option, which 241 /// accepts the values "true" and "false". 242 bool mayInlineTemplateFunctions(); 243 244 /// Returns whether or not paths that go through null returns should be 245 /// suppressed. 246 /// 247 /// This is a heuristic for avoiding bug reports with paths that go through 248 /// inlined functions that are more defensive than their callers. 249 /// 250 /// This is controlled by the 'suppress-null-return-paths' config option, 251 /// which accepts the values "true" and "false". 252 bool shouldPruneNullReturnPaths(); 253 254 /// Returns whether a bug report should \em not be suppressed if its path 255 /// includes a call with a null argument, even if that call has a null return. 256 /// 257 /// This option has no effect when #shouldPruneNullReturnPaths() is false. 258 /// 259 /// This is a counter-heuristic to avoid false negatives. 260 /// 261 /// This is controlled by the 'avoid-suppressing-null-argument-paths' config 262 /// option, which accepts the values "true" and "false". 263 bool shouldAvoidSuppressingNullArgumentPaths(); 264 265 // Returns the size of the functions (in basic blocks), which should be 266 // considered to be small enough to always inline. 267 // 268 // This is controlled by "ipa-always-inline-size" analyzer-config option. 269 unsigned getAlwaysInlineSize(); 270 271 /// Returns true if the analyzer engine should synthesize fake bodies 272 /// for well-known functions. 273 bool shouldSynthesizeBodies(); 274 275 /// Returns how often nodes in the ExplodedGraph should be recycled to save 276 /// memory. 277 /// 278 /// This is controlled by the 'graph-trim-interval' config option. To disable 279 /// node reclamation, set the option to "0". 280 unsigned getGraphTrimInterval(); 281 282 /// Returns the maximum times a large function could be inlined. 283 /// 284 /// This is controlled by the 'max-times-inline-large' config option. 285 unsigned getMaxTimesInlineLarge(); 286 287public: 288 AnalyzerOptions() : CXXMemberInliningMode() { 289 AnalysisStoreOpt = RegionStoreModel; 290 AnalysisConstraintsOpt = RangeConstraintsModel; 291 AnalysisDiagOpt = PD_HTML; 292 AnalysisPurgeOpt = PurgeStmt; 293 IPAMode = DynamicDispatchBifurcate; 294 ShowCheckerHelp = 0; 295 AnalyzeAll = 0; 296 AnalyzerDisplayProgress = 0; 297 AnalyzeNestedBlocks = 0; 298 eagerlyAssumeBinOpBifurcation = 0; 299 TrimGraph = 0; 300 visualizeExplodedGraphWithGraphViz = 0; 301 visualizeExplodedGraphWithUbiGraph = 0; 302 UnoptimizedCFG = 0; 303 PrintStats = 0; 304 NoRetryExhausted = 0; 305 // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls). 306 InlineMaxStackDepth = 5; 307 InlineMaxFunctionSize = 200; 308 InliningMode = NoRedundancy; 309 } 310}; 311 312typedef llvm::IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef; 313 314} 315 316#endif 317