[llvm] r260786 - [llvm-size] Make error handling uniform.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 12 17:38:16 PST 2016


Author: davide
Date: Fri Feb 12 19:38:16 2016
New Revision: 260786

URL: http://llvm.org/viewvc/llvm-project?rev=260786&view=rev
Log:
[llvm-size] Make error handling uniform.

Modified:
    llvm/trunk/test/tools/llvm-size/basic.test
    llvm/trunk/tools/llvm-size/llvm-size.cpp

Modified: llvm/trunk/test/tools/llvm-size/basic.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-size/basic.test?rev=260786&r1=260785&r2=260786&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-size/basic.test (original)
+++ llvm/trunk/test/tools/llvm-size/basic.test Fri Feb 12 19:38:16 2016
@@ -1,2 +1,2 @@
 RUN: llvm-size %t.blah 2>&1 | FileCheck --check-prefix=ENOENT %s
-ENOENT: {{.*}}llvm-size{{(\.EXE|\.exe)?}}: {{.*}}.blah: {{[Nn]}}o such file or directory
+ENOENT: {{.*}}llvm-size{{(\.EXE|\.exe)?}}: error reading file: {{[Nn]}}o such file or directory

Modified: llvm/trunk/tools/llvm-size/llvm-size.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-size/llvm-size.cpp?rev=260786&r1=260785&r2=260786&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-size/llvm-size.cpp (original)
+++ llvm/trunk/tools/llvm-size/llvm-size.cpp Fri Feb 12 19:38:16 2016
@@ -439,10 +439,8 @@ static void printFileSectionSizes(String
 
   // Attempt to open the binary.
   ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(file);
-  if (std::error_code EC = BinaryOrErr.getError()) {
-    errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
+  if (error(BinaryOrErr.getError()))
     return;
-  }
   Binary &Bin = *BinaryOrErr.get().getBinary();
 
   if (Archive *a = dyn_cast<Archive>(&Bin)) {
@@ -450,17 +448,12 @@ static void printFileSectionSizes(String
     for (object::Archive::child_iterator i = a->child_begin(),
                                          e = a->child_end();
          i != e; ++i) {
-      if (i->getError()) {
-        errs() << ToolName << ": " << file << ": " << i->getError().message()
-               << ".\n";
+      if (error(i->getError()))
         exit(1);
-      }
       auto &c = i->get();
       ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
-      if (std::error_code EC = ChildOrErr.getError()) {
-        errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
+      if (error(ChildOrErr.getError()))
         continue;
-      }
       if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
         MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
         if (!checkMachOAndArchFlags(o, file))
@@ -518,18 +511,12 @@ static void printFileSectionSizes(String
               for (object::Archive::child_iterator i = UA->child_begin(),
                                                    e = UA->child_end();
                    i != e; ++i) {
-                if (std::error_code EC = i->getError()) {
-                  errs() << ToolName << ": " << file << ": " << EC.message()
-                         << ".\n";
+                if (error(i->getError()))
                   exit(1);
-                }
                 auto &c = i->get();
                 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
-                if (std::error_code EC = ChildOrErr.getError()) {
-                  errs() << ToolName << ": " << file << ": " << EC.message()
-                         << ".\n";
+                if (error(ChildOrErr.getError()))
                   continue;
-                }
                 if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
                   MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
                   if (OutputFormat == sysv)
@@ -601,18 +588,12 @@ static void printFileSectionSizes(String
             for (object::Archive::child_iterator i = UA->child_begin(),
                                                  e = UA->child_end();
                  i != e; ++i) {
-              if (std::error_code EC = i->getError()) {
-                errs() << ToolName << ": " << file << ": " << EC.message()
-                       << ".\n";
+              if (error(i->getError()))
                 exit(1);
-              }
               auto &c = i->get();
               ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
-              if (std::error_code EC = ChildOrErr.getError()) {
-                errs() << ToolName << ": " << file << ": " << EC.message()
-                       << ".\n";
+              if (error(ChildOrErr.getError()))
                 continue;
-              }
               if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
                 MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
                 if (OutputFormat == sysv)
@@ -671,16 +652,12 @@ static void printFileSectionSizes(String
         for (object::Archive::child_iterator i = UA->child_begin(),
                                              e = UA->child_end();
              i != e; ++i) {
-          if (std::error_code EC = i->getError()) {
-            errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
+          if (error(i->getError()))
             exit(1);
-          }
           auto &c = i->get();
           ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
-          if (std::error_code EC = ChildOrErr.getError()) {
-            errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
+          if (error(ChildOrErr.getError()))
             continue;
-          }
           if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {
             MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
             if (OutputFormat == sysv)




More information about the llvm-commits mailing list