clang API Documentation
00001 //===--- AnalyzerOptions.h - Analysis Engine Options ------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This header defines various options for the static analyzer that are set 00011 // by the frontend and are consulted throughout the analyzer. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H 00016 #define LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H 00017 00018 #include "clang/Basic/LLVM.h" 00019 #include "llvm/ADT/IntrusiveRefCntPtr.h" 00020 #include "llvm/ADT/Optional.h" 00021 #include "llvm/ADT/StringMap.h" 00022 #include <string> 00023 #include <vector> 00024 00025 namespace clang { 00026 class ASTConsumer; 00027 class DiagnosticsEngine; 00028 class Preprocessor; 00029 class LangOptions; 00030 00031 /// Analysis - Set of available source code analyses. 00032 enum Analyses { 00033 #define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE) NAME, 00034 #include "clang/StaticAnalyzer/Core/Analyses.def" 00035 NumAnalyses 00036 }; 00037 00038 /// AnalysisStores - Set of available analysis store models. 00039 enum AnalysisStores { 00040 #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) NAME##Model, 00041 #include "clang/StaticAnalyzer/Core/Analyses.def" 00042 NumStores 00043 }; 00044 00045 /// AnalysisConstraints - Set of available constraint models. 00046 enum AnalysisConstraints { 00047 #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) NAME##Model, 00048 #include "clang/StaticAnalyzer/Core/Analyses.def" 00049 NumConstraints 00050 }; 00051 00052 /// AnalysisDiagClients - Set of available diagnostic clients for rendering 00053 /// analysis results. 00054 enum AnalysisDiagClients { 00055 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME, 00056 #include "clang/StaticAnalyzer/Core/Analyses.def" 00057 PD_NONE, 00058 NUM_ANALYSIS_DIAG_CLIENTS 00059 }; 00060 00061 /// AnalysisPurgeModes - Set of available strategies for dead symbol removal. 00062 enum AnalysisPurgeMode { 00063 #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) NAME, 00064 #include "clang/StaticAnalyzer/Core/Analyses.def" 00065 NumPurgeModes 00066 }; 00067 00068 /// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics. 00069 enum AnalysisInliningMode { 00070 #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME, 00071 #include "clang/StaticAnalyzer/Core/Analyses.def" 00072 NumInliningModes 00073 }; 00074 00075 /// \brief Describes the different kinds of C++ member functions which can be 00076 /// considered for inlining by the analyzer. 00077 /// 00078 /// These options are cumulative; enabling one kind of member function will 00079 /// enable all kinds with lower enum values. 00080 enum CXXInlineableMemberKind { 00081 // Uninitialized = 0, 00082 00083 /// A dummy mode in which no C++ inlining is enabled. 00084 CIMK_None = 1, 00085 00086 /// Refers to regular member function and operator calls. 00087 CIMK_MemberFunctions, 00088 00089 /// Refers to constructors (implicit or explicit). 00090 /// 00091 /// Note that a constructor will not be inlined if the corresponding 00092 /// destructor is non-trivial. 00093 CIMK_Constructors, 00094 00095 /// Refers to destructors (implicit or explicit). 00096 CIMK_Destructors 00097 }; 00098 00099 /// \brief Describes the different modes of inter-procedural analysis. 00100 enum IPAKind { 00101 IPAK_NotSet = 0, 00102 00103 /// Perform only intra-procedural analysis. 00104 IPAK_None = 1, 00105 00106 /// Inline C functions and blocks when their definitions are available. 00107 IPAK_BasicInlining = 2, 00108 00109 /// Inline callees(C, C++, ObjC) when their definitions are available. 00110 IPAK_Inlining = 3, 00111 00112 /// Enable inlining of dynamically dispatched methods. 00113 IPAK_DynamicDispatch = 4, 00114 00115 /// Enable inlining of dynamically dispatched methods, bifurcate paths when 00116 /// exact type info is unavailable. 00117 IPAK_DynamicDispatchBifurcate = 5 00118 }; 00119 00120 class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> { 00121 public: 00122 typedef llvm::StringMap<std::string> ConfigTable; 00123 00124 /// \brief Pair of checker name and enable/disable. 00125 std::vector<std::pair<std::string, bool> > CheckersControlList; 00126 00127 /// \brief A key-value table of use-specified configuration values. 00128 ConfigTable Config; 00129 AnalysisStores AnalysisStoreOpt; 00130 AnalysisConstraints AnalysisConstraintsOpt; 00131 AnalysisDiagClients AnalysisDiagOpt; 00132 AnalysisPurgeMode AnalysisPurgeOpt; 00133 00134 std::string AnalyzeSpecificFunction; 00135 00136 /// \brief The maximum number of times the analyzer visits a block. 00137 unsigned maxBlockVisitOnPath; 00138 00139 00140 /// \brief Disable all analyzer checks. 00141 /// 00142 /// This flag allows one to disable analyzer checks on the code processed by 00143 /// the given analysis consumer. Note, the code will get parsed and the 00144 /// command-line options will get checked. 00145 unsigned DisableAllChecks : 1; 00146 00147 unsigned ShowCheckerHelp : 1; 00148 unsigned AnalyzeAll : 1; 00149 unsigned AnalyzerDisplayProgress : 1; 00150 unsigned AnalyzeNestedBlocks : 1; 00151 00152 /// \brief The flag regulates if we should eagerly assume evaluations of 00153 /// conditionals, thus, bifurcating the path. 00154 /// 00155 /// This flag indicates how the engine should handle expressions such as: 'x = 00156 /// (y != 0)'. When this flag is true then the subexpression 'y != 0' will be 00157 /// eagerly assumed to be true or false, thus evaluating it to the integers 0 00158 /// or 1 respectively. The upside is that this can increase analysis 00159 /// precision until we have a better way to lazily evaluate such logic. The 00160 /// downside is that it eagerly bifurcates paths. 00161 unsigned eagerlyAssumeBinOpBifurcation : 1; 00162 00163 unsigned TrimGraph : 1; 00164 unsigned visualizeExplodedGraphWithGraphViz : 1; 00165 unsigned visualizeExplodedGraphWithUbiGraph : 1; 00166 unsigned UnoptimizedCFG : 1; 00167 unsigned PrintStats : 1; 00168 00169 /// \brief Do not re-analyze paths leading to exhausted nodes with a different 00170 /// strategy. We get better code coverage when retry is enabled. 00171 unsigned NoRetryExhausted : 1; 00172 00173 /// \brief The inlining stack depth limit. 00174 unsigned InlineMaxStackDepth; 00175 00176 /// \brief The mode of function selection used during inlining. 00177 AnalysisInliningMode InliningMode; 00178 00179 private: 00180 /// \brief Describes the kinds for high-level analyzer mode. 00181 enum UserModeKind { 00182 UMK_NotSet = 0, 00183 /// Perform shallow but fast analyzes. 00184 UMK_Shallow = 1, 00185 /// Perform deep analyzes. 00186 UMK_Deep = 2 00187 }; 00188 00189 /// Controls the high-level analyzer mode, which influences the default 00190 /// settings for some of the lower-level config options (such as IPAMode). 00191 /// \sa getUserMode 00192 UserModeKind UserMode; 00193 00194 /// Controls the mode of inter-procedural analysis. 00195 IPAKind IPAMode; 00196 00197 /// Controls which C++ member functions will be considered for inlining. 00198 CXXInlineableMemberKind CXXMemberInliningMode; 00199 00200 /// \sa includeTemporaryDtorsInCFG 00201 Optional<bool> IncludeTemporaryDtorsInCFG; 00202 00203 /// \sa mayInlineCXXStandardLibrary 00204 Optional<bool> InlineCXXStandardLibrary; 00205 00206 /// \sa mayInlineTemplateFunctions 00207 Optional<bool> InlineTemplateFunctions; 00208 00209 /// \sa mayInlineCXXAllocator 00210 Optional<bool> InlineCXXAllocator; 00211 00212 /// \sa mayInlineCXXContainerMethods 00213 Optional<bool> InlineCXXContainerMethods; 00214 00215 /// \sa mayInlineCXXSharedPtrDtor 00216 Optional<bool> InlineCXXSharedPtrDtor; 00217 00218 /// \sa mayInlineObjCMethod 00219 Optional<bool> ObjCInliningMode; 00220 00221 // Cache of the "ipa-always-inline-size" setting. 00222 // \sa getAlwaysInlineSize 00223 Optional<unsigned> AlwaysInlineSize; 00224 00225 /// \sa shouldSuppressNullReturnPaths 00226 Optional<bool> SuppressNullReturnPaths; 00227 00228 // \sa getMaxInlinableSize 00229 Optional<unsigned> MaxInlinableSize; 00230 00231 /// \sa shouldAvoidSuppressingNullArgumentPaths 00232 Optional<bool> AvoidSuppressingNullArgumentPaths; 00233 00234 /// \sa shouldSuppressInlinedDefensiveChecks 00235 Optional<bool> SuppressInlinedDefensiveChecks; 00236 00237 /// \sa shouldSuppressFromCXXStandardLibrary 00238 Optional<bool> SuppressFromCXXStandardLibrary; 00239 00240 /// \sa reportIssuesInMainSourceFile 00241 Optional<bool> ReportIssuesInMainSourceFile; 00242 00243 /// \sa StableReportFilename 00244 Optional<bool> StableReportFilename; 00245 00246 /// \sa getGraphTrimInterval 00247 Optional<unsigned> GraphTrimInterval; 00248 00249 /// \sa getMaxTimesInlineLarge 00250 Optional<unsigned> MaxTimesInlineLarge; 00251 00252 /// \sa getMaxNodesPerTopLevelFunction 00253 Optional<unsigned> MaxNodesPerTopLevelFunction; 00254 00255 public: 00256 /// Interprets an option's string value as a boolean. 00257 /// 00258 /// Accepts the strings "true" and "false". 00259 /// If an option value is not provided, returns the given \p DefaultVal. 00260 bool getBooleanOption(StringRef Name, bool DefaultVal); 00261 00262 /// Variant that accepts a Optional value to cache the result. 00263 bool getBooleanOption(Optional<bool> &V, StringRef Name, bool DefaultVal); 00264 00265 /// Interprets an option's string value as an integer value. 00266 int getOptionAsInteger(StringRef Name, int DefaultVal); 00267 00268 /// \brief Retrieves and sets the UserMode. This is a high-level option, 00269 /// which is used to set other low-level options. It is not accessible 00270 /// outside of AnalyzerOptions. 00271 UserModeKind getUserMode(); 00272 00273 /// \brief Returns the inter-procedural analysis mode. 00274 IPAKind getIPAMode(); 00275 00276 /// Returns the option controlling which C++ member functions will be 00277 /// considered for inlining. 00278 /// 00279 /// This is controlled by the 'c++-inlining' config option. 00280 /// 00281 /// \sa CXXMemberInliningMode 00282 bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K); 00283 00284 /// Returns true if ObjectiveC inlining is enabled, false otherwise. 00285 bool mayInlineObjCMethod(); 00286 00287 /// Returns whether or not the destructors for C++ temporary objects should 00288 /// be included in the CFG. 00289 /// 00290 /// This is controlled by the 'cfg-temporary-dtors' config option, which 00291 /// accepts the values "true" and "false". 00292 bool includeTemporaryDtorsInCFG(); 00293 00294 /// Returns whether or not C++ standard library functions may be considered 00295 /// for inlining. 00296 /// 00297 /// This is controlled by the 'c++-stdlib-inlining' config option, which 00298 /// accepts the values "true" and "false". 00299 bool mayInlineCXXStandardLibrary(); 00300 00301 /// Returns whether or not templated functions may be considered for inlining. 00302 /// 00303 /// This is controlled by the 'c++-template-inlining' config option, which 00304 /// accepts the values "true" and "false". 00305 bool mayInlineTemplateFunctions(); 00306 00307 /// Returns whether or not allocator call may be considered for inlining. 00308 /// 00309 /// This is controlled by the 'c++-allocator-inlining' config option, which 00310 /// accepts the values "true" and "false". 00311 bool mayInlineCXXAllocator(); 00312 00313 /// Returns whether or not methods of C++ container objects may be considered 00314 /// for inlining. 00315 /// 00316 /// This is controlled by the 'c++-container-inlining' config option, which 00317 /// accepts the values "true" and "false". 00318 bool mayInlineCXXContainerMethods(); 00319 00320 /// Returns whether or not the destructor of C++ 'shared_ptr' may be 00321 /// considered for inlining. 00322 /// 00323 /// This covers std::shared_ptr, std::tr1::shared_ptr, and boost::shared_ptr, 00324 /// and indeed any destructor named "~shared_ptr". 00325 /// 00326 /// This is controlled by the 'c++-shared_ptr-inlining' config option, which 00327 /// accepts the values "true" and "false". 00328 bool mayInlineCXXSharedPtrDtor(); 00329 00330 /// Returns whether or not paths that go through null returns should be 00331 /// suppressed. 00332 /// 00333 /// This is a heuristic for avoiding bug reports with paths that go through 00334 /// inlined functions that are more defensive than their callers. 00335 /// 00336 /// This is controlled by the 'suppress-null-return-paths' config option, 00337 /// which accepts the values "true" and "false". 00338 bool shouldSuppressNullReturnPaths(); 00339 00340 /// Returns whether a bug report should \em not be suppressed if its path 00341 /// includes a call with a null argument, even if that call has a null return. 00342 /// 00343 /// This option has no effect when #shouldSuppressNullReturnPaths() is false. 00344 /// 00345 /// This is a counter-heuristic to avoid false negatives. 00346 /// 00347 /// This is controlled by the 'avoid-suppressing-null-argument-paths' config 00348 /// option, which accepts the values "true" and "false". 00349 bool shouldAvoidSuppressingNullArgumentPaths(); 00350 00351 /// Returns whether or not diagnostics containing inlined defensive NULL 00352 /// checks should be suppressed. 00353 /// 00354 /// This is controlled by the 'suppress-inlined-defensive-checks' config 00355 /// option, which accepts the values "true" and "false". 00356 bool shouldSuppressInlinedDefensiveChecks(); 00357 00358 /// Returns whether or not diagnostics reported within the C++ standard 00359 /// library should be suppressed. 00360 /// 00361 /// This is controlled by the 'suppress-c++-stdlib' config option, 00362 /// which accepts the values "true" and "false". 00363 bool shouldSuppressFromCXXStandardLibrary(); 00364 00365 /// Returns whether or not the diagnostic report should be always reported 00366 /// in the main source file and not the headers. 00367 /// 00368 /// This is controlled by the 'report-in-main-source-file' config option, 00369 /// which accepts the values "true" and "false". 00370 bool shouldReportIssuesInMainSourceFile(); 00371 00372 /// Returns whether or not the report filename should be random or not. 00373 /// 00374 /// This is controlled by the 'stable-report-filename' config option, 00375 /// which accepts the values "true" and "false". Default = false 00376 bool shouldWriteStableReportFilename(); 00377 00378 /// Returns whether irrelevant parts of a bug report path should be pruned 00379 /// out of the final output. 00380 /// 00381 /// This is controlled by the 'prune-paths' config option, which accepts the 00382 /// values "true" and "false". 00383 bool shouldPrunePaths(); 00384 00385 /// Returns true if 'static' initializers should be in conditional logic 00386 /// in the CFG. 00387 bool shouldConditionalizeStaticInitializers(); 00388 00389 // Returns the size of the functions (in basic blocks), which should be 00390 // considered to be small enough to always inline. 00391 // 00392 // This is controlled by "ipa-always-inline-size" analyzer-config option. 00393 unsigned getAlwaysInlineSize(); 00394 00395 // Returns the bound on the number of basic blocks in an inlined function 00396 // (50 by default). 00397 // 00398 // This is controlled by "-analyzer-config max-inlinable-size" option. 00399 unsigned getMaxInlinableSize(); 00400 00401 /// Returns true if the analyzer engine should synthesize fake bodies 00402 /// for well-known functions. 00403 bool shouldSynthesizeBodies(); 00404 00405 /// Returns how often nodes in the ExplodedGraph should be recycled to save 00406 /// memory. 00407 /// 00408 /// This is controlled by the 'graph-trim-interval' config option. To disable 00409 /// node reclamation, set the option to "0". 00410 unsigned getGraphTrimInterval(); 00411 00412 /// Returns the maximum times a large function could be inlined. 00413 /// 00414 /// This is controlled by the 'max-times-inline-large' config option. 00415 unsigned getMaxTimesInlineLarge(); 00416 00417 /// Returns the maximum number of nodes the analyzer can generate while 00418 /// exploring a top level function (for each exploded graph). 00419 /// 150000 is default; 0 means no limit. 00420 /// 00421 /// This is controlled by the 'max-nodes' config option. 00422 unsigned getMaxNodesPerTopLevelFunction(); 00423 00424 public: 00425 AnalyzerOptions() : 00426 AnalysisStoreOpt(RegionStoreModel), 00427 AnalysisConstraintsOpt(RangeConstraintsModel), 00428 AnalysisDiagOpt(PD_HTML), 00429 AnalysisPurgeOpt(PurgeStmt), 00430 DisableAllChecks(0), 00431 ShowCheckerHelp(0), 00432 AnalyzeAll(0), 00433 AnalyzerDisplayProgress(0), 00434 AnalyzeNestedBlocks(0), 00435 eagerlyAssumeBinOpBifurcation(0), 00436 TrimGraph(0), 00437 visualizeExplodedGraphWithGraphViz(0), 00438 visualizeExplodedGraphWithUbiGraph(0), 00439 UnoptimizedCFG(0), 00440 PrintStats(0), 00441 NoRetryExhausted(0), 00442 // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls). 00443 InlineMaxStackDepth(5), 00444 InliningMode(NoRedundancy), 00445 UserMode(UMK_NotSet), 00446 IPAMode(IPAK_NotSet), 00447 CXXMemberInliningMode() {} 00448 00449 }; 00450 00451 typedef IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef; 00452 00453 } 00454 00455 #endif