<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - llvm-ar accidentally provides the wrong exit code when given an invalid command"
   href="https://bugs.llvm.org/show_bug.cgi?id=34396">34396</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm-ar accidentally provides the wrong exit code when given an invalid command
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>5.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>llvm-ar
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mvogelsang@rocketmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>llvm-ar parses its arguments, and if it can't make sense of them it shows it's
help message and exits. In particular llvm-ar calls `show_help` ( see it at
<a href="https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-ar/llvm-ar.cpp#L169">https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-ar/llvm-ar.cpp#L169</a>
)
'''
show_help(const std::string &msg) {
  errs() << ToolName << ": " << msg << "\n\n";
  cl::PrintHelpMessage();
  exit(1);
}
'''

llvm-ar dutifully tries to show some help and exit with a code indicating
error. Unfortunately, if one follows the `cl::PrintHelpMessage` function (found
at <a href="http://llvm.org/doxygen/CommandLine_8cpp_source.html#l02100">http://llvm.org/doxygen/CommandLine_8cpp_source.html#l02100</a>) they'll find
that it ends up calling `exit(0)`. The exit(1) never gets reached. 

This became a problem for us because GHC takes the AR implementation its given
and runs it with a variety of arguments to see what it supports. It relies on
the exit code to determine success or failure.

I'm not sure what would be technically the most appropriate fix would be in the
context of the LLVM project. Would simply changing `show_help` to print out
something like "unknown command line argument: run llvm-ar with -help for usage
information" and then call `exit(0)` be fine?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>