llvm.org GIT mirror llvm / 14fde14
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312761 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 1 year, 11 months ago
7 changed file(s) with 20 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
17601760
17611761 /// This function just prints the help message, exactly the same way as if the
17621762 /// -help or -help-hidden option had been given on the command line.
1763 ///
1764 /// NOTE: THIS FUNCTION TERMINATES THE PROGRAM!
17651763 ///
17661764 /// \param Hidden if true will print hidden options
17671765 /// \param Categorized if true print options in categories
17571757 void operator=(bool Value) {
17581758 if (!Value)
17591759 return;
1760
1760 printHelp();
1761
1762 // Halt the program since help information was printed
1763 exit(0);
1764 }
1765
1766 void printHelp() {
17611767 SubCommand *Sub = GlobalParser->getActiveSubCommand();
17621768 auto &OptionsMap = Sub->OptionsMap;
17631769 auto &PositionalOpts = Sub->PositionalOpts;
18251831 for (auto I : GlobalParser->MoreHelp)
18261832 outs() << I;
18271833 GlobalParser->MoreHelp.clear();
1828
1829 // Halt the program since help information was printed
1830 exit(0);
18311834 }
18321835 };
18331836
20972100
20982101 // Utility function for printing the help message.
20992102 void cl::PrintHelpMessage(bool Hidden, bool Categorized) {
2100 // This looks weird, but it actually prints the help message. The Printers are
2101 // types of HelpPrinter and the help gets printed when its operator= is
2102 // invoked. That's because the "normal" usages of the help printer is to be
2103 // assigned true/false depending on whether -help or -help-hidden was given or
2104 // not. Since we're circumventing that we have to make it look like -help or
2105 // -help-hidden were given, so we assign true.
2106
21072103 if (!Hidden && !Categorized)
2108 UncategorizedNormalPrinter = true;
2104 UncategorizedNormalPrinter.printHelp();
21092105 else if (!Hidden && Categorized)
2110 CategorizedNormalPrinter = true;
2106 CategorizedNormalPrinter.printHelp();
21112107 else if (Hidden && !Categorized)
2112 UncategorizedHiddenPrinter = true;
2108 UncategorizedHiddenPrinter.printHelp();
21132109 else
2114 CategorizedHiddenPrinter = true;
2110 CategorizedHiddenPrinter.printHelp();
21152111 }
21162112
21172113 /// Utility function for printing version number.
11
22 RUN: not llvm-ar e 2>&1 | FileCheck %s
33 CHECK: unknown option e.
4 CHECK: OVERVIEW: LLVM Archiver (llvm-ar)
252252 "for the executable by using debug symbols information\n"
253253 "contained in its symbol table.\n");
254254
255 if (Help)
255 if (Help) {
256256 PrintHelpMessage();
257 return 0;
258 }
257259
258260 if (Version) {
259261 llvm::cl::PrintVersionMessage();
5353 // Show the error message and exit.
5454 LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) {
5555 errs() << ToolName << ": " << Error << ".\n";
56 // FIXME: Other ar implementations will print the command line help in here.
57 // Unfortunately cl::PrintHelpMessage() exits with 0, so we can't call it.
56 cl::PrintHelpMessage();
5857 exit(1);
5958 }
6059
513513 "A tool to generate an optimization report from YAML optimization"
514514 " record files.\n");
515515
516 if (Help)
516 if (Help) {
517517 cl::PrintHelpMessage();
518 return 0;
519 }
518520
519521 LocationInfoTy LocationInfo;
520522 if (!readLocationInfo(LocationInfo))
4545
4646 // If all else fails, we still print the usage message.
4747 cl::PrintHelpMessage(false, true);
48 return 0;
4849 }