<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 7, 2017 at 3:20 PM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Thu Sep  7 15:20:38 2017<br>
New Revision: 312752<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=312752&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=312752&view=rev</a><br>
Log:<br>
llvm-ar: exit with 1 if there is an error.<br>
<br>
This is pr34396.<br>
<br>
Added:<br>
    llvm/trunk/test/tools/llvm-ar/<wbr>invalid-command-line.test<br>
Modified:<br>
    llvm/trunk/tools/llvm-ar/llvm-<wbr>ar.cpp<br>
<br>
Added: llvm/trunk/test/tools/llvm-ar/<wbr>invalid-command-line.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-ar/invalid-command-line.test?rev=312752&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/tools/<wbr>llvm-ar/invalid-command-line.<wbr>test?rev=312752&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/tools/llvm-ar/<wbr>invalid-command-line.test (added)<br>
+++ llvm/trunk/test/tools/llvm-ar/<wbr>invalid-command-line.test Thu Sep  7 15:20:38 2017<br>
@@ -0,0 +1,4 @@<br>
+Test that llvm-ar exits with 1 when there is an error.<br>
+<br>
+RUN: not llvm-ar e 2>&1 | FileCheck %s<br>
+CHECK: unknown option e.<br>
<br>
Modified: llvm/trunk/tools/llvm-ar/llvm-<wbr>ar.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=312752&r1=312751&r2=312752&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/tools/llvm-<wbr>ar/llvm-ar.cpp?rev=312752&r1=<wbr>312751&r2=312752&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/tools/llvm-ar/llvm-<wbr>ar.cpp (original)<br>
+++ llvm/trunk/tools/llvm-ar/llvm-<wbr>ar.cpp Thu Sep  7 15:20:38 2017<br>
@@ -54,6 +54,8 @@ static StringRef ToolName;<br>
 // Show the error message and exit.<br>
 LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) {<br>
   errs() << ToolName << ": " << Error << ".\n";<br>
+  // FIXME: Other ar implementations will print the command line help in here.<br>
+  // Unfortunately cl::PrintHelpMessage() exits with 0, so we can't call it.<br></blockquote><div><br></div><div>I wonder why PrintHelpMessage had to call `exit(0)`. Do you think you can just remove that and call `exit` explicitly on caller side?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   exit(1);<br>
 }<br>
<br>
@@ -164,26 +166,18 @@ static std::string ArchiveName;<br>
 // on the command line.<br>
 static std::vector<StringRef> Members;<br>
<br>
-// Show the error message, the help message and exit.<br>
-LLVM_ATTRIBUTE_NORETURN static void<br>
-show_help(const std::string &msg) {<br>
-  errs() << ToolName << ": " << msg << "\n\n";<br>
-  cl::PrintHelpMessage();<br>
-  exit(1);<br>
-}<br>
-<br>
 // Extract the member filename from the command line for the [relpos] argument<br>
 // associated with a, b, and i modifiers<br>
 static void getRelPos() {<br>
   if(RestOfArgs.size() == 0)<br>
-    show_help("Expected [relpos] for a, b, or i modifier");<br>
+    fail("Expected [relpos] for a, b, or i modifier");<br>
   RelPos = RestOfArgs[0];<br>
   RestOfArgs.erase(RestOfArgs.<wbr>begin());<br>
 }<br>
<br>
 static void getOptions() {<br>
   if(RestOfArgs.size() == 0)<br>
-    show_help("Expected options");<br>
+    fail("Expected options");<br>
   Options = RestOfArgs[0];<br>
   RestOfArgs.erase(RestOfArgs.<wbr>begin());<br>
 }<br>
@@ -191,7 +185,7 @@ static void getOptions() {<br>
 // Get the archive file name from the command line<br>
 static void getArchive() {<br>
   if(RestOfArgs.size() == 0)<br>
-    show_help("An archive name must be specified");<br>
+    fail("An archive name must be specified");<br>
   ArchiveName = RestOfArgs[0];<br>
   RestOfArgs.erase(RestOfArgs.<wbr>begin());<br>
 }<br>
@@ -275,7 +269,7 @@ static ArchiveOperation parseCommandLine<br>
       Thin = true;<br>
       break;<br>
     default:<br>
-      cl::PrintHelpMessage();<br>
+      fail(std::string("unknown option ") + Options[i]);<br>
     }<br>
   }<br>
<br>
@@ -290,26 +284,26 @@ static ArchiveOperation parseCommandLine<br>
     NumOperations = 1;<br>
     Operation = CreateSymTab;<br>
     if (!Members.empty())<br>
-      show_help("The s operation takes only an archive as argument");<br>
+      fail("The s operation takes only an archive as argument");<br>
   }<br>
<br>
   // Perform various checks on the operation/modifier specification<br>
   // to make sure we are dealing with a legal request.<br>
   if (NumOperations == 0)<br>
-    show_help("You must specify at least one of the operations");<br>
+    fail("You must specify at least one of the operations");<br>
   if (NumOperations > 1)<br>
-    show_help("Only one operation may be specified");<br>
+    fail("Only one operation may be specified");<br>
   if (NumPositional > 1)<br>
-    show_help("You may only specify one of a, b, and i modifiers");<br>
+    fail("You may only specify one of a, b, and i modifiers");<br>
   if (AddAfter || AddBefore) {<br>
     if (Operation != Move && Operation != ReplaceOrInsert)<br>
-      show_help("The 'a', 'b' and 'i' modifiers can only be specified with "<br>
-            "the 'm' or 'r' operations");<br>
+      fail("The 'a', 'b' and 'i' modifiers can only be specified with "<br>
+           "the 'm' or 'r' operations");<br>
   }<br>
   if (OriginalDates && Operation != Extract)<br>
-    show_help("The 'o' modifier is only applicable to the 'x' operation");<br>
+    fail("The 'o' modifier is only applicable to the 'x' operation");<br>
   if (OnlyUpdate && Operation != ReplaceOrInsert)<br>
-    show_help("The 'u' modifier is only applicable to the 'r' operation");<br>
+    fail("The 'u' modifier is only applicable to the 'r' operation");<br>
<br>
   // Return the parsed operation to the caller<br>
   return Operation;<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>