clang  8.0.0svn
AnalyzerOptions.h
Go to the documentation of this file.
1 //===- AnalyzerOptions.h - Analysis Engine Options --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This header defines various options for the static analyzer that are set
11 // by the frontend and are consulted throughout the analyzer.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H
16 #define LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H
17 
18 #include "clang/Basic/LLVM.h"
19 #include "llvm/ADT/IntrusiveRefCntPtr.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringRef.h"
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 namespace clang {
28 
29 namespace ento {
30 
31 class CheckerBase;
32 
33 } // namespace ento
34 
35 /// Analysis - Set of available source code analyses.
36 enum Analyses {
37 #define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE) NAME,
38 #include "clang/StaticAnalyzer/Core/Analyses.def"
40 };
41 
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"
47 };
48 
49 /// AnalysisConstraints - Set of available constraint models.
51 #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) NAME##Model,
52 #include "clang/StaticAnalyzer/Core/Analyses.def"
54 };
55 
56 /// AnalysisDiagClients - Set of available diagnostic clients for rendering
57 /// analysis results.
59 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME,
60 #include "clang/StaticAnalyzer/Core/Analyses.def"
63 };
64 
65 /// AnalysisPurgeModes - Set of available strategies for dead symbol removal.
67 #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) NAME,
68 #include "clang/StaticAnalyzer/Core/Analyses.def"
70 };
71 
72 /// AnalysisInlineFunctionSelection - Set of inlining function selection heuristics.
74 #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) NAME,
75 #include "clang/StaticAnalyzer/Core/Analyses.def"
77 };
78 
79 /// Describes the different kinds of C++ member functions which can be
80 /// considered for inlining by the analyzer.
81 ///
82 /// These options are cumulative; enabling one kind of member function will
83 /// enable all kinds with lower enum values.
85  // Uninitialized = 0,
86 
87  /// A dummy mode in which no C++ inlining is enabled.
89 
90  /// Refers to regular member function and operator calls.
92 
93  /// Refers to constructors (implicit or explicit).
94  ///
95  /// Note that a constructor will not be inlined if the corresponding
96  /// destructor is non-trivial.
98 
99  /// Refers to destructors (implicit or explicit).
101 };
102 
103 /// Describes the different modes of inter-procedural analysis.
104 enum IPAKind {
105  /// Perform only intra-procedural analysis.
107 
108  /// Inline C functions and blocks when their definitions are available.
110 
111  /// Inline callees(C, C++, ObjC) when their definitions are available.
113 
114  /// Enable inlining of dynamically dispatched methods.
116 
117  /// Enable inlining of dynamically dispatched methods, bifurcate paths when
118  /// exact type info is unavailable.
120 };
121 
123  DFS,
124  BFS,
129 };
130 
131 /// Describes the kinds for high-level analyzer mode.
133  /// Perform shallow but fast analyzes.
135 
136  /// Perform deep analyzes.
138 };
139 
140 /// Stores options for the analyzer from the command line.
141 ///
142 /// Some options are frontend flags (e.g.: -analyzer-output), but some are
143 /// analyzer configuration options, which are preceded by -analyzer-config
144 /// (e.g.: -analyzer-config notes-as-events=true).
145 ///
146 /// If you'd like to add a new frontend flag, add it to
147 /// include/clang/Driver/CC1Options.td, add a new field to store the value of
148 /// that flag in this class, and initialize it in
149 /// lib/Frontend/CompilerInvocation.cpp.
150 ///
151 /// If you'd like to add a new non-checker configuration, register it in
152 /// include/clang/StaticAnalyzer/Core/AnalyzerOptions.def, and refer to the
153 /// top of the file for documentation.
154 ///
155 /// If you'd like to add a new checker option, call getChecker*Option()
156 /// whenever.
157 ///
158 /// Some of the options are controlled by raw frontend flags for no good reason,
159 /// and should be eventually converted into -analyzer-config flags. New analyzer
160 /// options should not be implemented as frontend flags. Frontend flags still
161 /// make sense for things that do not affect the actual analysis.
162 class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
163 public:
164  using ConfigTable = llvm::StringMap<std::string>;
165 
166  static std::vector<StringRef>
167  getRegisteredCheckers(bool IncludeExperimental = false);
168 
169  /// Pair of checker name and enable/disable.
170  std::vector<std::pair<std::string, bool>> CheckersControlList;
171 
172  /// A key-value table of use-specified configuration values.
174  AnalysisStores AnalysisStoreOpt = RegionStoreModel;
175  AnalysisConstraints AnalysisConstraintsOpt = RangeConstraintsModel;
176  AnalysisDiagClients AnalysisDiagOpt = PD_HTML;
177  AnalysisPurgeMode AnalysisPurgeOpt = PurgeStmt;
178 
180 
181  /// File path to which the exploded graph should be dumped.
182  std::string DumpExplodedGraphTo;
183 
184  /// Store full compiler invocation for reproducible instructions in the
185  /// generated report.
187 
188  /// The maximum number of times the analyzer visits a block.
190 
191  /// Disable all analyzer checks.
192  ///
193  /// This flag allows one to disable analyzer checks on the code processed by
194  /// the given analysis consumer. Note, the code will get parsed and the
195  /// command-line options will get checked.
196  unsigned DisableAllChecks : 1;
197 
198  unsigned ShowCheckerHelp : 1;
200  unsigned ShowConfigOptionsList : 1;
201  unsigned AnalyzeAll : 1;
203  unsigned AnalyzeNestedBlocks : 1;
204 
206 
207  unsigned TrimGraph : 1;
209  unsigned UnoptimizedCFG : 1;
210  unsigned PrintStats : 1;
211 
212  /// Do not re-analyze paths leading to exhausted nodes with a different
213  /// strategy. We get better code coverage when retry is enabled.
214  unsigned NoRetryExhausted : 1;
215 
216  /// The inlining stack depth limit.
217  // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
218  unsigned InlineMaxStackDepth = 5;
219 
220  /// The mode of function selection used during inlining.
221  AnalysisInliningMode InliningMode = NoRedundancy;
222 
223 private:
224 
225 #define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \
226  Optional<TYPE> NAME;
227 #define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \
228  SHALLOW_VAL, DEEP_VAL) \
229  Optional<TYPE> NAME;
230 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
231 #undef ANALYZER_OPTION
232 #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
233 
234  /// Query an option's string value.
235  ///
236  /// If an option value is not provided, returns the given \p DefaultVal.
237  /// @param [in] OptionName Name for option to retrieve.
238  /// @param [in] DefaultVal Default value returned if no such option was
239  /// specified.
240  StringRef getStringOption(StringRef OptionName, StringRef DefaultVal);
241 
242  void initOption(Optional<StringRef> &V, StringRef Name,
243  StringRef DefaultVal);
244 
245  void initOption(Optional<bool> &V, StringRef Name, bool DefaultVal);
246 
247  void initOption(Optional<unsigned> &V, StringRef Name,
248  unsigned DefaultVal);
249 public:
251  : DisableAllChecks(false), ShowCheckerHelp(false),
252  ShowEnabledCheckerList(false), ShowConfigOptionsList(false),
253  AnalyzeAll(false), AnalyzerDisplayProgress(false),
254  AnalyzeNestedBlocks(false), eagerlyAssumeBinOpBifurcation(false),
255  TrimGraph(false), visualizeExplodedGraphWithGraphViz(false),
256  UnoptimizedCFG(false), PrintStats(false), NoRetryExhausted(false) {}
257 
258  /// Interprets an option's string value as a boolean. The "true" string is
259  /// interpreted as true and the "false" string is interpreted as false.
260  ///
261  /// If an option value is not provided, returns the given \p DefaultVal.
262  /// @param [in] Name Name for option to retrieve.
263  /// @param [in] DefaultVal Default value returned if no such option was
264  /// specified.
265  /// @param [in] C The checker object the option belongs to. Checker options
266  /// are retrieved in the following format:
267  /// `-analyzer-config <package and checker name>:OptionName=Value.
268  /// @param [in] SearchInParents If set to true and the searched option was not
269  /// specified for the given checker the options for the parent packages will
270  /// be searched as well. The inner packages take precedence over the outer
271  /// ones.
272  bool getCheckerBooleanOption(StringRef Name, bool DefaultVal,
273  const ento::CheckerBase *C,
274  bool SearchInParents = false) const;
275 
276 
277  /// Interprets an option's string value as an integer value.
278  ///
279  /// If an option value is not provided, returns the given \p DefaultVal.
280  /// @param [in] Name Name for option to retrieve.
281  /// @param [in] DefaultVal Default value returned if no such option was
282  /// specified.
283  /// @param [in] C The checker object the option belongs to. Checker options
284  /// are retrieved in the following format:
285  /// `-analyzer-config <package and checker name>:OptionName=Value.
286  /// @param [in] SearchInParents If set to true and the searched option was not
287  /// specified for the given checker the options for the parent packages will
288  /// be searched as well. The inner packages take precedence over the outer
289  /// ones.
290  int getCheckerIntegerOption(StringRef Name, int DefaultVal,
291  const ento::CheckerBase *C,
292  bool SearchInParents = false) const;
293 
294  /// Query an option's string value.
295  ///
296  /// If an option value is not provided, returns the given \p DefaultVal.
297  /// @param [in] Name Name for option to retrieve.
298  /// @param [in] DefaultVal Default value returned if no such option was
299  /// specified.
300  /// @param [in] C The checker object the option belongs to. Checker options
301  /// are retrieved in the following format:
302  /// `-analyzer-config <package and checker name>:OptionName=Value.
303  /// @param [in] SearchInParents If set to true and the searched option was not
304  /// specified for the given checker the options for the parent packages will
305  /// be searched as well. The inner packages take precedence over the outer
306  /// ones.
307  StringRef getCheckerStringOption(StringRef Name, StringRef DefaultVal,
308  const ento::CheckerBase *C,
309  bool SearchInParents = false) const;
310 
311 #define ANALYZER_OPTION_GEN_FN(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL, \
312  CREATE_FN) \
313  TYPE CREATE_FN() { \
314  initOption(NAME, CMDFLAG, DEFAULT_VAL); \
315  return NAME.getValue(); \
316  }
317 
318 #define ANALYZER_OPTION_GEN_FN_DEPENDS_ON_USER_MODE( \
319  TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL, DEEP_VAL, CREATE_FN) \
320  TYPE CREATE_FN() { \
321  switch (getUserMode()) { \
322  case UMK_Shallow: \
323  initOption(NAME, CMDFLAG, SHALLOW_VAL); \
324  break; \
325  case UMK_Deep: \
326  initOption(NAME, CMDFLAG, DEEP_VAL); \
327  break; \
328  } \
329  \
330  return NAME.getValue(); \
331  }
332 
333 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
334 
335 #undef ANALYZER_OPTION_GEN_FN_DEPENDS_ON_USER_MODE
336 #undef ANALYZER_OPTION_WITH_FN
337 
338  /// Retrieves and sets the UserMode. This is a high-level option,
339  /// which is used to set other low-level options. It is not accessible
340  /// outside of AnalyzerOptions.
341  UserModeKind getUserMode();
342 
343  ExplorationStrategyKind getExplorationStrategy();
344 
345  /// Returns the inter-procedural analysis mode.
346  IPAKind getIPAMode();
347 
348  /// Returns the option controlling which C++ member functions will be
349  /// considered for inlining.
350  ///
351  /// This is controlled by the 'c++-inlining' config option.
352  ///
353  /// \sa CXXMemberInliningMode
354  bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K);
355 
356  StringRef getCTUDir();
357 };
358 
360 
361 } // namespace clang
362 
363 #endif // LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H
Inline C functions and blocks when their definitions are available.
IPAKind
Describes the different modes of inter-procedural analysis.
unsigned visualizeExplodedGraphWithGraphViz
Perform only intra-procedural analysis.
A dummy mode in which no C++ inlining is enabled.
Inline callees(C, C++, ObjC) when their definitions are available.
Perform deep analyzes.
std::string DumpExplodedGraphTo
File path to which the exploded graph should be dumped.
unsigned eagerlyAssumeBinOpBifurcation
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
std::string FullCompilerInvocation
Store full compiler invocation for reproducible instructions in the generated report.
std::vector< std::pair< std::string, bool > > CheckersControlList
Pair of checker name and enable/disable.
AnalysisStores
AnalysisStores - Set of available analysis store models.
ExplorationStrategyKind
Refers to regular member function and operator calls.
AnalysisInliningMode
AnalysisInlineFunctionSelection - Set of inlining function selection heuristics.
Refers to constructors (implicit or explicit).
Enable inlining of dynamically dispatched methods.
UserModeKind
Describes the kinds for high-level analyzer mode.
#define false
Definition: stdbool.h:33
AnalysisConstraints
AnalysisConstraints - Set of available constraint models.
llvm::StringMap< std::string > ConfigTable
ConfigTable Config
A key-value table of use-specified configuration values.
Refers to destructors (implicit or explicit).
unsigned maxBlockVisitOnPath
The maximum number of times the analyzer visits a block.
unsigned DisableAllChecks
Disable all analyzer checks.
Dataflow Directional Tag Classes.
Perform shallow but fast analyzes.
std::string AnalyzeSpecificFunction
AnalysisPurgeMode
AnalysisPurgeModes - Set of available strategies for dead symbol removal.
Stores options for the analyzer from the command line.
unsigned NoRetryExhausted
Do not re-analyze paths leading to exhausted nodes with a different strategy.
Analyses
Analysis - Set of available source code analyses.
CXXInlineableMemberKind
Describes the different kinds of C++ member functions which can be considered for inlining by the ana...
Enable inlining of dynamically dispatched methods, bifurcate paths when exact type info is unavailabl...
AnalysisDiagClients
AnalysisDiagClients - Set of available diagnostic clients for rendering analysis results.