AnalyzerOptions.h revision d130140cb7bce73b4350c5d50495443abe38418a
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 exploded nodes the analyzer will generate. 136 unsigned MaxNodes; 137 138 /// \brief The maximum number of times the analyzer visits a block. 139 unsigned maxBlockVisitOnPath; 140 141 142 unsigned ShowCheckerHelp : 1; 143 unsigned AnalyzeAll : 1; 144 unsigned AnalyzerDisplayProgress : 1; 145 unsigned AnalyzeNestedBlocks : 1; 146 147 /// \brief The flag regulates if we should eagerly assume evaluations of 148 /// conditionals, thus, bifurcating the path. 149 /// 150 /// This flag indicates how the engine should handle expressions such as: 'x = 151 /// (y != 0)'. When this flag is true then the subexpression 'y != 0' will be 152 /// eagerly assumed to be true or false, thus evaluating it to the integers 0 153 /// or 1 respectively. The upside is that this can increase analysis 154 /// precision until we have a better way to lazily evaluate such logic. The 155 /// downside is that it eagerly bifurcates paths. 156 unsigned eagerlyAssumeBinOpBifurcation : 1; 157 158 unsigned TrimGraph : 1; 159 unsigned visualizeExplodedGraphWithGraphViz : 1; 160 unsigned visualizeExplodedGraphWithUbiGraph : 1; 161 unsigned UnoptimizedCFG : 1; 162 unsigned PrintStats : 1; 163 164 /// \brief Do not re-analyze paths leading to exhausted nodes with a different 165 /// strategy. We get better code coverage when retry is enabled. 166 unsigned NoRetryExhausted : 1; 167 168 /// \brief The inlining stack depth limit. 169 unsigned InlineMaxStackDepth; 170 171 /// \brief The mode of function selection used during inlining. 172 unsigned InlineMaxFunctionSize; 173 174 /// \brief The mode of function selection used during inlining. 175 AnalysisInliningMode InliningMode; 176 177private: 178 /// \brief Describes the kinds for high-level analyzer mode. 179 enum UserModeKind { 180 UMK_NotSet = 0, 181 /// Perform shallow but fast analyzes. 182 UMK_Shallow = 1, 183 /// Perform deep analyzes. 184 UMK_Deep = 2 185 }; 186 187 /// Controls the high-level analyzer mode, which influences the default 188 /// settings for some of the lower-level config options (such as IPAMode). 189 /// \sa getUserMode 190 UserModeKind UserMode; 191 192 /// Controls the mode of inter-procedural analysis. 193 IPAKind IPAMode; 194 195 /// Controls which C++ member functions will be considered for inlining. 196 CXXInlineableMemberKind CXXMemberInliningMode; 197 198 /// \sa includeTemporaryDtorsInCFG 199 llvm::Optional<bool> IncludeTemporaryDtorsInCFG; 200 201 /// \sa mayInlineCXXStandardLibrary 202 llvm::Optional<bool> InlineCXXStandardLibrary; 203 204 /// \sa mayInlineTemplateFunctions 205 llvm::Optional<bool> InlineTemplateFunctions; 206 207 /// \sa mayInlineObjCMethod 208 llvm::Optional<bool> ObjCInliningMode; 209 210 // Cache of the "ipa-always-inline-size" setting. 211 // \sa getAlwaysInlineSize 212 llvm::Optional<unsigned> AlwaysInlineSize; 213 214 /// \sa shouldPruneNullReturnPaths 215 llvm::Optional<bool> PruneNullReturnPaths; 216 217 /// \sa shouldAvoidSuppressingNullArgumentPaths 218 llvm::Optional<bool> AvoidSuppressingNullArgumentPaths; 219 220 /// \sa getGraphTrimInterval 221 llvm::Optional<unsigned> GraphTrimInterval; 222 223 /// \sa getMaxTimesInlineLarge 224 llvm::Optional<unsigned> MaxTimesInlineLarge; 225 226 /// Interprets an option's string value as a boolean. 227 /// 228 /// Accepts the strings "true" and "false". 229 /// If an option value is not provided, returns the given \p DefaultVal. 230 bool getBooleanOption(StringRef Name, bool DefaultVal); 231 232 /// Variant that accepts a Optional value to cache the result. 233 bool getBooleanOption(llvm::Optional<bool> &V, StringRef Name, 234 bool DefaultVal); 235 236 /// Interprets an option's string value as an integer value. 237 int getOptionAsInteger(StringRef Name, int DefaultVal); 238 239public: 240 /// \brief Retrieves and sets the UserMode. This is a high-level option, 241 /// which is used to set other low-level options. It is not accessible 242 /// outside of AnalyzerOptions. 243 UserModeKind getUserMode(); 244 245 /// \brief Returns the inter-procedural analysis mode. 246 IPAKind getIPAMode(); 247 248 /// Returns the option controlling which C++ member functions will be 249 /// considered for inlining. 250 /// 251 /// This is controlled by the 'c++-inlining' config option. 252 /// 253 /// \sa CXXMemberInliningMode 254 bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K); 255 256 /// Returns true if ObjectiveC inlining is enabled, false otherwise. 257 bool mayInlineObjCMethod(); 258 259 /// Returns whether or not the destructors for C++ temporary objects should 260 /// be included in the CFG. 261 /// 262 /// This is controlled by the 'cfg-temporary-dtors' config option, which 263 /// accepts the values "true" and "false". 264 bool includeTemporaryDtorsInCFG(); 265 266 /// Returns whether or not C++ standard library functions may be considered 267 /// for inlining. 268 /// 269 /// This is controlled by the 'c++-stdlib-inlining' config option, which 270 /// accepts the values "true" and "false". 271 bool mayInlineCXXStandardLibrary(); 272 273 /// Returns whether or not templated functions may be considered for inlining. 274 /// 275 /// This is controlled by the 'c++-template-inlining' config option, which 276 /// accepts the values "true" and "false". 277 bool mayInlineTemplateFunctions(); 278 279 /// Returns whether or not paths that go through null returns should be 280 /// suppressed. 281 /// 282 /// This is a heuristic for avoiding bug reports with paths that go through 283 /// inlined functions that are more defensive than their callers. 284 /// 285 /// This is controlled by the 'suppress-null-return-paths' config option, 286 /// which accepts the values "true" and "false". 287 bool shouldPruneNullReturnPaths(); 288 289 /// Returns whether a bug report should \em not be suppressed if its path 290 /// includes a call with a null argument, even if that call has a null return. 291 /// 292 /// This option has no effect when #shouldPruneNullReturnPaths() is false. 293 /// 294 /// This is a counter-heuristic to avoid false negatives. 295 /// 296 /// This is controlled by the 'avoid-suppressing-null-argument-paths' config 297 /// option, which accepts the values "true" and "false". 298 bool shouldAvoidSuppressingNullArgumentPaths(); 299 300 // Returns the size of the functions (in basic blocks), which should be 301 // considered to be small enough to always inline. 302 // 303 // This is controlled by "ipa-always-inline-size" analyzer-config option. 304 unsigned getAlwaysInlineSize(); 305 306 /// Returns true if the analyzer engine should synthesize fake bodies 307 /// for well-known functions. 308 bool shouldSynthesizeBodies(); 309 310 /// Returns how often nodes in the ExplodedGraph should be recycled to save 311 /// memory. 312 /// 313 /// This is controlled by the 'graph-trim-interval' config option. To disable 314 /// node reclamation, set the option to "0". 315 unsigned getGraphTrimInterval(); 316 317 /// Returns the maximum times a large function could be inlined. 318 /// 319 /// This is controlled by the 'max-times-inline-large' config option. 320 unsigned getMaxTimesInlineLarge(); 321 322public: 323 AnalyzerOptions() : 324 AnalysisStoreOpt(RegionStoreModel), 325 AnalysisConstraintsOpt(RangeConstraintsModel), 326 AnalysisDiagOpt(PD_HTML), 327 AnalysisPurgeOpt(PurgeStmt), 328 ShowCheckerHelp(0), 329 AnalyzeAll(0), 330 AnalyzerDisplayProgress(0), 331 AnalyzeNestedBlocks(0), 332 eagerlyAssumeBinOpBifurcation(0), 333 TrimGraph(0), 334 visualizeExplodedGraphWithGraphViz(0), 335 visualizeExplodedGraphWithUbiGraph(0), 336 UnoptimizedCFG(0), 337 PrintStats(0), 338 NoRetryExhausted(0), 339 // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls). 340 InlineMaxStackDepth(5), 341 InlineMaxFunctionSize(50), 342 InliningMode(NoRedundancy), 343 CXXMemberInliningMode() {} 344 345}; 346 347typedef IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef; 348 349} 350 351#endif 352