Prazek updated this revision to Diff 84448. Prazek added a comment. reformat
https://reviews.llvm.org/D28729 Files: clang-tidy/ClangTidy.cpp clang-tidy/ClangTidyOptions.cpp clang-tidy/ClangTidyOptions.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,2 @@ +// RUN: clang-tidy -checks=* -list-checks | not grep 'clang-analyzer-alpha' +// RUN: clang-tidy -checks=* -list-checks -enable-alpha-checks | grep 'clang-analyzer-alpha' Index: clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tidy/tool/ClangTidyMain.cpp +++ clang-tidy/tool/ClangTidyMain.cpp @@ -180,6 +180,14 @@ cl::init(false), cl::cat(ClangTidyCategory)); +static cl::opt<bool> EnableAlphaChecks("enable-alpha-checks", cl::desc(R"( +Enable experimental clang-analyzer-alpha-* checks. +This option overrides the value read from a +.clang-tidy file. +)"), + cl::init(false), + 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 @@ -272,6 +280,7 @@ DefaultOptions.HeaderFilterRegex = HeaderFilter; DefaultOptions.SystemHeaders = SystemHeaders; DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors; + DefaultOptions.EnableAlphaChecks = EnableAlphaChecks; DefaultOptions.User = llvm::sys::Process::GetEnv("USER"); // USERNAME is used on Windows. if (!DefaultOptions.User) Index: clang-tidy/ClangTidyOptions.h =================================================================== --- clang-tidy/ClangTidyOptions.h +++ clang-tidy/ClangTidyOptions.h @@ -75,6 +75,9 @@ /// \brief Turns on temporary destructor-based analysis. llvm::Optional<bool> AnalyzeTemporaryDtors; + /// \brief Turns on experimental alpha checkers from static-analyzer. + llvm::Optional<bool> EnableAlphaChecks; + /// \brief Specifies the name or e-mail of the user running clang-tidy. /// /// This option is used, for example, to place the correct user name in TODO() Index: clang-tidy/ClangTidyOptions.cpp =================================================================== --- clang-tidy/ClangTidyOptions.cpp +++ clang-tidy/ClangTidyOptions.cpp @@ -89,6 +89,7 @@ IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors); IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex); IO.mapOptional("AnalyzeTemporaryDtors", Options.AnalyzeTemporaryDtors); + IO.mapOptional("EnableAlphaChecks", Options.EnableAlphaChecks); IO.mapOptional("User", Options.User); IO.mapOptional("CheckOptions", NOpts->Options); IO.mapOptional("ExtraArgs", Options.ExtraArgs); @@ -109,6 +110,7 @@ Options.HeaderFilterRegex = ""; Options.SystemHeaders = false; Options.AnalyzeTemporaryDtors = false; + Options.EnableAlphaChecks = false; Options.User = llvm::None; for (ClangTidyModuleRegistry::iterator I = ClangTidyModuleRegistry::begin(), E = ClangTidyModuleRegistry::end(); @@ -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.User, Other.User); mergeVectors(Result.ExtraArgs, Other.ExtraArgs); mergeVectors(Result.ExtraArgsBefore, Other.ExtraArgsBefore); Index: clang-tidy/ClangTidy.cpp =================================================================== --- clang-tidy/ClangTidy.cpp +++ clang-tidy/ClangTidy.cpp @@ -289,11 +289,12 @@ typedef std::vector<std::pair<std::string, bool>> CheckersList; -static CheckersList getCheckersControlList(GlobList &Filter) { +static CheckersList getCheckersControlList(GlobList &Filter, + 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()); @@ -359,7 +360,8 @@ Context.getOptions().AnalyzeTemporaryDtors ? "true" : "false"; GlobList &Filter = Context.getChecksFilter(); - AnalyzerOptions->CheckersControlList = getCheckersControlList(Filter); + AnalyzerOptions->CheckersControlList = + getCheckersControlList(Filter, *Context.getOptions().EnableAlphaChecks); if (!AnalyzerOptions->CheckersControlList.empty()) { setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions); AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel; @@ -384,7 +386,8 @@ CheckNames.push_back(CheckFactory.first); } - for (const auto &AnalyzerCheck : getCheckersControlList(Filter)) + for (const auto &AnalyzerCheck : + getCheckersControlList(Filter, *Context.getOptions().EnableAlphaChecks)) CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first); std::sort(CheckNames.begin(), CheckNames.end());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits