Index: include/clang/Driver/CC1Options.td =================================================================== --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -114,6 +114,9 @@ def analyzer_checker_help : Flag<["-"], "analyzer-checker-help">, HelpText<"Display the list of analyzer checkers that are available">; +def analyzer_checker_list_enabled : Flag<["-"], "analyzer-checker-list-enabled">, + HelpText<"Display the list of enabled analyzer checkers">; + def analyzer_config : Separate<["-"], "analyzer-config">, HelpText<"Choose analyzer options to enable">; Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h =================================================================== --- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -149,6 +149,7 @@ unsigned DisableAllChecks : 1; unsigned ShowCheckerHelp : 1; + unsigned ShowEnabledCheckerList : 1; unsigned AnalyzeAll : 1; unsigned AnalyzerDisplayProgress : 1; unsigned AnalyzeNestedBlocks : 1; @@ -541,6 +542,7 @@ AnalysisPurgeOpt(PurgeStmt), DisableAllChecks(0), ShowCheckerHelp(0), + ShowEnabledCheckerList(0), AnalyzeAll(0), AnalyzerDisplayProgress(0), AnalyzeNestedBlocks(0), Index: include/clang/StaticAnalyzer/Core/CheckerRegistry.h =================================================================== --- include/clang/StaticAnalyzer/Core/CheckerRegistry.h +++ include/clang/StaticAnalyzer/Core/CheckerRegistry.h @@ -127,7 +127,9 @@ /// 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 &opts) const; private: mutable CheckerInfoList Checkers; Index: include/clang/StaticAnalyzer/Frontend/FrontendActions.h =================================================================== --- include/clang/StaticAnalyzer/Frontend/FrontendActions.h +++ include/clang/StaticAnalyzer/Frontend/FrontendActions.h @@ -17,6 +17,7 @@ namespace clang { class Stmt; +class AnalyzerOptions; namespace ento { @@ -52,6 +53,8 @@ }; void printCheckerHelp(raw_ostream &OS, ArrayRef plugins); +void printEnabledCheckerList(raw_ostream &OS, ArrayRef plugins, + const AnalyzerOptions &opts); } // end GR namespace Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -238,6 +238,7 @@ } Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help); + Opts.ShowEnabledCheckerList = Args.hasArg(OPT_analyzer_checker_list_enabled); Opts.DisableAllChecks = Args.hasArg(OPT_analyzer_disable_all_checks); Opts.visualizeExplodedGraphWithGraphViz = Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp =================================================================== --- lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -229,6 +229,11 @@ 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. Index: lib/StaticAnalyzer/Core/CheckerRegistry.cpp =================================================================== --- lib/StaticAnalyzer/Core/CheckerRegistry.cpp +++ lib/StaticAnalyzer/Core/CheckerRegistry.cpp @@ -175,3 +175,22 @@ out << '\n'; } } + +void CheckerRegistry::printList( + raw_ostream &out, SmallVectorImpl &opts) const { + std::sort(Checkers.begin(), Checkers.end(), checkerNameLT); + + // Collect checkers enabled by the options. + CheckerInfoSet enabledCheckers; + for (SmallVectorImpl::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'; + } +} Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp =================================================================== --- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp +++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp @@ -101,6 +101,16 @@ << pluginAPIVersion; } +static SmallVector +getCheckerOptList(const AnalyzerOptions &opts) { + SmallVector checkerOpts; + for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) { + const std::pair &opt = opts.CheckersControlList[i]; + checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second)); + } + return checkerOpts; +} + std::unique_ptr ento::createCheckerManager(AnalyzerOptions &opts, const LangOptions &langOpts, ArrayRef plugins, @@ -108,11 +118,7 @@ std::unique_ptr checkerMgr( new CheckerManager(langOpts, &opts)); - SmallVector checkerOpts; - for (unsigned i = 0, e = opts.CheckersControlList.size(); i != e; ++i) { - const std::pair &opt = opts.CheckersControlList[i]; - checkerOpts.push_back(CheckerOptInfo(opt.first.c_str(), opt.second)); - } + SmallVector checkerOpts = getCheckerOptList(opts); ClangCheckerRegistry allCheckers(plugins, &diags); allCheckers.initializeManager(*checkerMgr, checkerOpts); @@ -137,3 +143,12 @@ ClangCheckerRegistry(plugins).printHelp(out); } + +void ento::printEnabledCheckerList(raw_ostream &out, + ArrayRef plugins, + const AnalyzerOptions &opts) { + out << "OVERVIEW: Clang Static Analyzer Enabled Checkers List\n\n"; + + SmallVector checkerOpts = getCheckerOptList(opts); + ClangCheckerRegistry(plugins).printList(out, checkerOpts); +} Index: test/Analysis/analyzer-enabled-checkers.c =================================================================== --- /dev/null +++ test/Analysis/analyzer-enabled-checkers.c @@ -0,0 +1,29 @@ +// RUN: %clang -target x86_64-apple-darwin10 --analyze %s -o /dev/null -Xclang -analyzer-checker=core -Xclang -analyzer-checker-list-enabled > %t 2>&1 +// RUN: FileCheck --input-file=%t %s + +void bar() {} +void foo() { + // Call bar 33 times so max-times-inline-large is met and + // min-blocks-for-inline-large is checked + for (int i = 0; i < 34; ++i) { + bar(); + } +} + +// 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 +