[llvm-bugs] [Bug 34396] New: llvm-ar accidentally provides the wrong exit code when given an invalid command

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 31 03:24:59 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34396

            Bug ID: 34396
           Summary: llvm-ar accidentally provides the wrong exit code when
                    given an invalid command
           Product: tools
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: llvm-ar
          Assignee: unassignedbugs at nondot.org
          Reporter: mvogelsang at rocketmail.com
                CC: llvm-bugs at lists.llvm.org

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
https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-ar/llvm-ar.cpp#L169
)
'''
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 http://llvm.org/doxygen/CommandLine_8cpp_source.html#l02100) 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?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170831/04d2e30e/attachment-0001.html>


More information about the llvm-bugs mailing list