1 //===--- AnalyzerOptions.h - Analysis Engine Options ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header defines various options for the static analyzer that are set
11 // by the frontend and are consulted throughout the analyzer.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H
16 #define LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H
18 #include "clang/Basic/LLVM.h"
19 #include "llvm/ADT/IntrusiveRefCntPtr.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/StringMap.h"
27 class DiagnosticsEngine;
35 /// Analysis - Set of available source code analyses.
37 #define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE) NAME,
38 #include "clang/StaticAnalyzer/Core/Analyses.def"
42 /// AnalysisStores - Set of available analysis store models.
44 #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) NAME##Model,
45 #include "clang/StaticAnalyzer/Core/Analyses.def"
49 /// AnalysisConstraints - Set of available constraint models.
50 enum AnalysisConstraints {
51 #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) NAME##Model,
52 #include "clang/StaticAnalyzer/Core/Analyses.def"
56 /// AnalysisDiagClients - Set of available diagnostic clients for rendering
58 enum AnalysisDiagClients {
59 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME,
60 #include "clang/StaticAnalyzer/Core/Analyses.def"
62 NUM_ANALYSIS_DIAG_CLIENTS
65 /// AnalysisPurgeModes - Set of available strategies for dead symbol removal.
66 enum AnalysisPurgeMode {
67 #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) NAME,
68 #include "clang/StaticAnalyzer/Core/Analyses.def"
72 /// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics.
73 enum AnalysisInliningMode {
74 #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME,
75 #include "clang/StaticAnalyzer/Core/Analyses.def"
79 /// \brief Describes the different kinds of C++ member functions which can be
80 /// considered for inlining by the analyzer.
82 /// These options are cumulative; enabling one kind of member function will
83 /// enable all kinds with lower enum values.
84 enum CXXInlineableMemberKind {
87 /// A dummy mode in which no C++ inlining is enabled.
90 /// Refers to regular member function and operator calls.
93 /// Refers to constructors (implicit or explicit).
95 /// Note that a constructor will not be inlined if the corresponding
96 /// destructor is non-trivial.
99 /// Refers to destructors (implicit or explicit).
103 /// \brief Describes the different modes of inter-procedural analysis.
107 /// Perform only intra-procedural analysis.
110 /// Inline C functions and blocks when their definitions are available.
111 IPAK_BasicInlining = 2,
113 /// Inline callees(C, C++, ObjC) when their definitions are available.
116 /// Enable inlining of dynamically dispatched methods.
117 IPAK_DynamicDispatch = 4,
119 /// Enable inlining of dynamically dispatched methods, bifurcate paths when
120 /// exact type info is unavailable.
121 IPAK_DynamicDispatchBifurcate = 5
124 class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
126 typedef llvm::StringMap<std::string> ConfigTable;
128 static std::vector<StringRef>
129 getRegisteredCheckers(bool IncludeExperimental = false);
131 /// \brief Pair of checker name and enable/disable.
132 std::vector<std::pair<std::string, bool> > CheckersControlList;
134 /// \brief A key-value table of use-specified configuration values.
136 AnalysisStores AnalysisStoreOpt;
137 AnalysisConstraints AnalysisConstraintsOpt;
138 AnalysisDiagClients AnalysisDiagOpt;
139 AnalysisPurgeMode AnalysisPurgeOpt;
141 std::string AnalyzeSpecificFunction;
143 /// \brief The maximum number of times the analyzer visits a block.
144 unsigned maxBlockVisitOnPath;
147 /// \brief Disable all analyzer checks.
149 /// This flag allows one to disable analyzer checks on the code processed by
150 /// the given analysis consumer. Note, the code will get parsed and the
151 /// command-line options will get checked.
152 unsigned DisableAllChecks : 1;
154 unsigned ShowCheckerHelp : 1;
155 unsigned ShowEnabledCheckerList : 1;
156 unsigned AnalyzeAll : 1;
157 unsigned AnalyzerDisplayProgress : 1;
158 unsigned AnalyzeNestedBlocks : 1;
160 /// \brief The flag regulates if we should eagerly assume evaluations of
161 /// conditionals, thus, bifurcating the path.
163 /// This flag indicates how the engine should handle expressions such as: 'x =
164 /// (y != 0)'. When this flag is true then the subexpression 'y != 0' will be
165 /// eagerly assumed to be true or false, thus evaluating it to the integers 0
166 /// or 1 respectively. The upside is that this can increase analysis
167 /// precision until we have a better way to lazily evaluate such logic. The
168 /// downside is that it eagerly bifurcates paths.
169 unsigned eagerlyAssumeBinOpBifurcation : 1;
171 unsigned TrimGraph : 1;
172 unsigned visualizeExplodedGraphWithGraphViz : 1;
173 unsigned visualizeExplodedGraphWithUbiGraph : 1;
174 unsigned UnoptimizedCFG : 1;
175 unsigned PrintStats : 1;
177 /// \brief Do not re-analyze paths leading to exhausted nodes with a different
178 /// strategy. We get better code coverage when retry is enabled.
179 unsigned NoRetryExhausted : 1;
181 /// \brief The inlining stack depth limit.
182 unsigned InlineMaxStackDepth;
184 /// \brief The mode of function selection used during inlining.
185 AnalysisInliningMode InliningMode;
188 /// \brief Describes the kinds for high-level analyzer mode.
191 /// Perform shallow but fast analyzes.
193 /// Perform deep analyzes.
197 /// Controls the high-level analyzer mode, which influences the default
198 /// settings for some of the lower-level config options (such as IPAMode).
200 UserModeKind UserMode;
202 /// Controls the mode of inter-procedural analysis.
205 /// Controls which C++ member functions will be considered for inlining.
206 CXXInlineableMemberKind CXXMemberInliningMode;
208 /// \sa includeTemporaryDtorsInCFG
209 Optional<bool> IncludeTemporaryDtorsInCFG;
211 /// \sa mayInlineCXXStandardLibrary
212 Optional<bool> InlineCXXStandardLibrary;
214 /// \sa mayInlineTemplateFunctions
215 Optional<bool> InlineTemplateFunctions;
217 /// \sa mayInlineCXXAllocator
218 Optional<bool> InlineCXXAllocator;
220 /// \sa mayInlineCXXContainerMethods
221 Optional<bool> InlineCXXContainerMethods;
223 /// \sa mayInlineCXXSharedPtrDtor
224 Optional<bool> InlineCXXSharedPtrDtor;
226 /// \sa mayInlineObjCMethod
227 Optional<bool> ObjCInliningMode;
229 // Cache of the "ipa-always-inline-size" setting.
230 // \sa getAlwaysInlineSize
231 Optional<unsigned> AlwaysInlineSize;
233 /// \sa shouldSuppressNullReturnPaths
234 Optional<bool> SuppressNullReturnPaths;
236 // \sa getMaxInlinableSize
237 Optional<unsigned> MaxInlinableSize;
239 /// \sa shouldAvoidSuppressingNullArgumentPaths
240 Optional<bool> AvoidSuppressingNullArgumentPaths;
242 /// \sa shouldSuppressInlinedDefensiveChecks
243 Optional<bool> SuppressInlinedDefensiveChecks;
245 /// \sa shouldSuppressFromCXXStandardLibrary
246 Optional<bool> SuppressFromCXXStandardLibrary;
248 /// \sa reportIssuesInMainSourceFile
249 Optional<bool> ReportIssuesInMainSourceFile;
251 /// \sa StableReportFilename
252 Optional<bool> StableReportFilename;
254 /// \sa getGraphTrimInterval
255 Optional<unsigned> GraphTrimInterval;
257 /// \sa getMaxTimesInlineLarge
258 Optional<unsigned> MaxTimesInlineLarge;
260 /// \sa getMinCFGSizeTreatFunctionsAsLarge
261 Optional<unsigned> MinCFGSizeTreatFunctionsAsLarge;
263 /// \sa getMaxNodesPerTopLevelFunction
264 Optional<unsigned> MaxNodesPerTopLevelFunction;
266 /// \sa shouldInlineLambdas
267 Optional<bool> InlineLambdas;
269 /// \sa shouldWidenLoops
270 Optional<bool> WidenLoops;
272 /// \sa shouldDisplayNotesAsEvents
273 Optional<bool> DisplayNotesAsEvents;
275 /// A helper function that retrieves option for a given full-qualified
277 /// Options for checkers can be specified via 'analyzer-config' command-line
280 /// @code-analyzer-config unix.Malloc:OptionName=CheckerOptionValue @endcode
281 /// or @code-analyzer-config unix:OptionName=GroupOptionValue @endcode
282 /// for groups of checkers.
283 /// @param [in] CheckerName Full-qualified checker name, like
284 /// alpha.unix.StreamChecker.
285 /// @param [in] OptionName Name of the option to get.
286 /// @param [in] Default Default value if no option is specified.
287 /// @param [in] SearchInParents If set to true and the searched option was not
288 /// specified for the given checker the options for the parent packages will
289 /// be searched as well. The inner packages take precedence over the outer
291 /// @retval CheckerOptionValue An option for a checker if it was specified.
292 /// @retval GroupOptionValue An option for group if it was specified and no
293 /// checker-specific options were found. The closer group to checker,
294 /// the more priority it has. For example, @c coregroup.subgroup has more
295 /// priority than @c coregroup for @c coregroup.subgroup.CheckerName checker.
296 /// @retval Default If nor checker option, nor group option was found.
297 StringRef getCheckerOption(StringRef CheckerName, StringRef OptionName,
299 bool SearchInParents = false);
302 /// Interprets an option's string value as a boolean. The "true" string is
303 /// interpreted as true and the "false" string is interpreted as false.
305 /// If an option value is not provided, returns the given \p DefaultVal.
306 /// @param [in] Name Name for option to retrieve.
307 /// @param [in] DefaultVal Default value returned if no such option was
309 /// @param [in] C The optional checker parameter that can be used to restrict
310 /// the search to the options of this particular checker (and its parents
311 /// dependening on search mode).
312 /// @param [in] SearchInParents If set to true and the searched option was not
313 /// specified for the given checker the options for the parent packages will
314 /// be searched as well. The inner packages take precedence over the outer
316 bool getBooleanOption(StringRef Name, bool DefaultVal,
317 const ento::CheckerBase *C = nullptr,
318 bool SearchInParents = false);
320 /// Variant that accepts a Optional value to cache the result.
322 /// @param [in,out] V Return value storage, returned if parameter contains
323 /// an existing valid option, else it is used to store a return value
324 /// @param [in] Name Name for option to retrieve.
325 /// @param [in] DefaultVal Default value returned if no such option was
327 /// @param [in] C The optional checker parameter that can be used to restrict
328 /// the search to the options of this particular checker (and its parents
329 /// dependening on search mode).
330 /// @param [in] SearchInParents If set to true and the searched option was not
331 /// specified for the given checker the options for the parent packages will
332 /// be searched as well. The inner packages take precedence over the outer
334 bool getBooleanOption(Optional<bool> &V, StringRef Name, bool DefaultVal,
335 const ento::CheckerBase *C = nullptr,
336 bool SearchInParents = false);
338 /// Interprets an option's string value as an integer value.
340 /// If an option value is not provided, returns the given \p DefaultVal.
341 /// @param [in] Name Name for option to retrieve.
342 /// @param [in] DefaultVal Default value returned if no such option was
344 /// @param [in] C The optional checker parameter that can be used to restrict
345 /// the search to the options of this particular checker (and its parents
346 /// dependening on search mode).
347 /// @param [in] SearchInParents If set to true and the searched option was not
348 /// specified for the given checker the options for the parent packages will
349 /// be searched as well. The inner packages take precedence over the outer
351 int getOptionAsInteger(StringRef Name, int DefaultVal,
352 const ento::CheckerBase *C = nullptr,
353 bool SearchInParents = false);
355 /// Query an option's string value.
357 /// If an option value is not provided, returns the given \p DefaultVal.
358 /// @param [in] Name Name for option to retrieve.
359 /// @param [in] DefaultVal Default value returned if no such option was
361 /// @param [in] C The optional checker parameter that can be used to restrict
362 /// the search to the options of this particular checker (and its parents
363 /// dependening on search mode).
364 /// @param [in] SearchInParents If set to true and the searched option was not
365 /// specified for the given checker the options for the parent packages will
366 /// be searched as well. The inner packages take precedence over the outer
368 StringRef getOptionAsString(StringRef Name, StringRef DefaultVal,
369 const ento::CheckerBase *C = nullptr,
370 bool SearchInParents = false);
372 /// \brief Retrieves and sets the UserMode. This is a high-level option,
373 /// which is used to set other low-level options. It is not accessible
374 /// outside of AnalyzerOptions.
375 UserModeKind getUserMode();
377 /// \brief Returns the inter-procedural analysis mode.
378 IPAKind getIPAMode();
380 /// Returns the option controlling which C++ member functions will be
381 /// considered for inlining.
383 /// This is controlled by the 'c++-inlining' config option.
385 /// \sa CXXMemberInliningMode
386 bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K);
388 /// Returns true if ObjectiveC inlining is enabled, false otherwise.
389 bool mayInlineObjCMethod();
391 /// Returns whether or not the destructors for C++ temporary objects should
392 /// be included in the CFG.
394 /// This is controlled by the 'cfg-temporary-dtors' config option, which
395 /// accepts the values "true" and "false".
396 bool includeTemporaryDtorsInCFG();
398 /// Returns whether or not C++ standard library functions may be considered
401 /// This is controlled by the 'c++-stdlib-inlining' config option, which
402 /// accepts the values "true" and "false".
403 bool mayInlineCXXStandardLibrary();
405 /// Returns whether or not templated functions may be considered for inlining.
407 /// This is controlled by the 'c++-template-inlining' config option, which
408 /// accepts the values "true" and "false".
409 bool mayInlineTemplateFunctions();
411 /// Returns whether or not allocator call may be considered for inlining.
413 /// This is controlled by the 'c++-allocator-inlining' config option, which
414 /// accepts the values "true" and "false".
415 bool mayInlineCXXAllocator();
417 /// Returns whether or not methods of C++ container objects may be considered
420 /// This is controlled by the 'c++-container-inlining' config option, which
421 /// accepts the values "true" and "false".
422 bool mayInlineCXXContainerMethods();
424 /// Returns whether or not the destructor of C++ 'shared_ptr' may be
425 /// considered for inlining.
427 /// This covers std::shared_ptr, std::tr1::shared_ptr, and boost::shared_ptr,
428 /// and indeed any destructor named "~shared_ptr".
430 /// This is controlled by the 'c++-shared_ptr-inlining' config option, which
431 /// accepts the values "true" and "false".
432 bool mayInlineCXXSharedPtrDtor();
434 /// Returns whether or not paths that go through null returns should be
437 /// This is a heuristic for avoiding bug reports with paths that go through
438 /// inlined functions that are more defensive than their callers.
440 /// This is controlled by the 'suppress-null-return-paths' config option,
441 /// which accepts the values "true" and "false".
442 bool shouldSuppressNullReturnPaths();
444 /// Returns whether a bug report should \em not be suppressed if its path
445 /// includes a call with a null argument, even if that call has a null return.
447 /// This option has no effect when #shouldSuppressNullReturnPaths() is false.
449 /// This is a counter-heuristic to avoid false negatives.
451 /// This is controlled by the 'avoid-suppressing-null-argument-paths' config
452 /// option, which accepts the values "true" and "false".
453 bool shouldAvoidSuppressingNullArgumentPaths();
455 /// Returns whether or not diagnostics containing inlined defensive NULL
456 /// checks should be suppressed.
458 /// This is controlled by the 'suppress-inlined-defensive-checks' config
459 /// option, which accepts the values "true" and "false".
460 bool shouldSuppressInlinedDefensiveChecks();
462 /// Returns whether or not diagnostics reported within the C++ standard
463 /// library should be suppressed.
465 /// This is controlled by the 'suppress-c++-stdlib' config option,
466 /// which accepts the values "true" and "false".
467 bool shouldSuppressFromCXXStandardLibrary();
469 /// Returns whether or not the diagnostic report should be always reported
470 /// in the main source file and not the headers.
472 /// This is controlled by the 'report-in-main-source-file' config option,
473 /// which accepts the values "true" and "false".
474 bool shouldReportIssuesInMainSourceFile();
476 /// Returns whether or not the report filename should be random or not.
478 /// This is controlled by the 'stable-report-filename' config option,
479 /// which accepts the values "true" and "false". Default = false
480 bool shouldWriteStableReportFilename();
482 /// Returns whether irrelevant parts of a bug report path should be pruned
483 /// out of the final output.
485 /// This is controlled by the 'prune-paths' config option, which accepts the
486 /// values "true" and "false".
487 bool shouldPrunePaths();
489 /// Returns true if 'static' initializers should be in conditional logic
491 bool shouldConditionalizeStaticInitializers();
493 // Returns the size of the functions (in basic blocks), which should be
494 // considered to be small enough to always inline.
496 // This is controlled by "ipa-always-inline-size" analyzer-config option.
497 unsigned getAlwaysInlineSize();
499 // Returns the bound on the number of basic blocks in an inlined function
502 // This is controlled by "-analyzer-config max-inlinable-size" option.
503 unsigned getMaxInlinableSize();
505 /// Returns true if the analyzer engine should synthesize fake bodies
506 /// for well-known functions.
507 bool shouldSynthesizeBodies();
509 /// Returns how often nodes in the ExplodedGraph should be recycled to save
512 /// This is controlled by the 'graph-trim-interval' config option. To disable
513 /// node reclamation, set the option to "0".
514 unsigned getGraphTrimInterval();
516 /// Returns the maximum times a large function could be inlined.
518 /// This is controlled by the 'max-times-inline-large' config option.
519 unsigned getMaxTimesInlineLarge();
521 /// Returns the number of basic blocks a function needs to have to be
522 /// considered large for the 'max-times-inline-large' config option.
524 /// This is controlled by the 'min-cfg-size-treat-functions-as-large' config
526 unsigned getMinCFGSizeTreatFunctionsAsLarge();
528 /// Returns the maximum number of nodes the analyzer can generate while
529 /// exploring a top level function (for each exploded graph).
530 /// 150000 is default; 0 means no limit.
532 /// This is controlled by the 'max-nodes' config option.
533 unsigned getMaxNodesPerTopLevelFunction();
535 /// Returns true if lambdas should be inlined. Otherwise a sink node will be
536 /// generated each time a LambdaExpr is visited.
537 bool shouldInlineLambdas();
539 /// Returns true if the analysis should try to widen loops.
540 /// This is controlled by the 'widen-loops' config option.
541 bool shouldWidenLoops();
543 /// Returns true if the bug reporter should transparently treat extra note
544 /// diagnostic pieces as event diagnostic pieces. Useful when the diagnostic
545 /// consumer doesn't support the extra note pieces.
547 /// This is controlled by the 'extra-notes-as-events' option, which defaults
548 /// to false when unset.
549 bool shouldDisplayNotesAsEvents();
553 AnalysisStoreOpt(RegionStoreModel),
554 AnalysisConstraintsOpt(RangeConstraintsModel),
555 AnalysisDiagOpt(PD_HTML),
556 AnalysisPurgeOpt(PurgeStmt),
559 ShowEnabledCheckerList(0),
561 AnalyzerDisplayProgress(0),
562 AnalyzeNestedBlocks(0),
563 eagerlyAssumeBinOpBifurcation(0),
565 visualizeExplodedGraphWithGraphViz(0),
566 visualizeExplodedGraphWithUbiGraph(0),
570 // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
571 InlineMaxStackDepth(5),
572 InliningMode(NoRedundancy),
573 UserMode(UMK_NotSet),
574 IPAMode(IPAK_NotSet),
575 CXXMemberInliningMode() {}
579 typedef IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef;