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_ANALYZEROPTIONS_H
16 #define LLVM_CLANG_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"
57 NUM_ANALYSIS_DIAG_CLIENTS
60 /// AnalysisPurgeModes - Set of available strategies for dead symbol removal.
61 enum AnalysisPurgeMode {
62 #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) NAME,
63 #include "clang/StaticAnalyzer/Core/Analyses.def"
67 /// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics.
68 enum AnalysisInliningMode {
69 #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME,
70 #include "clang/StaticAnalyzer/Core/Analyses.def"
74 /// \brief Describes the different kinds of C++ member functions which can be
75 /// considered for inlining by the analyzer.
77 /// These options are cumulative; enabling one kind of member function will
78 /// enable all kinds with lower enum values.
79 enum CXXInlineableMemberKind {
82 /// A dummy mode in which no C++ inlining is enabled.
85 /// Refers to regular member function and operator calls.
88 /// Refers to constructors (implicit or explicit).
90 /// Note that a constructor will not be inlined if the corresponding
91 /// destructor is non-trivial.
94 /// Refers to destructors (implicit or explicit).
98 /// \brief Describes the different modes of inter-procedural analysis.
102 /// Perform only intra-procedural analysis.
105 /// Inline C functions and blocks when their definitions are available.
106 IPAK_BasicInlining = 2,
108 /// Inline callees(C, C++, ObjC) when their definitions are available.
111 /// Enable inlining of dynamically dispatched methods.
112 IPAK_DynamicDispatch = 4,
114 /// Enable inlining of dynamically dispatched methods, bifurcate paths when
115 /// exact type info is unavailable.
116 IPAK_DynamicDispatchBifurcate = 5
119 class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
121 typedef llvm::StringMap<std::string> ConfigTable;
123 /// \brief Pair of checker name and enable/disable.
124 std::vector<std::pair<std::string, bool> > CheckersControlList;
126 /// \brief A key-value table of use-specified configuration values.
128 AnalysisStores AnalysisStoreOpt;
129 AnalysisConstraints AnalysisConstraintsOpt;
130 AnalysisDiagClients AnalysisDiagOpt;
131 AnalysisPurgeMode AnalysisPurgeOpt;
133 std::string AnalyzeSpecificFunction;
135 /// \brief The maximum number of times the analyzer visits a block.
136 unsigned maxBlockVisitOnPath;
139 unsigned ShowCheckerHelp : 1;
140 unsigned AnalyzeAll : 1;
141 unsigned AnalyzerDisplayProgress : 1;
142 unsigned AnalyzeNestedBlocks : 1;
144 /// \brief The flag regulates if we should eagerly assume evaluations of
145 /// conditionals, thus, bifurcating the path.
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;
155 unsigned TrimGraph : 1;
156 unsigned visualizeExplodedGraphWithGraphViz : 1;
157 unsigned visualizeExplodedGraphWithUbiGraph : 1;
158 unsigned UnoptimizedCFG : 1;
159 unsigned PrintStats : 1;
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;
165 /// \brief The inlining stack depth limit.
166 unsigned InlineMaxStackDepth;
168 /// \brief The mode of function selection used during inlining.
169 AnalysisInliningMode InliningMode;
172 /// \brief Describes the kinds for high-level analyzer mode.
175 /// Perform shallow but fast analyzes.
177 /// Perform deep analyzes.
181 /// Controls the high-level analyzer mode, which influences the default
182 /// settings for some of the lower-level config options (such as IPAMode).
184 UserModeKind UserMode;
186 /// Controls the mode of inter-procedural analysis.
189 /// Controls which C++ member functions will be considered for inlining.
190 CXXInlineableMemberKind CXXMemberInliningMode;
192 /// \sa includeTemporaryDtorsInCFG
193 Optional<bool> IncludeTemporaryDtorsInCFG;
195 /// \sa mayInlineCXXStandardLibrary
196 Optional<bool> InlineCXXStandardLibrary;
198 /// \sa mayInlineTemplateFunctions
199 Optional<bool> InlineTemplateFunctions;
201 /// \sa mayInlineCXXContainerCtorsAndDtors
202 Optional<bool> InlineCXXContainerCtorsAndDtors;
204 /// \sa mayInlineCXXSharedPtrDtor
205 Optional<bool> InlineCXXSharedPtrDtor;
207 /// \sa mayInlineObjCMethod
208 Optional<bool> ObjCInliningMode;
210 // Cache of the "ipa-always-inline-size" setting.
211 // \sa getAlwaysInlineSize
212 Optional<unsigned> AlwaysInlineSize;
214 /// \sa shouldSuppressNullReturnPaths
215 Optional<bool> SuppressNullReturnPaths;
217 // \sa getMaxInlinableSize
218 Optional<unsigned> MaxInlinableSize;
220 /// \sa shouldAvoidSuppressingNullArgumentPaths
221 Optional<bool> AvoidSuppressingNullArgumentPaths;
223 /// \sa shouldSuppressInlinedDefensiveChecks
224 Optional<bool> SuppressInlinedDefensiveChecks;
226 /// \sa shouldSuppressFromCXXStandardLibrary
227 Optional<bool> SuppressFromCXXStandardLibrary;
229 /// \sa reportIssuesInMainSourceFile
230 Optional<bool> ReportIssuesInMainSourceFile;
232 /// \sa getGraphTrimInterval
233 Optional<unsigned> GraphTrimInterval;
235 /// \sa getMaxTimesInlineLarge
236 Optional<unsigned> MaxTimesInlineLarge;
238 /// \sa getMaxNodesPerTopLevelFunction
239 Optional<unsigned> MaxNodesPerTopLevelFunction;
242 /// Interprets an option's string value as a boolean.
244 /// Accepts the strings "true" and "false".
245 /// If an option value is not provided, returns the given \p DefaultVal.
246 bool getBooleanOption(StringRef Name, bool DefaultVal);
248 /// Variant that accepts a Optional value to cache the result.
249 bool getBooleanOption(Optional<bool> &V, StringRef Name, bool DefaultVal);
251 /// Interprets an option's string value as an integer value.
252 int getOptionAsInteger(StringRef Name, int DefaultVal);
254 /// \brief Retrieves and sets the UserMode. This is a high-level option,
255 /// which is used to set other low-level options. It is not accessible
256 /// outside of AnalyzerOptions.
257 UserModeKind getUserMode();
259 /// \brief Returns the inter-procedural analysis mode.
260 IPAKind getIPAMode();
262 /// Returns the option controlling which C++ member functions will be
263 /// considered for inlining.
265 /// This is controlled by the 'c++-inlining' config option.
267 /// \sa CXXMemberInliningMode
268 bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K);
270 /// Returns true if ObjectiveC inlining is enabled, false otherwise.
271 bool mayInlineObjCMethod();
273 /// Returns whether or not the destructors for C++ temporary objects should
274 /// be included in the CFG.
276 /// This is controlled by the 'cfg-temporary-dtors' config option, which
277 /// accepts the values "true" and "false".
278 bool includeTemporaryDtorsInCFG();
280 /// Returns whether or not C++ standard library functions may be considered
283 /// This is controlled by the 'c++-stdlib-inlining' config option, which
284 /// accepts the values "true" and "false".
285 bool mayInlineCXXStandardLibrary();
287 /// Returns whether or not templated functions may be considered for inlining.
289 /// This is controlled by the 'c++-template-inlining' config option, which
290 /// accepts the values "true" and "false".
291 bool mayInlineTemplateFunctions();
293 /// Returns whether or not constructors and destructors of C++ container
294 /// objects may be considered for inlining.
296 /// This is controlled by the 'c++-container-inlining' config option, which
297 /// accepts the values "true" and "false".
298 bool mayInlineCXXContainerCtorsAndDtors();
300 /// Returns whether or not the destructor of C++ 'shared_ptr' may be
301 /// considered for inlining.
303 /// This covers std::shared_ptr, std::tr1::shared_ptr, and boost::shared_ptr,
304 /// and indeed any destructor named "~shared_ptr".
306 /// This is controlled by the 'c++-shared_ptr-inlining' config option, which
307 /// accepts the values "true" and "false".
308 bool mayInlineCXXSharedPtrDtor();
310 /// Returns whether or not paths that go through null returns should be
313 /// This is a heuristic for avoiding bug reports with paths that go through
314 /// inlined functions that are more defensive than their callers.
316 /// This is controlled by the 'suppress-null-return-paths' config option,
317 /// which accepts the values "true" and "false".
318 bool shouldSuppressNullReturnPaths();
320 /// Returns whether a bug report should \em not be suppressed if its path
321 /// includes a call with a null argument, even if that call has a null return.
323 /// This option has no effect when #shouldSuppressNullReturnPaths() is false.
325 /// This is a counter-heuristic to avoid false negatives.
327 /// This is controlled by the 'avoid-suppressing-null-argument-paths' config
328 /// option, which accepts the values "true" and "false".
329 bool shouldAvoidSuppressingNullArgumentPaths();
331 /// Returns whether or not diagnostics containing inlined defensive NULL
332 /// checks should be suppressed.
334 /// This is controlled by the 'suppress-inlined-defensive-checks' config
335 /// option, which accepts the values "true" and "false".
336 bool shouldSuppressInlinedDefensiveChecks();
338 /// Returns whether or not diagnostics reported within the C++ standard
339 /// library should be suppressed.
341 /// This is controlled by the 'suppress-c++-stdlib' config option,
342 /// which accepts the values "true" and "false".
343 bool shouldSuppressFromCXXStandardLibrary();
345 /// Returns whether or not the diagnostic report should be always reported
346 /// in the main source file and not the headers.
348 /// This is controlled by the 'report-in-main-source-file' config option,
349 /// which accepts the values "true" and "false".
350 bool shouldReportIssuesInMainSourceFile();
352 /// Returns whether irrelevant parts of a bug report path should be pruned
353 /// out of the final output.
355 /// This is controlled by the 'prune-paths' config option, which accepts the
356 /// values "true" and "false".
357 bool shouldPrunePaths();
359 /// Returns true if 'static' initializers should be in conditional logic
361 bool shouldConditionalizeStaticInitializers();
363 // Returns the size of the functions (in basic blocks), which should be
364 // considered to be small enough to always inline.
366 // This is controlled by "ipa-always-inline-size" analyzer-config option.
367 unsigned getAlwaysInlineSize();
369 // Returns the bound on the number of basic blocks in an inlined function
372 // This is controlled by "-analyzer-config max-inlinable-size" option.
373 unsigned getMaxInlinableSize();
375 /// Returns true if the analyzer engine should synthesize fake bodies
376 /// for well-known functions.
377 bool shouldSynthesizeBodies();
379 /// Returns how often nodes in the ExplodedGraph should be recycled to save
382 /// This is controlled by the 'graph-trim-interval' config option. To disable
383 /// node reclamation, set the option to "0".
384 unsigned getGraphTrimInterval();
386 /// Returns the maximum times a large function could be inlined.
388 /// This is controlled by the 'max-times-inline-large' config option.
389 unsigned getMaxTimesInlineLarge();
391 /// Returns the maximum number of nodes the analyzer can generate while
392 /// exploring a top level function (for each exploded graph).
393 /// 150000 is default; 0 means no limit.
395 /// This is controlled by the 'max-nodes' config option.
396 unsigned getMaxNodesPerTopLevelFunction();
400 AnalysisStoreOpt(RegionStoreModel),
401 AnalysisConstraintsOpt(RangeConstraintsModel),
402 AnalysisDiagOpt(PD_HTML),
403 AnalysisPurgeOpt(PurgeStmt),
406 AnalyzerDisplayProgress(0),
407 AnalyzeNestedBlocks(0),
408 eagerlyAssumeBinOpBifurcation(0),
410 visualizeExplodedGraphWithGraphViz(0),
411 visualizeExplodedGraphWithUbiGraph(0),
415 // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
416 InlineMaxStackDepth(5),
417 InliningMode(NoRedundancy),
418 UserMode(UMK_NotSet),
419 IPAMode(IPAK_NotSet),
420 CXXMemberInliningMode() {}
424 typedef IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef;