Fix llvm-size to exit with non zero when it can’t open a file.
authorKevin Enderby <enderby@apple.com>
Mon, 2 May 2016 21:41:03 +0000 (21:41 +0000)
committerKevin Enderby <enderby@apple.com>
Mon, 2 May 2016 21:41:03 +0000 (21:41 +0000)
rdar://26027819

llvm-svn: 268313

llvm/test/tools/llvm-size/basic.test
llvm/tools/llvm-size/llvm-size.cpp

index 614c639..88b8dcb 100644 (file)
@@ -1,2 +1,2 @@
-RUN: llvm-size %t.blah 2>&1 | FileCheck --check-prefix=ENOENT %s
+RUN: not llvm-size %t.blah 2>&1 | FileCheck --check-prefix=ENOENT %s
 ENOENT: {{.*}}llvm-size{{(\.EXE|\.exe)?}}: error reading file: {{[Nn]}}o such file or directory
index 1be173b..e3b487c 100644 (file)
@@ -84,6 +84,8 @@ RadixShort(cl::desc("Print size in radix:"),
 static cl::list<std::string>
 InputFilenames(cl::Positional, cl::desc("<input files>"), cl::ZeroOrMore);
 
+bool HadError = false;
+
 static std::string ToolName;
 
 /// If ec is not success, print the error and return true.
@@ -91,6 +93,7 @@ static bool error(std::error_code ec) {
   if (!ec)
     return false;
 
+  HadError = true;
   errs() << ToolName << ": error reading file: " << ec.message() << ".\n";
   errs().flush();
   return true;
@@ -757,5 +760,6 @@ int main(int argc, char **argv) {
   std::for_each(InputFilenames.begin(), InputFilenames.end(),
                 printFileSectionSizes);
 
-  return 0;
+  if (HadError)
+    return 1;
 }