Index: clang-tidy/ClangTidy.cpp =================================================================== --- clang-tidy/ClangTidy.cpp +++ clang-tidy/ClangTidy.cpp @@ -303,11 +303,12 @@ typedef std::vector> 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.getOptions().EnableAlphaChecks); 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.getOptions().EnableAlphaChecks)) CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first); std::sort(CheckNames.begin(), CheckNames.end()); Index: clang-tidy/ClangTidyOptions.h =================================================================== --- clang-tidy/ClangTidyOptions.h +++ clang-tidy/ClangTidyOptions.h @@ -77,6 +77,9 @@ /// \brief Turns on temporary destructor-based analysis. llvm::Optional AnalyzeTemporaryDtors; + /// \brief Turns on experimental alpha checkers from the static analyzer. + llvm::Optional EnableAlphaChecks; + /// \brief Format code around applied fixes with clang-format using this /// style. /// Index: clang-tidy/ClangTidyOptions.cpp =================================================================== --- clang-tidy/ClangTidyOptions.cpp +++ clang-tidy/ClangTidyOptions.cpp @@ -87,6 +87,7 @@ IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors); IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex); IO.mapOptional("AnalyzeTemporaryDtors", Options.AnalyzeTemporaryDtors); + IO.mapOptional("EnableAlphaChecks", Options.EnableAlphaChecks); IO.mapOptional("FormatStyle", Options.FormatStyle); IO.mapOptional("User", Options.User); IO.mapOptional("CheckOptions", NOpts->Options); @@ -108,6 +109,7 @@ Options.HeaderFilterRegex = ""; Options.SystemHeaders = false; Options.AnalyzeTemporaryDtors = false; + Options.EnableAlphaChecks = false; Options.FormatStyle = "none"; Options.User = llvm::None; for (ClangTidyModuleRegistry::iterator I = ClangTidyModuleRegistry::begin(), @@ -148,6 +150,7 @@ overrideValue(Result.HeaderFilterRegex, Other.HeaderFilterRegex); overrideValue(Result.SystemHeaders, Other.SystemHeaders); overrideValue(Result.AnalyzeTemporaryDtors, Other.AnalyzeTemporaryDtors); + overrideValue(Result.EnableAlphaChecks, Other.EnableAlphaChecks); overrideValue(Result.FormatStyle, Other.FormatStyle); overrideValue(Result.User, Other.User); mergeVectors(Result.ExtraArgs, Other.ExtraArgs); Index: clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tidy/tool/ClangTidyMain.cpp +++ clang-tidy/tool/ClangTidyMain.cpp @@ -192,6 +192,12 @@ cl::init(false), cl::cat(ClangTidyCategory)); +/// This option Enables 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 EnableAlphaChecks("enable-alpha-checks", cl::init(false), + cl::Hidden, cl::cat(ClangTidyCategory)); + static cl::opt ExportFixes("export-fixes", cl::desc(R"( YAML file to store suggested fixes in. The stored fixes can be applied to the input source @@ -301,6 +307,7 @@ DefaultOptions.HeaderFilterRegex = HeaderFilter; DefaultOptions.SystemHeaders = SystemHeaders; DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors; + DefaultOptions.EnableAlphaChecks = EnableAlphaChecks; DefaultOptions.FormatStyle = FormatStyle; DefaultOptions.User = llvm::sys::Process::GetEnv("USER"); // USERNAME is used on Windows. Index: test/clang-tidy/enable-alpha-checks.cpp =================================================================== --- /dev/null +++ test/clang-tidy/enable-alpha-checks.cpp @@ -0,0 +1,6 @@ +// Check if '-enable-alpha-checks' is visible for users +// RUN: clang-tidy -help | not grep 'enable-alpha-checks' + +// Check if '-enable-alpha-checks' enables alpha checks. +// RUN: clang-tidy -checks=* -list-checks | not grep 'clang-analyzer-alpha' +// RUN: clang-tidy -checks=* -list-checks -enable-alpha-checks | grep 'clang-analyzer-alpha'