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;
31 /// Analysis - Set of available source code analyses.
33 #define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE) NAME,
34 #include "clang/StaticAnalyzer/Core/Analyses.def"
38 /// AnalysisStores - Set of available analysis store models.
40 #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) NAME##Model,
41 #include "clang/StaticAnalyzer/Core/Analyses.def"
45 /// AnalysisConstraints - Set of available constraint models.
46 enum AnalysisConstraints {
47 #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) NAME##Model,
48 #include "clang/StaticAnalyzer/Core/Analyses.def"
52 /// AnalysisDiagClients - Set of available diagnostic clients for rendering
54 enum AnalysisDiagClients {
55 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME,
56 #include "clang/StaticAnalyzer/Core/Analyses.def"
58 NUM_ANALYSIS_DIAG_CLIENTS
61 /// AnalysisPurgeModes - Set of available strategies for dead symbol removal.
62 enum AnalysisPurgeMode {
63 #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) NAME,
64 #include "clang/StaticAnalyzer/Core/Analyses.def"
68 /// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics.
69 enum AnalysisInliningMode {
70 #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME,
71 #include "clang/StaticAnalyzer/Core/Analyses.def"
75 /// \brief Describes the different kinds of C++ member functions which can be
76 /// considered for inlining by the analyzer.
78 /// These options are cumulative; enabling one kind of member function will
79 /// enable all kinds with lower enum values.
80 enum CXXInlineableMemberKind {
83 /// A dummy mode in which no C++ inlining is enabled.
86 /// Refers to regular member function and operator calls.
89 /// Refers to constructors (implicit or explicit).
91 /// Note that a constructor will not be inlined if the corresponding
92 /// destructor is non-trivial.
95 /// Refers to destructors (implicit or explicit).
99 /// \brief Describes the different modes of inter-procedural analysis.
103 /// Perform only intra-procedural analysis.
106 /// Inline C functions and blocks when their definitions are available.
107 IPAK_BasicInlining = 2,
109 /// Inline callees(C, C++, ObjC) when their definitions are available.
112 /// Enable inlining of dynamically dispatched methods.
113 IPAK_DynamicDispatch = 4,
115 /// Enable inlining of dynamically dispatched methods, bifurcate paths when
116 /// exact type info is unavailable.
117 IPAK_DynamicDispatchBifurcate = 5
120 class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
122 typedef llvm::StringMap<std::string> ConfigTable;
124 /// \brief Pair of checker name and enable/disable.
125 std::vector<std::pair<std::string, bool> > CheckersControlList;
127 /// \brief A key-value table of use-specified configuration values.
129 AnalysisStores AnalysisStoreOpt;
130 AnalysisConstraints AnalysisConstraintsOpt;
131 AnalysisDiagClients AnalysisDiagOpt;
132 AnalysisPurgeMode AnalysisPurgeOpt;
134 std::string AnalyzeSpecificFunction;
136 /// \brief The maximum number of times the analyzer visits a block.
137 unsigned maxBlockVisitOnPath;
140 /// \brief Disable all analyzer checks.
142 /// This flag allows one to disable analyzer checks on the code processed by
143 /// the given analysis consumer. Note, the code will get parsed and the
144 /// command-line options will get checked.
145 unsigned DisableAllChecks : 1;
147 unsigned ShowCheckerHelp : 1;
148 unsigned AnalyzeAll : 1;
149 unsigned AnalyzerDisplayProgress : 1;
150 unsigned AnalyzeNestedBlocks : 1;
152 /// \brief The flag regulates if we should eagerly assume evaluations of
153 /// conditionals, thus, bifurcating the path.
155 /// This flag indicates how the engine should handle expressions such as: 'x =
156 /// (y != 0)'. When this flag is true then the subexpression 'y != 0' will be
157 /// eagerly assumed to be true or false, thus evaluating it to the integers 0
158 /// or 1 respectively. The upside is that this can increase analysis
159 /// precision until we have a better way to lazily evaluate such logic. The
160 /// downside is that it eagerly bifurcates paths.
161 unsigned eagerlyAssumeBinOpBifurcation : 1;
163 unsigned TrimGraph : 1;
164 unsigned visualizeExplodedGraphWithGraphViz : 1;
165 unsigned visualizeExplodedGraphWithUbiGraph : 1;
166 unsigned UnoptimizedCFG : 1;
167 unsigned PrintStats : 1;
169 /// \brief Do not re-analyze paths leading to exhausted nodes with a different
170 /// strategy. We get better code coverage when retry is enabled.
171 unsigned NoRetryExhausted : 1;
173 /// \brief The inlining stack depth limit.
174 unsigned InlineMaxStackDepth;
176 /// \brief The mode of function selection used during inlining.
177 AnalysisInliningMode InliningMode;
180 /// \brief Describes the kinds for high-level analyzer mode.
183 /// Perform shallow but fast analyzes.
185 /// Perform deep analyzes.
189 /// Controls the high-level analyzer mode, which influences the default
190 /// settings for some of the lower-level config options (such as IPAMode).
192 UserModeKind UserMode;
194 /// Controls the mode of inter-procedural analysis.
197 /// Controls which C++ member functions will be considered for inlining.
198 CXXInlineableMemberKind CXXMemberInliningMode;
200 /// \sa includeTemporaryDtorsInCFG
201 Optional<bool> IncludeTemporaryDtorsInCFG;
203 /// \sa mayInlineCXXStandardLibrary
204 Optional<bool> InlineCXXStandardLibrary;
206 /// \sa mayInlineTemplateFunctions
207 Optional<bool> InlineTemplateFunctions;
209 /// \sa mayInlineCXXAllocator
210 Optional<bool> InlineCXXAllocator;
212 /// \sa mayInlineCXXContainerMethods
213 Optional<bool> InlineCXXContainerMethods;
215 /// \sa mayInlineCXXSharedPtrDtor
216 Optional<bool> InlineCXXSharedPtrDtor;
218 /// \sa mayInlineObjCMethod
219 Optional<bool> ObjCInliningMode;
221 // Cache of the "ipa-always-inline-size" setting.
222 // \sa getAlwaysInlineSize
223 Optional<unsigned> AlwaysInlineSize;
225 /// \sa shouldSuppressNullReturnPaths
226 Optional<bool> SuppressNullReturnPaths;
228 // \sa getMaxInlinableSize
229 Optional<unsigned> MaxInlinableSize;
231 /// \sa shouldAvoidSuppressingNullArgumentPaths
232 Optional<bool> AvoidSuppressingNullArgumentPaths;
234 /// \sa shouldSuppressInlinedDefensiveChecks
235 Optional<bool> SuppressInlinedDefensiveChecks;
237 /// \sa shouldSuppressFromCXXStandardLibrary
238 Optional<bool> SuppressFromCXXStandardLibrary;
240 /// \sa reportIssuesInMainSourceFile
241 Optional<bool> ReportIssuesInMainSourceFile;
243 /// \sa StableReportFilename
244 Optional<bool> StableReportFilename;
246 /// \sa getGraphTrimInterval
247 Optional<unsigned> GraphTrimInterval;
249 /// \sa getMaxTimesInlineLarge
250 Optional<unsigned> MaxTimesInlineLarge;
252 /// \sa getMaxNodesPerTopLevelFunction
253 Optional<unsigned> MaxNodesPerTopLevelFunction;
256 /// Interprets an option's string value as a boolean.
258 /// Accepts the strings "true" and "false".
259 /// If an option value is not provided, returns the given \p DefaultVal.
260 bool getBooleanOption(StringRef Name, bool DefaultVal);
262 /// Variant that accepts a Optional value to cache the result.
263 bool getBooleanOption(Optional<bool> &V, StringRef Name, bool DefaultVal);
265 /// Interprets an option's string value as an integer value.
266 int getOptionAsInteger(StringRef Name, int DefaultVal);
268 /// \brief Retrieves and sets the UserMode. This is a high-level option,
269 /// which is used to set other low-level options. It is not accessible
270 /// outside of AnalyzerOptions.
271 UserModeKind getUserMode();
273 /// \brief Returns the inter-procedural analysis mode.
274 IPAKind getIPAMode();
276 /// Returns the option controlling which C++ member functions will be
277 /// considered for inlining.
279 /// This is controlled by the 'c++-inlining' config option.
281 /// \sa CXXMemberInliningMode
282 bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K);
284 /// Returns true if ObjectiveC inlining is enabled, false otherwise.
285 bool mayInlineObjCMethod();
287 /// Returns whether or not the destructors for C++ temporary objects should
288 /// be included in the CFG.
290 /// This is controlled by the 'cfg-temporary-dtors' config option, which
291 /// accepts the values "true" and "false".
292 bool includeTemporaryDtorsInCFG();
294 /// Returns whether or not C++ standard library functions may be considered
297 /// This is controlled by the 'c++-stdlib-inlining' config option, which
298 /// accepts the values "true" and "false".
299 bool mayInlineCXXStandardLibrary();
301 /// Returns whether or not templated functions may be considered for inlining.
303 /// This is controlled by the 'c++-template-inlining' config option, which
304 /// accepts the values "true" and "false".
305 bool mayInlineTemplateFunctions();
307 /// Returns whether or not allocator call may be considered for inlining.
309 /// This is controlled by the 'c++-allocator-inlining' config option, which
310 /// accepts the values "true" and "false".
311 bool mayInlineCXXAllocator();
313 /// Returns whether or not methods of C++ container objects may be considered
316 /// This is controlled by the 'c++-container-inlining' config option, which
317 /// accepts the values "true" and "false".
318 bool mayInlineCXXContainerMethods();
320 /// Returns whether or not the destructor of C++ 'shared_ptr' may be
321 /// considered for inlining.
323 /// This covers std::shared_ptr, std::tr1::shared_ptr, and boost::shared_ptr,
324 /// and indeed any destructor named "~shared_ptr".
326 /// This is controlled by the 'c++-shared_ptr-inlining' config option, which
327 /// accepts the values "true" and "false".
328 bool mayInlineCXXSharedPtrDtor();
330 /// Returns whether or not paths that go through null returns should be
333 /// This is a heuristic for avoiding bug reports with paths that go through
334 /// inlined functions that are more defensive than their callers.
336 /// This is controlled by the 'suppress-null-return-paths' config option,
337 /// which accepts the values "true" and "false".
338 bool shouldSuppressNullReturnPaths();
340 /// Returns whether a bug report should \em not be suppressed if its path
341 /// includes a call with a null argument, even if that call has a null return.
343 /// This option has no effect when #shouldSuppressNullReturnPaths() is false.
345 /// This is a counter-heuristic to avoid false negatives.
347 /// This is controlled by the 'avoid-suppressing-null-argument-paths' config
348 /// option, which accepts the values "true" and "false".
349 bool shouldAvoidSuppressingNullArgumentPaths();
351 /// Returns whether or not diagnostics containing inlined defensive NULL
352 /// checks should be suppressed.
354 /// This is controlled by the 'suppress-inlined-defensive-checks' config
355 /// option, which accepts the values "true" and "false".
356 bool shouldSuppressInlinedDefensiveChecks();
358 /// Returns whether or not diagnostics reported within the C++ standard
359 /// library should be suppressed.
361 /// This is controlled by the 'suppress-c++-stdlib' config option,
362 /// which accepts the values "true" and "false".
363 bool shouldSuppressFromCXXStandardLibrary();
365 /// Returns whether or not the diagnostic report should be always reported
366 /// in the main source file and not the headers.
368 /// This is controlled by the 'report-in-main-source-file' config option,
369 /// which accepts the values "true" and "false".
370 bool shouldReportIssuesInMainSourceFile();
372 /// Returns whether or not the report filename should be random or not.
374 /// This is controlled by the 'stable-report-filename' config option,
375 /// which accepts the values "true" and "false". Default = false
376 bool shouldWriteStableReportFilename();
378 /// Returns whether irrelevant parts of a bug report path should be pruned
379 /// out of the final output.
381 /// This is controlled by the 'prune-paths' config option, which accepts the
382 /// values "true" and "false".
383 bool shouldPrunePaths();
385 /// Returns true if 'static' initializers should be in conditional logic
387 bool shouldConditionalizeStaticInitializers();
389 // Returns the size of the functions (in basic blocks), which should be
390 // considered to be small enough to always inline.
392 // This is controlled by "ipa-always-inline-size" analyzer-config option.
393 unsigned getAlwaysInlineSize();
395 // Returns the bound on the number of basic blocks in an inlined function
398 // This is controlled by "-analyzer-config max-inlinable-size" option.
399 unsigned getMaxInlinableSize();
401 /// Returns true if the analyzer engine should synthesize fake bodies
402 /// for well-known functions.
403 bool shouldSynthesizeBodies();
405 /// Returns how often nodes in the ExplodedGraph should be recycled to save
408 /// This is controlled by the 'graph-trim-interval' config option. To disable
409 /// node reclamation, set the option to "0".
410 unsigned getGraphTrimInterval();
412 /// Returns the maximum times a large function could be inlined.
414 /// This is controlled by the 'max-times-inline-large' config option.
415 unsigned getMaxTimesInlineLarge();
417 /// Returns the maximum number of nodes the analyzer can generate while
418 /// exploring a top level function (for each exploded graph).
419 /// 150000 is default; 0 means no limit.
421 /// This is controlled by the 'max-nodes' config option.
422 unsigned getMaxNodesPerTopLevelFunction();
426 AnalysisStoreOpt(RegionStoreModel),
427 AnalysisConstraintsOpt(RangeConstraintsModel),
428 AnalysisDiagOpt(PD_HTML),
429 AnalysisPurgeOpt(PurgeStmt),
433 AnalyzerDisplayProgress(0),
434 AnalyzeNestedBlocks(0),
435 eagerlyAssumeBinOpBifurcation(0),
437 visualizeExplodedGraphWithGraphViz(0),
438 visualizeExplodedGraphWithUbiGraph(0),
442 // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
443 InlineMaxStackDepth(5),
444 InliningMode(NoRedundancy),
445 UserMode(UMK_NotSet),
446 IPAMode(IPAK_NotSet),
447 CXXMemberInliningMode() {}
451 typedef IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef;