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
20 #include "clang/Basic/LLVM.h"
21 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/IntrusiveRefCntPtr.h"
23 #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, AUTOCREAT) 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 /// AnalysisIPAMode - Set of inter-procedural modes.
68 enum AnalysisIPAMode {
69 #define ANALYSIS_IPA(NAME, CMDFLAG, DESC) NAME,
70 #include "clang/StaticAnalyzer/Core/Analyses.def"
74 /// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics.
75 enum AnalysisInliningMode {
76 #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME,
77 #include "clang/StaticAnalyzer/Core/Analyses.def"
81 /// \brief Describes the different kinds of C++ member functions which can be
82 /// considered for inlining by the analyzer.
84 /// These options are cumulative; enabling one kind of member function will
85 /// enable all kinds with lower enum values.
86 enum CXXInlineableMemberKind {
89 /// A dummy mode in which no C++ inlining is enabled.
92 /// Refers to regular member function and operator calls.
95 /// Refers to constructors (implicit or explicit).
97 /// Note that a constructor will not be inlined if the corresponding
98 /// destructor is non-trivial.
101 /// Refers to destructors (implicit or explicit).
106 class AnalyzerOptions : public llvm::RefCountedBase<AnalyzerOptions> {
108 typedef llvm::StringMap<std::string> ConfigTable;
110 /// \brief Pair of checker name and enable/disable.
111 std::vector<std::pair<std::string, bool> > CheckersControlList;
113 /// \brief A key-value table of use-specified configuration values.
115 AnalysisStores AnalysisStoreOpt;
116 AnalysisConstraints AnalysisConstraintsOpt;
117 AnalysisDiagClients AnalysisDiagOpt;
118 AnalysisPurgeMode AnalysisPurgeOpt;
120 // \brief The interprocedural analysis mode.
121 AnalysisIPAMode IPAMode;
123 std::string AnalyzeSpecificFunction;
125 /// \brief The maximum number of exploded nodes the analyzer will generate.
128 /// \brief The maximum number of times the analyzer visits a block.
129 unsigned maxBlockVisitOnPath;
132 unsigned ShowCheckerHelp : 1;
133 unsigned AnalyzeAll : 1;
134 unsigned AnalyzerDisplayProgress : 1;
135 unsigned AnalyzeNestedBlocks : 1;
137 /// \brief The flag regulates if we should eagerly assume evaluations of
138 /// conditionals, thus, bifurcating the path.
140 /// This flag indicates how the engine should handle expressions such as: 'x =
141 /// (y != 0)'. When this flag is true then the subexpression 'y != 0' will be
142 /// eagerly assumed to be true or false, thus evaluating it to the integers 0
143 /// or 1 respectively. The upside is that this can increase analysis
144 /// precision until we have a better way to lazily evaluate such logic. The
145 /// downside is that it eagerly bifurcates paths.
146 unsigned eagerlyAssumeBinOpBifurcation : 1;
148 unsigned TrimGraph : 1;
149 unsigned visualizeExplodedGraphWithGraphViz : 1;
150 unsigned visualizeExplodedGraphWithUbiGraph : 1;
151 unsigned UnoptimizedCFG : 1;
152 unsigned PrintStats : 1;
154 /// \brief Do not re-analyze paths leading to exhausted nodes with a different
155 /// strategy. We get better code coverage when retry is enabled.
156 unsigned NoRetryExhausted : 1;
158 /// \brief The inlining stack depth limit.
159 unsigned InlineMaxStackDepth;
161 /// \brief The mode of function selection used during inlining.
162 unsigned InlineMaxFunctionSize;
164 /// \brief The mode of function selection used during inlining.
165 AnalysisInliningMode InliningMode;
168 /// Controls which C++ member functions will be considered for inlining.
169 CXXInlineableMemberKind CXXMemberInliningMode;
171 /// \sa includeTemporaryDtorsInCFG
172 llvm::Optional<bool> IncludeTemporaryDtorsInCFG;
174 /// \sa mayInlineCXXStandardLibrary
175 llvm::Optional<bool> InlineCXXStandardLibrary;
177 /// \sa mayInlineTemplateFunctions
178 llvm::Optional<bool> InlineTemplateFunctions;
180 /// \sa mayInlineObjCMethod
181 llvm::Optional<bool> ObjCInliningMode;
183 // Cache of the "ipa-always-inline-size" setting.
184 // \sa getAlwaysInlineSize
185 llvm::Optional<unsigned> AlwaysInlineSize;
187 /// \sa shouldPruneNullReturnPaths
188 llvm::Optional<bool> PruneNullReturnPaths;
190 /// \sa shouldAvoidSuppressingNullArgumentPaths
191 llvm::Optional<bool> AvoidSuppressingNullArgumentPaths;
193 /// \sa getGraphTrimInterval
194 llvm::Optional<unsigned> GraphTrimInterval;
196 /// Interprets an option's string value as a boolean.
198 /// Accepts the strings "true" and "false".
199 /// If an option value is not provided, returns the given \p DefaultVal.
200 bool getBooleanOption(StringRef Name, bool DefaultVal);
202 /// Variant that accepts a Optional value to cache the result.
203 bool getBooleanOption(llvm::Optional<bool> &V, StringRef Name,
206 /// Interprets an option's string value as an integer value.
207 int getOptionAsInteger(llvm::StringRef Name, int DefaultVal);
210 /// Returns the option controlling which C++ member functions will be
211 /// considered for inlining.
213 /// This is controlled by the 'c++-inlining' config option.
215 /// \sa CXXMemberInliningMode
216 bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K);
218 /// Returns true if ObjectiveC inlining is enabled, false otherwise.
219 bool mayInlineObjCMethod();
221 /// Returns whether or not the destructors for C++ temporary objects should
222 /// be included in the CFG.
224 /// This is controlled by the 'cfg-temporary-dtors' config option, which
225 /// accepts the values "true" and "false".
226 bool includeTemporaryDtorsInCFG();
228 /// Returns whether or not C++ standard library functions may be considered
231 /// This is controlled by the 'c++-stdlib-inlining' config option, which
232 /// accepts the values "true" and "false".
233 bool mayInlineCXXStandardLibrary();
235 /// Returns whether or not templated functions may be considered for inlining.
237 /// This is controlled by the 'c++-template-inlining' config option, which
238 /// accepts the values "true" and "false".
239 bool mayInlineTemplateFunctions();
241 /// Returns whether or not paths that go through null returns should be
244 /// This is a heuristic for avoiding bug reports with paths that go through
245 /// inlined functions that are more defensive than their callers.
247 /// This is controlled by the 'suppress-null-return-paths' config option,
248 /// which accepts the values "true" and "false".
249 bool shouldPruneNullReturnPaths();
251 /// Returns whether a bug report should \em not be suppressed if its path
252 /// includes a call with a null argument, even if that call has a null return.
254 /// This option has no effect when #shouldPruneNullReturnPaths() is false.
256 /// This is a counter-heuristic to avoid false negatives.
258 /// This is controlled by the 'avoid-suppressing-null-argument-paths' config
259 /// option, which accepts the values "true" and "false".
260 bool shouldAvoidSuppressingNullArgumentPaths();
262 // Returns the size of the functions (in basic blocks), which should be
263 // considered to be small enough to always inline.
265 // This is controlled by "ipa-always-inline-size" analyzer-config option.
266 unsigned getAlwaysInlineSize();
268 /// Returns true if the analyzer engine should synthesize fake bodies
269 /// for well-known functions.
270 bool shouldSynthesizeBodies();
272 /// Returns how often nodes in the ExplodedGraph should be recycled to save
275 /// This is controlled by the 'graph-trim-interval' config option. To disable
276 /// node reclamation, set the option to "0".
277 unsigned getGraphTrimInterval();
280 AnalyzerOptions() : CXXMemberInliningMode() {
281 AnalysisStoreOpt = RegionStoreModel;
282 AnalysisConstraintsOpt = RangeConstraintsModel;
283 AnalysisDiagOpt = PD_HTML;
284 AnalysisPurgeOpt = PurgeStmt;
285 IPAMode = DynamicDispatchBifurcate;
288 AnalyzerDisplayProgress = 0;
289 AnalyzeNestedBlocks = 0;
290 eagerlyAssumeBinOpBifurcation = 0;
292 visualizeExplodedGraphWithGraphViz = 0;
293 visualizeExplodedGraphWithUbiGraph = 0;
296 NoRetryExhausted = 0;
297 // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
298 InlineMaxStackDepth = 5;
299 InlineMaxFunctionSize = 200;
300 InliningMode = NoRedundancy;
304 typedef llvm::IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef;