AnalyzerOptions.h revision d95b70175646829c26344d5f0bda1ec3009f2a5b
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/// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics. 68enum AnalysisInliningMode { 69#define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME, 70#include "clang/StaticAnalyzer/Core/Analyses.def" 71NumInliningModes 72}; 73 74/// \brief Describes the different kinds of C++ member functions which can be 75/// considered for inlining by the analyzer. 76/// 77/// These options are cumulative; enabling one kind of member function will 78/// enable all kinds with lower enum values. 79enum CXXInlineableMemberKind { 80 // Uninitialized = 0, 81 82 /// A dummy mode in which no C++ inlining is enabled. 83 CIMK_None = 1, 84 85 /// Refers to regular member function and operator calls. 86 CIMK_MemberFunctions, 87 88 /// Refers to constructors (implicit or explicit). 89 /// 90 /// Note that a constructor will not be inlined if the corresponding 91 /// destructor is non-trivial. 92 CIMK_Constructors, 93 94 /// Refers to destructors (implicit or explicit). 95 CIMK_Destructors 96}; 97 98/// \brief Describes the different modes of inter-procedural analysis. 99enum IPAKind { 100 IPAK_NotSet = 0, 101 102 /// Perform only intra-procedural analysis. 103 IPAK_None = 1, 104 105 /// Inline C functions and blocks when their definitions are available. 106 IPAK_BasicInlining = 2, 107 108 /// Inline callees(C, C++, ObjC) when their definitions are available. 109 IPAK_Inlining = 3, 110 111 /// Enable inlining of dynamically dispatched methods. 112 IPAK_DynamicDispatch = 4, 113 114 /// Enable inlining of dynamically dispatched methods, bifurcate paths when 115 /// exact type info is unavailable. 116 IPAK_DynamicDispatchBifurcate = 5 117}; 118 119class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> { 120public: 121 typedef llvm::StringMap<std::string> ConfigTable; 122 123 /// \brief Pair of checker name and enable/disable. 124 std::vector<std::pair<std::string, bool> > CheckersControlList; 125 126 /// \brief A key-value table of use-specified configuration values. 127 ConfigTable Config; 128 AnalysisStores AnalysisStoreOpt; 129 AnalysisConstraints AnalysisConstraintsOpt; 130 AnalysisDiagClients AnalysisDiagOpt; 131 AnalysisPurgeMode AnalysisPurgeOpt; 132 133 std::string AnalyzeSpecificFunction; 134 135 /// \brief The maximum number of times the analyzer visits a block. 136 unsigned maxBlockVisitOnPath; 137 138 139 unsigned ShowCheckerHelp : 1; 140 unsigned AnalyzeAll : 1; 141 unsigned AnalyzerDisplayProgress : 1; 142 unsigned AnalyzeNestedBlocks : 1; 143 144 /// \brief The flag regulates if we should eagerly assume evaluations of 145 /// conditionals, thus, bifurcating the path. 146 /// 147 /// This flag indicates how the engine should handle expressions such as: 'x = 148 /// (y != 0)'. When this flag is true then the subexpression 'y != 0' will be 149 /// eagerly assumed to be true or false, thus evaluating it to the integers 0 150 /// or 1 respectively. The upside is that this can increase analysis 151 /// precision until we have a better way to lazily evaluate such logic. The 152 /// downside is that it eagerly bifurcates paths. 153 unsigned eagerlyAssumeBinOpBifurcation : 1; 154 155 unsigned TrimGraph : 1; 156 unsigned visualizeExplodedGraphWithGraphViz : 1; 157 unsigned visualizeExplodedGraphWithUbiGraph : 1; 158 unsigned UnoptimizedCFG : 1; 159 unsigned PrintStats : 1; 160 161 /// \brief Do not re-analyze paths leading to exhausted nodes with a different 162 /// strategy. We get better code coverage when retry is enabled. 163 unsigned NoRetryExhausted : 1; 164 165 /// \brief The inlining stack depth limit. 166 unsigned InlineMaxStackDepth; 167 168 /// \brief The mode of function selection used during inlining. 169 AnalysisInliningMode InliningMode; 170 171private: 172 /// \brief Describes the kinds for high-level analyzer mode. 173 enum UserModeKind { 174 UMK_NotSet = 0, 175 /// Perform shallow but fast analyzes. 176 UMK_Shallow = 1, 177 /// Perform deep analyzes. 178 UMK_Deep = 2 179 }; 180 181 /// Controls the high-level analyzer mode, which influences the default 182 /// settings for some of the lower-level config options (such as IPAMode). 183 /// \sa getUserMode 184 UserModeKind UserMode; 185 186 /// Controls the mode of inter-procedural analysis. 187 IPAKind IPAMode; 188 189 /// Controls which C++ member functions will be considered for inlining. 190 CXXInlineableMemberKind CXXMemberInliningMode; 191 192 /// \sa includeTemporaryDtorsInCFG 193 Optional<bool> IncludeTemporaryDtorsInCFG; 194 195 /// \sa mayInlineCXXStandardLibrary 196 Optional<bool> InlineCXXStandardLibrary; 197 198 /// \sa mayInlineTemplateFunctions 199 Optional<bool> InlineTemplateFunctions; 200 201 /// \sa mayInlineCXXContainerCtorsAndDtors 202 Optional<bool> InlineCXXContainerCtorsAndDtors; 203 204 /// \sa mayInlineObjCMethod 205 Optional<bool> ObjCInliningMode; 206 207 // Cache of the "ipa-always-inline-size" setting. 208 // \sa getAlwaysInlineSize 209 Optional<unsigned> AlwaysInlineSize; 210 211 /// \sa shouldSuppressNullReturnPaths 212 Optional<bool> SuppressNullReturnPaths; 213 214 // \sa getMaxInlinableSize 215 Optional<unsigned> MaxInlinableSize; 216 217 /// \sa shouldAvoidSuppressingNullArgumentPaths 218 Optional<bool> AvoidSuppressingNullArgumentPaths; 219 220 /// \sa shouldSuppressInlinedDefensiveChecks 221 Optional<bool> SuppressInlinedDefensiveChecks; 222 223 /// \sa shouldSuppressFromCXXStandardLibrary 224 Optional<bool> SuppressFromCXXStandardLibrary; 225 226 /// \sa reportIssuesInMainSourceFile 227 Optional<bool> ReportIssuesInMainSourceFile; 228 229 /// \sa getGraphTrimInterval 230 Optional<unsigned> GraphTrimInterval; 231 232 /// \sa getMaxTimesInlineLarge 233 Optional<unsigned> MaxTimesInlineLarge; 234 235 /// \sa getMaxNodesPerTopLevelFunction 236 Optional<unsigned> MaxNodesPerTopLevelFunction; 237 238public: 239 /// Interprets an option's string value as a boolean. 240 /// 241 /// Accepts the strings "true" and "false". 242 /// If an option value is not provided, returns the given \p DefaultVal. 243 bool getBooleanOption(StringRef Name, bool DefaultVal); 244 245 /// Variant that accepts a Optional value to cache the result. 246 bool getBooleanOption(Optional<bool> &V, StringRef Name, bool DefaultVal); 247 248 /// Interprets an option's string value as an integer value. 249 int getOptionAsInteger(StringRef Name, int DefaultVal); 250 251 /// \brief Retrieves and sets the UserMode. This is a high-level option, 252 /// which is used to set other low-level options. It is not accessible 253 /// outside of AnalyzerOptions. 254 UserModeKind getUserMode(); 255 256 /// \brief Returns the inter-procedural analysis mode. 257 IPAKind getIPAMode(); 258 259 /// Returns the option controlling which C++ member functions will be 260 /// considered for inlining. 261 /// 262 /// This is controlled by the 'c++-inlining' config option. 263 /// 264 /// \sa CXXMemberInliningMode 265 bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K); 266 267 /// Returns true if ObjectiveC inlining is enabled, false otherwise. 268 bool mayInlineObjCMethod(); 269 270 /// Returns whether or not the destructors for C++ temporary objects should 271 /// be included in the CFG. 272 /// 273 /// This is controlled by the 'cfg-temporary-dtors' config option, which 274 /// accepts the values "true" and "false". 275 bool includeTemporaryDtorsInCFG(); 276 277 /// Returns whether or not C++ standard library functions may be considered 278 /// for inlining. 279 /// 280 /// This is controlled by the 'c++-stdlib-inlining' config option, which 281 /// accepts the values "true" and "false". 282 bool mayInlineCXXStandardLibrary(); 283 284 /// Returns whether or not templated functions may be considered for inlining. 285 /// 286 /// This is controlled by the 'c++-template-inlining' config option, which 287 /// accepts the values "true" and "false". 288 bool mayInlineTemplateFunctions(); 289 290 /// Returns whether or not constructors and destructors of C++ container 291 /// objects may be considered for inlining. 292 /// 293 /// This is controlled by the 'c++-container-inlining' config option, which 294 /// accepts the values "true" and "false". 295 bool mayInlineCXXContainerCtorsAndDtors(); 296 297 /// Returns whether or not paths that go through null returns should be 298 /// suppressed. 299 /// 300 /// This is a heuristic for avoiding bug reports with paths that go through 301 /// inlined functions that are more defensive than their callers. 302 /// 303 /// This is controlled by the 'suppress-null-return-paths' config option, 304 /// which accepts the values "true" and "false". 305 bool shouldSuppressNullReturnPaths(); 306 307 /// Returns whether a bug report should \em not be suppressed if its path 308 /// includes a call with a null argument, even if that call has a null return. 309 /// 310 /// This option has no effect when #shouldSuppressNullReturnPaths() is false. 311 /// 312 /// This is a counter-heuristic to avoid false negatives. 313 /// 314 /// This is controlled by the 'avoid-suppressing-null-argument-paths' config 315 /// option, which accepts the values "true" and "false". 316 bool shouldAvoidSuppressingNullArgumentPaths(); 317 318 /// Returns whether or not diagnostics containing inlined defensive NULL 319 /// checks should be suppressed. 320 /// 321 /// This is controlled by the 'suppress-inlined-defensive-checks' config 322 /// option, which accepts the values "true" and "false". 323 bool shouldSuppressInlinedDefensiveChecks(); 324 325 /// Returns whether or not diagnostics reported within the C++ standard 326 /// library should be suppressed. 327 /// 328 /// This is controlled by the 'suppress-c++-stdlib' config option, 329 /// which accepts the values "true" and "false". 330 bool shouldSuppressFromCXXStandardLibrary(); 331 332 /// Returns whether or not the diagnostic report should be always reported 333 /// in the main source file and not the headers. 334 /// 335 /// This is controlled by the 'report-in-main-source-file' config option, 336 /// which accepts the values "true" and "false". 337 bool shouldReportIssuesInMainSourceFile(); 338 339 /// Returns whether irrelevant parts of a bug report path should be pruned 340 /// out of the final output. 341 /// 342 /// This is controlled by the 'prune-paths' config option, which accepts the 343 /// values "true" and "false". 344 bool shouldPrunePaths(); 345 346 /// Returns true if 'static' initializers should be in conditional logic 347 /// in the CFG. 348 bool shouldConditionalizeStaticInitializers(); 349 350 // Returns the size of the functions (in basic blocks), which should be 351 // considered to be small enough to always inline. 352 // 353 // This is controlled by "ipa-always-inline-size" analyzer-config option. 354 unsigned getAlwaysInlineSize(); 355 356 // Returns the bound on the number of basic blocks in an inlined function 357 // (50 by default). 358 // 359 // This is controlled by "-analyzer-config max-inlinable-size" option. 360 unsigned getMaxInlinableSize(); 361 362 /// Returns true if the analyzer engine should synthesize fake bodies 363 /// for well-known functions. 364 bool shouldSynthesizeBodies(); 365 366 /// Returns how often nodes in the ExplodedGraph should be recycled to save 367 /// memory. 368 /// 369 /// This is controlled by the 'graph-trim-interval' config option. To disable 370 /// node reclamation, set the option to "0". 371 unsigned getGraphTrimInterval(); 372 373 /// Returns the maximum times a large function could be inlined. 374 /// 375 /// This is controlled by the 'max-times-inline-large' config option. 376 unsigned getMaxTimesInlineLarge(); 377 378 /// Returns the maximum number of nodes the analyzer can generate while 379 /// exploring a top level function (for each exploded graph). 380 /// 150000 is default; 0 means no limit. 381 /// 382 /// This is controlled by the 'max-nodes' config option. 383 unsigned getMaxNodesPerTopLevelFunction(); 384 385public: 386 AnalyzerOptions() : 387 AnalysisStoreOpt(RegionStoreModel), 388 AnalysisConstraintsOpt(RangeConstraintsModel), 389 AnalysisDiagOpt(PD_HTML), 390 AnalysisPurgeOpt(PurgeStmt), 391 ShowCheckerHelp(0), 392 AnalyzeAll(0), 393 AnalyzerDisplayProgress(0), 394 AnalyzeNestedBlocks(0), 395 eagerlyAssumeBinOpBifurcation(0), 396 TrimGraph(0), 397 visualizeExplodedGraphWithGraphViz(0), 398 visualizeExplodedGraphWithUbiGraph(0), 399 UnoptimizedCFG(0), 400 PrintStats(0), 401 NoRetryExhausted(0), 402 // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls). 403 InlineMaxStackDepth(5), 404 InliningMode(NoRedundancy), 405 UserMode(UMK_NotSet), 406 IPAMode(IPAK_NotSet), 407 CXXMemberInliningMode() {} 408 409}; 410 411typedef IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef; 412 413} 414 415#endif 416