summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp1
-rw-r--r--clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp10
-rw-r--r--clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp32
-rw-r--r--clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp51
-rw-r--r--clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp51
5 files changed, 99 insertions, 46 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 7cdc050e467..877e70b6616 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -286,6 +286,7 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help);
Opts.ShowCheckerHelpHidden = Args.hasArg(OPT_analyzer_checker_help_hidden);
+ Opts.ShowCheckerOptionList = Args.hasArg(OPT_analyzer_checker_option_help);
Opts.ShowConfigOptionsList = Args.hasArg(OPT_analyzer_config_help);
Opts.ShowEnabledCheckerList = Args.hasArg(OPT_analyzer_list_enabled_checkers);
Opts.ShouldEmitErrorsOnInvalidConfigValue =
diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index f77a865efa7..27690be777b 100644
--- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -247,6 +247,16 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
return true;
}
+ // Honor -analyzer-checker-option-help.
+ if (Clang->getAnalyzerOpts()->ShowCheckerOptionList) {
+ ento::printCheckerConfigList(llvm::outs(),
+ Clang->getFrontendOpts().Plugins,
+ *Clang->getAnalyzerOpts(),
+ Clang->getDiagnostics(),
+ Clang->getLangOpts());
+ return true;
+ }
+
// Honor -analyzer-list-enabled-checkers.
if (AnOpts.ShowEnabledCheckerList) {
ento::printEnabledCheckerList(llvm::outs(),
diff --git a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
index 68b2c052305..71abe2ae6c0 100644
--- a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -19,6 +19,7 @@
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstddef>
@@ -48,6 +49,37 @@ AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental /* = false */) {
return Result;
}
+void AnalyzerOptions::printFormattedEntry(
+ llvm::raw_ostream &Out,
+ std::pair<StringRef, StringRef> EntryDescPair,
+ size_t InitialPad, size_t EntryWidth, size_t MinLineWidth) {
+
+ llvm::formatted_raw_ostream FOut(Out);
+
+ const size_t PadForDesc = InitialPad + EntryWidth;
+
+ FOut.PadToColumn(InitialPad) << EntryDescPair.first;
+ // If the buffer's length is greater then PadForDesc, print a newline.
+ if (FOut.getColumn() > PadForDesc)
+ FOut << '\n';
+
+ FOut.PadToColumn(PadForDesc);
+
+ if (MinLineWidth == 0) {
+ FOut << EntryDescPair.second;
+ return;
+ }
+
+ for (char C : EntryDescPair.second) {
+ if (FOut.getColumn() > MinLineWidth && C == ' ') {
+ FOut << '\n';
+ FOut.PadToColumn(PadForDesc);
+ continue;
+ }
+ FOut << C;
+ }
+}
+
ExplorationStrategyKind
AnalyzerOptions::getExplorationStrategy() const {
auto K =
diff --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
index 4ad362fe1e3..1e45ee96145 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
@@ -18,7 +18,6 @@
#include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
#include "clang/StaticAnalyzer/Frontend/FrontendActions.h"
#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>
@@ -65,17 +64,20 @@ void ento::printEnabledCheckerList(raw_ostream &out,
.printEnabledCheckerList(out);
}
+void ento::printCheckerConfigList(raw_ostream &OS,
+ ArrayRef<std::string> plugins,
+ AnalyzerOptions &opts,
+ DiagnosticsEngine &diags,
+ const LangOptions &LangOpts) {
+ CheckerRegistry(plugins, diags, opts, LangOpts)
+ .printCheckerOptionList(OS);
+}
+
void ento::printAnalyzerConfigList(raw_ostream &out) {
out << "OVERVIEW: Clang Static Analyzer -analyzer-config Option List\n\n";
- out << "USAGE: clang -cc1 [CLANG_OPTIONS] -analyzer-config "
- "<OPTION1=VALUE,OPTION2=VALUE,...>\n\n";
- out << " clang -cc1 [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, "
- "-analyzer-config OPTION2=VALUE, ...\n\n";
- out << " clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang"
- "<OPTION1=VALUE,OPTION2=VALUE,...>\n\n";
- out << " clang [CLANG_OPTIONS] -Xclang -analyzer-config -Xclang "
- "OPTION1=VALUE, -Xclang -analyzer-config -Xclang "
- "OPTION2=VALUE, ...\n\n";
+ out << "USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>\n\n";
+ out << " -analyzer-config OPTION1=VALUE, -analyzer-config "
+ "OPTION2=VALUE, ...\n\n";
out << "OPTIONS:\n\n";
using OptionAndDescriptionTy = std::pair<StringRef, std::string>;
@@ -109,31 +111,10 @@ void ento::printAnalyzerConfigList(raw_ostream &out) {
return LHS.first < RHS.first;
});
- constexpr size_t MinLineWidth = 70;
- constexpr size_t PadForOpt = 2;
- constexpr size_t OptionWidth = 30;
- constexpr size_t PadForDesc = PadForOpt + OptionWidth;
- static_assert(MinLineWidth > PadForDesc, "MinLineWidth must be greater!");
-
- llvm::formatted_raw_ostream FOut(out);
-
for (const auto &Pair : PrintableOptions) {
- FOut.PadToColumn(PadForOpt) << Pair.first;
-
- // If the buffer's length is greater then PadForDesc, print a newline.
- if (FOut.getColumn() > PadForDesc)
- FOut << '\n';
-
- FOut.PadToColumn(PadForDesc);
-
- for (char C : Pair.second) {
- if (FOut.getColumn() > MinLineWidth && C == ' ') {
- FOut << '\n';
- FOut.PadToColumn(PadForDesc);
- continue;
- }
- FOut << C;
- }
- FOut << "\n\n";
+ AnalyzerOptions::printFormattedEntry(out, Pair, /*InitialPad*/ 2,
+ /*EntryWidth*/ 30,
+ /*MinLineWidth*/ 70);
+ out << "\n\n";
}
}
diff --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
index d41ca0a8f32..d405933ca65 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -518,17 +518,8 @@ void CheckerRegistry::printCheckerWithDescList(raw_ostream &Out,
if (!AnOpts.ShowCheckerHelpHidden && Checker.IsHidden)
continue;
- Out.indent(InitialPad) << Checker.FullName;
-
- int Pad = OptionFieldWidth - Checker.FullName.size();
-
- // Break on long option names.
- if (Pad < 0) {
- Out << '\n';
- Pad = OptionFieldWidth + InitialPad;
- }
- Out.indent(Pad + 2) << Checker.Desc;
-
+ AnalyzerOptions::printFormattedEntry(Out, {Checker.FullName, Checker.Desc},
+ InitialPad, OptionFieldWidth);
Out << '\n';
}
}
@@ -540,3 +531,41 @@ void CheckerRegistry::printEnabledCheckerList(raw_ostream &Out) const {
for (const auto *i : EnabledCheckers)
Out << i->FullName << '\n';
}
+
+void CheckerRegistry::printCheckerOptionList(raw_ostream &Out) const {
+ Out << "OVERVIEW: Clang Static Analyzer Checker and Package Option List\n\n";
+ Out << "USAGE: -analyzer-config <OPTION1=VALUE,OPTION2=VALUE,...>\n\n";
+ Out << " -analyzer-config OPTION1=VALUE, -analyzer-config "
+ "OPTION2=VALUE, ...\n\n";
+ Out << "OPTIONS:\n\n";
+
+ std::multimap<StringRef, const CmdLineOption &> OptionMap;
+
+ for (const CheckerInfo &Checker : Checkers) {
+ for (const CmdLineOption &Option : Checker.CmdLineOptions) {
+ OptionMap.insert({Checker.FullName, Option});
+ }
+ }
+
+ for (const PackageInfo &Package : Packages) {
+ for (const CmdLineOption &Option : Package.CmdLineOptions) {
+ OptionMap.insert({Package.FullName, Option});
+ }
+ }
+
+ for (const std::pair<StringRef, const CmdLineOption &> &Entry : OptionMap) {
+ const CmdLineOption &Option = Entry.second;
+ std::string FullOption = (Entry.first + ":" + Option.OptionName).str();
+
+ std::string Desc =
+ ("(" + Option.OptionType + ") " + Option.Description + " (default: " +
+ (Option.DefaultValStr.empty() ? "\"\"" : Option.DefaultValStr) + ")")
+ .str();
+
+ AnalyzerOptions::printFormattedEntry(Out, {FullOption, Desc},
+ /*InitialPad*/ 2,
+ /*EntryWidth*/ 50,
+ /*MinLineWidth*/ 90);
+ Out << "\n\n";
+ }
+}
OpenPOWER on IntegriCloud