|
@@ -137,6 +137,28 @@ enum UserModeKind {
|
|
UMK_Deep = 2
|
|
UMK_Deep = 2
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+/// Stores options for the analyzer from the command line.
|
|
|
|
+///
|
|
|
|
+/// Some options are frontend flags (e.g.: -analyzer-output), but some are
|
|
|
|
+/// analyzer configuration options, which are preceded by -analyzer-config
|
|
|
|
+/// (e.g.: -analyzer-config notes-as-events=true).
|
|
|
|
+///
|
|
|
|
+/// If you'd like to add a new frontend flag, add it to
|
|
|
|
+/// include/clang/Driver/CC1Options.td, add a new field to store the value of
|
|
|
|
+/// that flag in this class, and initialize it in
|
|
|
|
+/// lib/Frontend/CompilerInvocation.cpp.
|
|
|
|
+///
|
|
|
|
+/// If you'd like to add a new non-checker configuration, register it in
|
|
|
|
+/// include/clang/StaticAnalyzer/Core/AnalyzerOptions.def, and refer to the
|
|
|
|
+/// top of the file for documentation.
|
|
|
|
+///
|
|
|
|
+/// If you'd like to add a new checker option, call getChecker*Option()
|
|
|
|
+/// whenever.
|
|
|
|
+///
|
|
|
|
+/// Some of the options are controlled by raw frontend flags for no good reason,
|
|
|
|
+/// and should be eventually converted into -analyzer-config flags. New analyzer
|
|
|
|
+/// options should not be implemented as frontend flags. Frontend flags still
|
|
|
|
+/// make sense for things that do not affect the actual analysis.
|
|
class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
|
|
class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
|
|
public:
|
|
public:
|
|
using ConfigTable = llvm::StringMap<std::string>;
|
|
using ConfigTable = llvm::StringMap<std::string>;
|
|
@@ -209,32 +231,21 @@ private:
|
|
#undef ANALYZER_OPTION
|
|
#undef ANALYZER_OPTION
|
|
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
|
|
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
|
|
|
|
|
|
- /// A helper function that retrieves option for a given full-qualified
|
|
|
|
- /// checker name.
|
|
|
|
- /// Options for checkers can be specified via 'analyzer-config' command-line
|
|
|
|
- /// option.
|
|
|
|
- /// Example:
|
|
|
|
- /// @code-analyzer-config unix.Malloc:OptionName=CheckerOptionValue @endcode
|
|
|
|
- /// or @code-analyzer-config unix:OptionName=GroupOptionValue @endcode
|
|
|
|
- /// for groups of checkers.
|
|
|
|
- /// @param [in] CheckerName Full-qualified checker name, like
|
|
|
|
- /// alpha.unix.StreamChecker.
|
|
|
|
- /// @param [in] OptionName Name of the option to get.
|
|
|
|
- /// @param [in] Default Default value if no option is specified.
|
|
|
|
- /// @param [in] SearchInParents If set to true and the searched option was not
|
|
|
|
- /// specified for the given checker the options for the parent packages will
|
|
|
|
- /// be searched as well. The inner packages take precedence over the outer
|
|
|
|
- /// ones.
|
|
|
|
- /// @retval CheckerOptionValue An option for a checker if it was specified.
|
|
|
|
- /// @retval GroupOptionValue An option for group if it was specified and no
|
|
|
|
- /// checker-specific options were found. The closer group to checker,
|
|
|
|
- /// the more priority it has. For example, @c coregroup.subgroup has more
|
|
|
|
- /// priority than @c coregroup for @c coregroup.subgroup.CheckerName checker.
|
|
|
|
- /// @retval Default If nor checker option, nor group option was found.
|
|
|
|
- StringRef getCheckerOption(StringRef CheckerName, StringRef OptionName,
|
|
|
|
- StringRef Default,
|
|
|
|
- bool SearchInParents = false);
|
|
|
|
|
|
+ /// Query an option's string value.
|
|
|
|
+ ///
|
|
|
|
+ /// If an option value is not provided, returns the given \p DefaultVal.
|
|
|
|
+ /// @param [in] Name Name for option to retrieve.
|
|
|
|
+ /// @param [in] DefaultVal Default value returned if no such option was
|
|
|
|
+ /// specified.
|
|
|
|
+ StringRef getStringOption(StringRef OptionName, StringRef DefaultVal);
|
|
|
|
+
|
|
|
|
+ void initOption(Optional<StringRef> &V, StringRef Name,
|
|
|
|
+ StringRef DefaultVal);
|
|
|
|
|
|
|
|
+ void initOption(Optional<bool> &V, StringRef Name, bool DefaultVal);
|
|
|
|
+
|
|
|
|
+ void initOption(Optional<unsigned> &V, StringRef Name,
|
|
|
|
+ unsigned DefaultVal);
|
|
public:
|
|
public:
|
|
AnalyzerOptions()
|
|
AnalyzerOptions()
|
|
: DisableAllChecks(false), ShowCheckerHelp(false),
|
|
: DisableAllChecks(false), ShowCheckerHelp(false),
|
|
@@ -252,34 +263,17 @@ public:
|
|
/// @param [in] Name Name for option to retrieve.
|
|
/// @param [in] Name Name for option to retrieve.
|
|
/// @param [in] DefaultVal Default value returned if no such option was
|
|
/// @param [in] DefaultVal Default value returned if no such option was
|
|
/// specified.
|
|
/// specified.
|
|
- /// @param [in] C The optional checker parameter that can be used to restrict
|
|
|
|
- /// the search to the options of this particular checker (and its parents
|
|
|
|
- /// depending on search mode).
|
|
|
|
|
|
+ /// @param [in] C The checker object the option belongs to. Checker options
|
|
|
|
+ /// are retrieved in the following format:
|
|
|
|
+ /// `-analyzer-config <package and checker name>:OptionName=Value.
|
|
/// @param [in] SearchInParents If set to true and the searched option was not
|
|
/// @param [in] SearchInParents If set to true and the searched option was not
|
|
/// specified for the given checker the options for the parent packages will
|
|
/// specified for the given checker the options for the parent packages will
|
|
/// be searched as well. The inner packages take precedence over the outer
|
|
/// be searched as well. The inner packages take precedence over the outer
|
|
/// ones.
|
|
/// ones.
|
|
- bool getBooleanOption(StringRef Name, bool DefaultVal,
|
|
|
|
- const ento::CheckerBase *C = nullptr,
|
|
|
|
- bool SearchInParents = false);
|
|
|
|
|
|
+ bool getCheckerBooleanOption(StringRef Name, bool DefaultVal,
|
|
|
|
+ const ento::CheckerBase *C,
|
|
|
|
+ bool SearchInParents = false) const;
|
|
|
|
|
|
- /// Variant that accepts a Optional value to cache the result.
|
|
|
|
- ///
|
|
|
|
- /// @param [in,out] V Return value storage, returned if parameter contains
|
|
|
|
- /// an existing valid option, else it is used to store a return value
|
|
|
|
- /// @param [in] Name Name for option to retrieve.
|
|
|
|
- /// @param [in] DefaultVal Default value returned if no such option was
|
|
|
|
- /// specified.
|
|
|
|
- /// @param [in] C The optional checker parameter that can be used to restrict
|
|
|
|
- /// the search to the options of this particular checker (and its parents
|
|
|
|
- /// depending on search mode).
|
|
|
|
- /// @param [in] SearchInParents If set to true and the searched option was not
|
|
|
|
- /// specified for the given checker the options for the parent packages will
|
|
|
|
- /// be searched as well. The inner packages take precedence over the outer
|
|
|
|
- /// ones.
|
|
|
|
- bool getBooleanOption(Optional<bool> &V, StringRef Name, bool DefaultVal,
|
|
|
|
- const ento::CheckerBase *C = nullptr,
|
|
|
|
- bool SearchInParents = false);
|
|
|
|
|
|
|
|
/// Interprets an option's string value as an integer value.
|
|
/// Interprets an option's string value as an integer value.
|
|
///
|
|
///
|
|
@@ -287,21 +281,16 @@ public:
|
|
/// @param [in] Name Name for option to retrieve.
|
|
/// @param [in] Name Name for option to retrieve.
|
|
/// @param [in] DefaultVal Default value returned if no such option was
|
|
/// @param [in] DefaultVal Default value returned if no such option was
|
|
/// specified.
|
|
/// specified.
|
|
- /// @param [in] C The optional checker parameter that can be used to restrict
|
|
|
|
- /// the search to the options of this particular checker (and its parents
|
|
|
|
- /// depending on search mode).
|
|
|
|
|
|
+ /// @param [in] C The checker object the option belongs to. Checker options
|
|
|
|
+ /// are retrieved in the following format:
|
|
|
|
+ /// `-analyzer-config <package and checker name>:OptionName=Value.
|
|
/// @param [in] SearchInParents If set to true and the searched option was not
|
|
/// @param [in] SearchInParents If set to true and the searched option was not
|
|
/// specified for the given checker the options for the parent packages will
|
|
/// specified for the given checker the options for the parent packages will
|
|
/// be searched as well. The inner packages take precedence over the outer
|
|
/// be searched as well. The inner packages take precedence over the outer
|
|
/// ones.
|
|
/// ones.
|
|
- int getOptionAsInteger(StringRef Name, int DefaultVal,
|
|
|
|
- const ento::CheckerBase *C = nullptr,
|
|
|
|
- bool SearchInParents = false);
|
|
|
|
-
|
|
|
|
- unsigned getOptionAsUInt(Optional<unsigned> &V, StringRef Name,
|
|
|
|
- unsigned DefaultVal,
|
|
|
|
- const ento::CheckerBase *C = nullptr,
|
|
|
|
- bool SearchInParents = false);
|
|
|
|
|
|
+ int getCheckerIntegerOption(StringRef Name, int DefaultVal,
|
|
|
|
+ const ento::CheckerBase *C,
|
|
|
|
+ bool SearchInParents = false) const;
|
|
|
|
|
|
/// Query an option's string value.
|
|
/// Query an option's string value.
|
|
///
|
|
///
|
|
@@ -309,29 +298,38 @@ public:
|
|
/// @param [in] Name Name for option to retrieve.
|
|
/// @param [in] Name Name for option to retrieve.
|
|
/// @param [in] DefaultVal Default value returned if no such option was
|
|
/// @param [in] DefaultVal Default value returned if no such option was
|
|
/// specified.
|
|
/// specified.
|
|
- /// @param [in] C The optional checker parameter that can be used to restrict
|
|
|
|
- /// the search to the options of this particular checker (and its parents
|
|
|
|
- /// depending on search mode).
|
|
|
|
|
|
+ /// @param [in] C The checker object the option belongs to. Checker options
|
|
|
|
+ /// are retrieved in the following format:
|
|
|
|
+ /// `-analyzer-config <package and checker name>:OptionName=Value.
|
|
/// @param [in] SearchInParents If set to true and the searched option was not
|
|
/// @param [in] SearchInParents If set to true and the searched option was not
|
|
/// specified for the given checker the options for the parent packages will
|
|
/// specified for the given checker the options for the parent packages will
|
|
/// be searched as well. The inner packages take precedence over the outer
|
|
/// be searched as well. The inner packages take precedence over the outer
|
|
/// ones.
|
|
/// ones.
|
|
- StringRef getOptionAsString(StringRef Name, StringRef DefaultVal,
|
|
|
|
- const ento::CheckerBase *C = nullptr,
|
|
|
|
- bool SearchInParents = false);
|
|
|
|
-
|
|
|
|
- StringRef getOptionAsString(Optional<StringRef> &V, StringRef Name,
|
|
|
|
- StringRef DefaultVal,
|
|
|
|
- const ento::CheckerBase *C = nullptr,
|
|
|
|
- bool SearchInParents = false);
|
|
|
|
|
|
+ StringRef getCheckerStringOption(StringRef Name, StringRef DefaultVal,
|
|
|
|
+ const ento::CheckerBase *C,
|
|
|
|
+ bool SearchInParents = false) const;
|
|
|
|
|
|
#define ANALYZER_OPTION_GEN_FN(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL, \
|
|
#define ANALYZER_OPTION_GEN_FN(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL, \
|
|
- CREATE_FN) \
|
|
|
|
- TYPE CREATE_FN();
|
|
|
|
|
|
+ CREATE_FN) \
|
|
|
|
+ TYPE CREATE_FN() { \
|
|
|
|
+ initOption(NAME, CMDFLAG, DEFAULT_VAL); \
|
|
|
|
+ return NAME.getValue(); \
|
|
|
|
+ }
|
|
|
|
|
|
#define ANALYZER_OPTION_GEN_FN_DEPENDS_ON_USER_MODE( \
|
|
#define ANALYZER_OPTION_GEN_FN_DEPENDS_ON_USER_MODE( \
|
|
TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL, DEEP_VAL, CREATE_FN) \
|
|
TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL, DEEP_VAL, CREATE_FN) \
|
|
- TYPE CREATE_FN();
|
|
|
|
|
|
+ TYPE CREATE_FN() { \
|
|
|
|
+ switch (getUserMode()) { \
|
|
|
|
+ case UMK_Shallow: \
|
|
|
|
+ initOption(NAME, CMDFLAG, SHALLOW_VAL); \
|
|
|
|
+ break; \
|
|
|
|
+ case UMK_Deep: \
|
|
|
|
+ initOption(NAME, CMDFLAG, DEEP_VAL); \
|
|
|
|
+ break; \
|
|
|
|
+ } \
|
|
|
|
+ \
|
|
|
|
+ return NAME.getValue(); \
|
|
|
|
+ }
|
|
|
|
|
|
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
|
|
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
|
|
|
|
|