Author: xazax Date: Mon Aug 8 08:41:04 2016 New Revision: 278006 URL: http://llvm.org/viewvc/llvm-project?rev=278006&view=rev Log: [analyzer] Command line option to show enabled checker list.
This patch adds a command line option to list the checkers that were enabled by analyzer-checker and not disabled by -analyzer-disable-checker. It can be very useful to debug long command lines when it is not immediately apparent which checkers are turned on and which checkers are turned off. Differential Revision: https://reviews.llvm.org/D23060 Added: cfe/trunk/test/Analysis/analyzer-enabled-checkers.c Modified: cfe/trunk/include/clang/Driver/CC1Options.td cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerRegistry.h cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp Modified: cfe/trunk/include/clang/Driver/CC1Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=278006&r1=278005&r2=278006&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td (original) +++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Aug 8 08:41:04 2016 @@ -114,6 +114,9 @@ def analyzer_disable_all_checks : Flag<[ def analyzer_checker_help : Flag<["-"], "analyzer-checker-help">, HelpText<"Display the list of analyzer checkers that are available">; +def analyzer_list_enabled_checkers : Flag<["-"], "analyzer-list-enabled-checkers">, + HelpText<"Display the list of enabled analyzer checkers">; + def analyzer_config : Separate<["-"], "analyzer-config">, HelpText<"Choose analyzer options to enable">; Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=278006&r1=278005&r2=278006&view=diff ============================================================================== --- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original) +++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Mon Aug 8 08:41:04 2016 @@ -149,6 +149,7 @@ public: unsigned DisableAllChecks : 1; unsigned ShowCheckerHelp : 1; + unsigned ShowEnabledCheckerList : 1; unsigned AnalyzeAll : 1; unsigned AnalyzerDisplayProgress : 1; unsigned AnalyzeNestedBlocks : 1; @@ -541,6 +542,7 @@ public: AnalysisPurgeOpt(PurgeStmt), DisableAllChecks(0), ShowCheckerHelp(0), + ShowEnabledCheckerList(0), AnalyzeAll(0), AnalyzerDisplayProgress(0), AnalyzeNestedBlocks(0), Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerRegistry.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerRegistry.h?rev=278006&r1=278005&r2=278006&view=diff ============================================================================== --- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerRegistry.h (original) +++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerRegistry.h Mon Aug 8 08:41:04 2016 @@ -127,7 +127,9 @@ public: /// Prints the name and description of all checkers in this registry. /// This output is not intended to be machine-parseable. - void printHelp(raw_ostream &out, size_t maxNameChars = 30) const ; + void printHelp(raw_ostream &out, size_t maxNameChars = 30) const; + void printList(raw_ostream &out, + SmallVectorImpl<CheckerOptInfo> &opts) const; private: mutable CheckerInfoList Checkers; Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h?rev=278006&r1=278005&r2=278006&view=diff ============================================================================== --- cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h (original) +++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/FrontendActions.h Mon Aug 8 08:41:04 2016 @@ -17,6 +17,7 @@ namespace clang { class Stmt; +class AnalyzerOptions; namespace ento { @@ -52,6 +53,8 @@ private: }; void printCheckerHelp(raw_ostream &OS, ArrayRef<std::string> plugins); +void printEnabledCheckerList(raw_ostream &OS, ArrayRef<std::string> plugins, + const AnalyzerOptions &opts); } // end GR namespace Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=278006&r1=278005&r2=278006&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Aug 8 08:41:04 2016 @@ -238,6 +238,7 @@ static bool ParseAnalyzerArgs(AnalyzerOp } Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help); + Opts.ShowEnabledCheckerList = Args.hasArg(OPT_analyzer_list_enabled_checkers); Opts.DisableAllChecks = Args.hasArg(OPT_analyzer_disable_all_checks); Opts.visualizeExplodedGraphWithGraphViz = Modified: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=278006&r1=278005&r2=278006&view=diff ============================================================================== --- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original) +++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp Mon Aug 8 08:41:04 2016 @@ -229,6 +229,11 @@ bool clang::ExecuteCompilerInvocation(Co ento::printCheckerHelp(llvm::outs(), Clang->getFrontendOpts().Plugins); return true; } + if (Clang->getAnalyzerOpts()->ShowEnabledCheckerList) { + ento::printEnabledCheckerList(llvm::outs(), + Clang->getFrontendOpts().Plugins, + *Clang->getAnalyzerOpts()); + } #endif // If there were errors in processing arguments, don't do anything else. Modified: cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp?rev=278006&r1=278005&r2=278006&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/CheckerRegistry.cpp Mon Aug 8 08:41:04 2016 @@ -175,3 +175,22 @@ void CheckerRegistry::printHelp(raw_ostr out << '\n'; } } + +void CheckerRegistry::printList( + raw_ostream &out, SmallVectorImpl<CheckerOptInfo> &opts) const { + std::sort(Checkers.begin(), Checkers.end(), checkerNameLT); + + // Collect checkers enabled by the options. + CheckerInfoSet enabledCheckers; + for (SmallVectorImpl<CheckerOptInfo>::iterator i = opts.begin(), + e = opts.end(); + i != e; ++i) { + collectCheckers(Checkers, Packages, *i, enabledCheckers); + } + + for (CheckerInfoSet::const_iterator i = enabledCheckers.begin(), + e = enabledCheckers.end(); + i != e; ++i) { + out << (*i)->FullName << '\n'; + } +} Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp?rev=278006&r1=278005&r2=278006&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp Mon Aug 8 08:41:04 2016 @@ -101,6 +101,16 @@ void ClangCheckerRegistry::warnIncompati << pluginAPIVersion; } +static SmallVector<CheckerOptInfo, 8> +getCheckerOptList(const AnalyzerOptions &opts) { + SmallVector<CheckerOptInfo, 8> checkerOpts; + for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) { + const std::pair<std::string, bool> &opt = opts.CheckersControlList[i]; + checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second)); + } + return checkerOpts; +} + std::unique_ptr<CheckerManager> ento::createCheckerManager(AnalyzerOptions &opts, const LangOptions &langOpts, ArrayRef<std::string> plugins, @@ -108,11 +118,7 @@ ento::createCheckerManager(AnalyzerOptio std::unique_ptr<CheckerManager> checkerMgr( new CheckerManager(langOpts, &opts)); - SmallVector<CheckerOptInfo, 8> checkerOpts; - for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) { - const std::pair<std::string, bool> &opt = opts.CheckersControlList[i]; - checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second)); - } + SmallVector<CheckerOptInfo, 8> checkerOpts = getCheckerOptList(opts); ClangCheckerRegistry allCheckers(plugins, &diags); allCheckers.initializeManager(*checkerMgr, checkerOpts); @@ -137,3 +143,12 @@ void ento::printCheckerHelp(raw_ostream ClangCheckerRegistry(plugins).printHelp(out); } + +void ento::printEnabledCheckerList(raw_ostream &out, + ArrayRef<std::string> plugins, + const AnalyzerOptions &opts) { + out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n"; + + SmallVector<CheckerOptInfo, 8> checkerOpts = getCheckerOptList(opts); + ClangCheckerRegistry(plugins).printList(out, checkerOpts); +} Added: cfe/trunk/test/Analysis/analyzer-enabled-checkers.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-enabled-checkers.c?rev=278006&view=auto ============================================================================== --- cfe/trunk/test/Analysis/analyzer-enabled-checkers.c (added) +++ cfe/trunk/test/Analysis/analyzer-enabled-checkers.c Mon Aug 8 08:41:04 2016 @@ -0,0 +1,20 @@ +// RUN: %clang -target x86_64-apple-darwin10 --analyze %s -o /dev/null -Xclang -analyzer-checker=core -Xclang -analyzer-list-enabled-checkers > %t 2>&1 +// RUN: FileCheck --input-file=%t %s + +// CHECK: OVERVIEW: Clang Static Analyzer Enabled Checkers List +// CHECK: core.CallAndMessage +// CHECK: core.DivideZero +// CHECK: core.DynamicTypePropagation +// CHECK: core.NonNullParamChecker +// CHECK: core.NullDereference +// CHECK: core.StackAddressEscape +// CHECK: core.UndefinedBinaryOperatorResult +// CHECK: core.VLASize +// CHECK: core.builtin.BuiltinFunctions +// CHECK: core.builtin.NoReturnFunctions +// CHECK: core.uninitialized.ArraySubscript +// CHECK: core.uninitialized.Assign +// CHECK: core.uninitialized.Branch +// CHECK: core.uninitialized.CapturedBlockVariable +// CHECK: core.uninitialized.UndefReturn + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits