pfultz2 updated this revision to Diff 145229.
pfultz2 added a comment.
Moved flag for alpha checks to the ClangTidyContext
https://reviews.llvm.org/D46159
Files:
clang-tidy/ClangTidy.cpp
clang-tidy/ClangTidy.h
clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tidy/tool/ClangTidyMain.cpp
test/clang-tidy/enable-alpha-checks.cpp
Index: test/clang-tidy/enable-alpha-checks.cpp
===================================================================
--- /dev/null
+++ test/clang-tidy/enable-alpha-checks.cpp
@@ -0,0 +1,6 @@
+// Check if '-allow-enabling-analyzer-alpha-checkers' is visible for users
+// RUN: clang-tidy -help | not grep 'allow-enabling-analyzer-alpha-checkers'
+
+// Check if '-allow-enabling-analyzer-alpha-checkers' enables alpha checks.
+// RUN: clang-tidy -checks=* -list-checks | not grep 'clang-analyzer-alpha'
+// RUN: clang-tidy -checks=* -list-checks -allow-enabling-analyzer-alpha-checkers | grep 'clang-analyzer-alpha'
Index: clang-tidy/tool/ClangTidyMain.cpp
===================================================================
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -192,6 +192,14 @@
cl::init(false),
cl::cat(ClangTidyCategory));
+/// This option allows enabling alpha checkers from the static analyzer, that
+/// are experimental. This option is set to false and not visible in help,
+/// because it is highly not recommended for users.
+static cl::opt<bool>
+ AllowEnablingAnalyzerAlphaCheckers("allow-enabling-analyzer-alpha-checkers",
+ cl::init(false), cl::Hidden,
+ cl::cat(ClangTidyCategory));
+
static cl::opt<std::string> ExportFixes("export-fixes", cl::desc(R"(
YAML file to store suggested fixes in. The
stored fixes can be applied to the input source
@@ -388,7 +396,8 @@
<< EC.message() << "\n";
}
ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
- std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions);
+ std::vector<std::string> EnabledChecks =
+ getCheckNames(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);
if (ExplainConfig) {
// FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
@@ -419,7 +428,8 @@
}
if (DumpConfig) {
- EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions);
+ EffectiveOptions.CheckOptions =
+ getCheckOptions(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);
llvm::outs() << configurationAsText(
ClangTidyOptions::getDefaults().mergeWith(
EffectiveOptions))
@@ -444,7 +454,8 @@
llvm::InitializeAllTargetMCs();
llvm::InitializeAllAsmParsers();
- ClangTidyContext Context(std::move(OwningOptionsProvider));
+ ClangTidyContext Context(std::move(OwningOptionsProvider),
+ AllowEnablingAnalyzerAlphaCheckers);
runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS,
EnableCheckProfile ? &Profile : nullptr);
ArrayRef<ClangTidyError> Errors = Context.getErrors();
Index: clang-tidy/ClangTidyDiagnosticConsumer.h
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -104,7 +104,8 @@
class ClangTidyContext {
public:
/// \brief Initializes \c ClangTidyContext instance.
- ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider);
+ ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
+ bool AllowEnablingAnalyzerAlphaCheckers = false);
~ClangTidyContext();
@@ -186,6 +187,11 @@
return CurrentBuildDirectory;
}
+ /// \brief Turns on experimental alpha checkers from the static analyzer.
+ bool isAlphaChecksAllowed() const {
+ return AllowEnablingAnalyzerAlphaCheckers;
+ }
+
private:
// Calls setDiagnosticsEngine() and storeError().
friend class ClangTidyDiagnosticConsumer;
@@ -217,6 +223,8 @@
llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
ProfileData *Profile;
+
+ bool AllowEnablingAnalyzerAlphaCheckers;
};
/// \brief A diagnostic consumer that turns each \c Diagnostic into a
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -177,9 +177,11 @@
};
ClangTidyContext::ClangTidyContext(
- std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider)
+ std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
+ bool AllowEnablingAnalyzerAlphaCheckers)
: DiagEngine(nullptr), OptionsProvider(std::move(OptionsProvider)),
- Profile(nullptr) {
+ Profile(nullptr),
+ AllowEnablingAnalyzerAlphaCheckers(AllowEnablingAnalyzerAlphaCheckers) {
// Before the first translation unit we can get errors related to command-line
// parsing, use empty string for the file name in this case.
setCurrentFile("");
Index: clang-tidy/ClangTidy.h
===================================================================
--- clang-tidy/ClangTidy.h
+++ clang-tidy/ClangTidy.h
@@ -210,15 +210,18 @@
/// \brief Fills the list of check names that are enabled when the provided
/// filters are applied.
-std::vector<std::string> getCheckNames(const ClangTidyOptions &Options);
+std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
+ bool AllowEnablingAnalyzerAlphaCheckers);
/// \brief Returns the effective check-specific options.
///
/// The method configures ClangTidy with the specified \p Options and collects
/// effective options from all created checks. The returned set of options
/// includes default check-specific options for all keys not overridden by \p
/// Options.
-ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options);
+ClangTidyOptions::OptionMap
+getCheckOptions(const ClangTidyOptions &Options,
+ bool AllowEnablingAnalyzerAlphaCheckers);
/// \brief Run a set of clang-tidy checks on a set of files.
///
Index: clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -303,11 +303,12 @@
typedef std::vector<std::pair<std::string, bool>> CheckersList;
-static CheckersList getCheckersControlList(ClangTidyContext &Context) {
+static CheckersList getCheckersControlList(ClangTidyContext &Context,
+ bool IncludeExperimental) {
CheckersList List;
const auto &RegisteredCheckers =
- AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/false);
+ AnalyzerOptions::getRegisteredCheckers(IncludeExperimental);
bool AnalyzerChecksEnabled = false;
for (StringRef CheckName : RegisteredCheckers) {
std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());
@@ -374,7 +375,8 @@
AnalyzerOptions->Config["cfg-temporary-dtors"] =
Context.getOptions().AnalyzeTemporaryDtors ? "true" : "false";
- AnalyzerOptions->CheckersControlList = getCheckersControlList(Context);
+ AnalyzerOptions->CheckersControlList =
+ getCheckersControlList(Context, Context.isAlphaChecksAllowed());
if (!AnalyzerOptions->CheckersControlList.empty()) {
setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
@@ -398,7 +400,8 @@
CheckNames.push_back(CheckFactory.first);
}
- for (const auto &AnalyzerCheck : getCheckersControlList(Context))
+ for (const auto &AnalyzerCheck :
+ getCheckersControlList(Context, Context.isAlphaChecksAllowed()))
CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
std::sort(CheckNames.begin(), CheckNames.end());
@@ -457,18 +460,24 @@
store(Options, LocalName, llvm::itostr(Value));
}
-std::vector<std::string> getCheckNames(const ClangTidyOptions &Options) {
+std::vector<std::string>
+getCheckNames(const ClangTidyOptions &Options,
+ bool AllowEnablingAnalyzerAlphaCheckers) {
clang::tidy::ClangTidyContext Context(
llvm::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
- Options));
+ Options),
+ AllowEnablingAnalyzerAlphaCheckers);
ClangTidyASTConsumerFactory Factory(Context);
return Factory.getCheckNames();
}
-ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options) {
+ClangTidyOptions::OptionMap
+getCheckOptions(const ClangTidyOptions &Options,
+ bool AllowEnablingAnalyzerAlphaCheckers) {
clang::tidy::ClangTidyContext Context(
llvm::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(),
- Options));
+ Options),
+ AllowEnablingAnalyzerAlphaCheckers);
ClangTidyASTConsumerFactory Factory(Context);
return Factory.getCheckOptions();
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits