Don't call exit from cl::PrintHelpMessage.
Most callers were not expecting the exit(0) and trying to exit with a
different value.
This also adds back the call to cl::PrintHelpMessage in llvm-ar.
llvm-svn: 312761
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 22d1819..2357a12 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -1762,8 +1762,6 @@
/// This function just prints the help message, exactly the same way as if the
/// -help or -help-hidden option had been given on the command line.
///
-/// NOTE: THIS FUNCTION TERMINATES THE PROGRAM!
-///
/// \param Hidden if true will print hidden options
/// \param Categorized if true print options in categories
void PrintHelpMessage(bool Hidden = false, bool Categorized = false);
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 8fb0121..0d662cb 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -1758,7 +1758,13 @@
void operator=(bool Value) {
if (!Value)
return;
+ printHelp();
+ // Halt the program since help information was printed
+ exit(0);
+ }
+
+ void printHelp() {
SubCommand *Sub = GlobalParser->getActiveSubCommand();
auto &OptionsMap = Sub->OptionsMap;
auto &PositionalOpts = Sub->PositionalOpts;
@@ -1826,9 +1832,6 @@
for (auto I : GlobalParser->MoreHelp)
outs() << I;
GlobalParser->MoreHelp.clear();
-
- // Halt the program since help information was printed
- exit(0);
}
};
@@ -2098,21 +2101,14 @@
// Utility function for printing the help message.
void cl::PrintHelpMessage(bool Hidden, bool Categorized) {
- // This looks weird, but it actually prints the help message. The Printers are
- // types of HelpPrinter and the help gets printed when its operator= is
- // invoked. That's because the "normal" usages of the help printer is to be
- // assigned true/false depending on whether -help or -help-hidden was given or
- // not. Since we're circumventing that we have to make it look like -help or
- // -help-hidden were given, so we assign true.
-
if (!Hidden && !Categorized)
- UncategorizedNormalPrinter = true;
+ UncategorizedNormalPrinter.printHelp();
else if (!Hidden && Categorized)
- CategorizedNormalPrinter = true;
+ CategorizedNormalPrinter.printHelp();
else if (Hidden && !Categorized)
- UncategorizedHiddenPrinter = true;
+ UncategorizedHiddenPrinter.printHelp();
else
- CategorizedHiddenPrinter = true;
+ CategorizedHiddenPrinter.printHelp();
}
/// Utility function for printing version number.
diff --git a/llvm/test/tools/llvm-ar/invalid-command-line.test b/llvm/test/tools/llvm-ar/invalid-command-line.test
index 44a3728..e13f54c 100644
--- a/llvm/test/tools/llvm-ar/invalid-command-line.test
+++ b/llvm/test/tools/llvm-ar/invalid-command-line.test
@@ -2,3 +2,4 @@
RUN: not llvm-ar e 2>&1 | FileCheck %s
CHECK: unknown option e.
+CHECK: OVERVIEW: LLVM Archiver (llvm-ar)
diff --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp
index 1ce0aef..51eb3ff 100644
--- a/llvm/tools/dsymutil/dsymutil.cpp
+++ b/llvm/tools/dsymutil/dsymutil.cpp
@@ -253,8 +253,10 @@
"for the executable <input file> by using debug symbols information\n"
"contained in its symbol table.\n");
- if (Help)
+ if (Help) {
PrintHelpMessage();
+ return 0;
+ }
if (Version) {
llvm::cl::PrintVersionMessage();
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 65c6198..03655cb 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -54,8 +54,7 @@
// Show the error message and exit.
LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) {
errs() << ToolName << ": " << Error << ".\n";
- // FIXME: Other ar implementations will print the command line help in here.
- // Unfortunately cl::PrintHelpMessage() exits with 0, so we can't call it.
+ cl::PrintHelpMessage();
exit(1);
}
diff --git a/llvm/tools/llvm-opt-report/OptReport.cpp b/llvm/tools/llvm-opt-report/OptReport.cpp
index 4f45dd9..3c6115d 100644
--- a/llvm/tools/llvm-opt-report/OptReport.cpp
+++ b/llvm/tools/llvm-opt-report/OptReport.cpp
@@ -514,8 +514,10 @@
"A tool to generate an optimization report from YAML optimization"
" record files.\n");
- if (Help)
+ if (Help) {
cl::PrintHelpMessage();
+ return 0;
+ }
LocationInfoTy LocationInfo;
if (!readLocationInfo(LocationInfo))
diff --git a/llvm/tools/llvm-xray/llvm-xray.cc b/llvm/tools/llvm-xray/llvm-xray.cc
index 98303e7..34c453a 100644
--- a/llvm/tools/llvm-xray/llvm-xray.cc
+++ b/llvm/tools/llvm-xray/llvm-xray.cc
@@ -46,4 +46,5 @@
// If all else fails, we still print the usage message.
cl::PrintHelpMessage(false, true);
+ return 0;
}