Backing out commit r250906 as it broke lld.
authorKevin Enderby <enderby@apple.com>
Wed, 21 Oct 2015 17:13:20 +0000 (17:13 +0000)
committerKevin Enderby <enderby@apple.com>
Wed, 21 Oct 2015 17:13:20 +0000 (17:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250908 91177308-0d34-0410-b5e6-96231b3b80d8

18 files changed:
include/llvm/Object/Archive.h
include/llvm/Support/ErrorOr.h
lib/ExecutionEngine/MCJIT/MCJIT.cpp
lib/ExecutionEngine/Orc/OrcMCJITReplacement.h
lib/Object/Archive.cpp
lib/Object/ArchiveWriter.cpp
test/tools/llvm-objdump/Inputs/malformed-archives/libbogus1.a [deleted file]
test/tools/llvm-objdump/Inputs/malformed-archives/libbogus2.a [deleted file]
test/tools/llvm-objdump/Inputs/malformed-archives/libbogus3.a [deleted file]
test/tools/llvm-objdump/malformed-archives.test [deleted file]
tools/dsymutil/BinaryHolder.cpp
tools/llvm-ar/llvm-ar.cpp
tools/llvm-cxxdump/llvm-cxxdump.cpp
tools/llvm-nm/llvm-nm.cpp
tools/llvm-objdump/MachODump.cpp
tools/llvm-objdump/llvm-objdump.cpp
tools/llvm-readobj/llvm-readobj.cpp
tools/llvm-size/llvm-size.cpp

index 356393cce2d755442c654fa971e5f0293ba400d1..32c72a0cc3d334fb11ec9e685afc27eaa6ad4368 100644 (file)
@@ -65,10 +65,7 @@ public:
     bool isThinMember() const;
 
   public:
-    Child(const Archive *Parent, const char *Start,
-          std::error_code *EC);
-    static ErrorOr<std::unique_ptr<Child>> create(const Archive *Parent,
-                                                  const char *Start);
+    Child(const Archive *Parent, const char *Start);
 
     bool operator ==(const Child &other) const {
       assert(Parent == other.Parent);
@@ -80,7 +77,7 @@ public:
     }
 
     const Archive *getParent() const { return Parent; }
-    ErrorOr<Child> getNext() const;
+    Child getNext() const;
 
     ErrorOr<StringRef> getName() const;
     StringRef getRawName() const { return getHeader()->getName(); }
@@ -96,9 +93,9 @@ public:
       return getHeader()->getAccessMode();
     }
     /// \return the size of the archive member without the header or padding.
-    ErrorOr<uint64_t> getSize() const;
+    uint64_t getSize() const;
     /// \return the size in the archive header for this member.
-    ErrorOr<uint64_t> getRawSize() const;
+    uint64_t getRawSize() const;
 
     ErrorOr<StringRef> getBuffer() const;
     uint64_t getChildOffset() const;
@@ -110,35 +107,28 @@ public:
   };
 
   class child_iterator {
-    ErrorOr<Child> child;
+    Child child;
 
   public:
-    child_iterator() : child(Child(nullptr, nullptr, nullptr)) {}
+    child_iterator() : child(Child(nullptr, nullptr)) {}
     child_iterator(const Child &c) : child(c) {}
-    child_iterator(std::error_code EC) : child(EC) {}
-    const ErrorOr<Child> *operator->() const { return &child; }
-    const ErrorOr<Child> &operator*() const { return child; }
+    const Child *operator->() const { return &child; }
+    const Child &operator*() const { return child; }
 
     bool operator==(const child_iterator &other) const {
-      if ((*this)->getError())
-        return false;
-      if (other->getError())
-        return false;
-      return (*this)->get() == other->get();
+      return child == other.child;
     }
 
     bool operator!=(const child_iterator &other) const {
       return !(*this == other);
     }
 
-    // No operator< as we can't do less than compares with iterators that
-    // contain errors.
+    bool operator<(const child_iterator &other) const {
+      return child < other.child;
+    }
 
-    // Code in loops with child_iterators must check for errors on each loop
-    // iteration.  And if there is an error break out of the loop.
     child_iterator &operator++() { // Preincrement
-      assert(child && "Can't increment iterator with error");
-      child = child->getNext();
+      child = child.getNext();
       return *this;
     }
   };
@@ -222,7 +212,7 @@ public:
   StringRef getSymbolTable() const {
     // We know that the symbol table is not an external file,
     // so we just assert there is no error.
-    return *(*SymbolTable)->getBuffer();
+    return *SymbolTable->getBuffer();
   }
   uint32_t getNumberOfSymbols() const;
 
index 5021468b4da97bf19a1ef1172b415f536c885b78..46b619217753bcc8fe586fb3bd7ba77471ce0a1f 100644 (file)
@@ -91,7 +91,6 @@ private:
   typedef typename std::remove_reference<T>::type &reference;
   typedef const typename std::remove_reference<T>::type &const_reference;
   typedef typename std::remove_reference<T>::type *pointer;
-  typedef const typename std::remove_reference<T>::type *const_pointer;
 
 public:
   template <class E>
@@ -184,18 +183,10 @@ public:
     return toPointer(getStorage());
   }
 
-  const_pointer operator ->() const {
-    return toPointer(getStorage());
-  }
-
   reference operator *() {
     return *getStorage();
   }
 
-  const_reference operator *() const {
-    return *getStorage();
-  }
-
 private:
   template <class OtherT>
   void copyConstruct(const ErrorOr<OtherT> &Other) {
@@ -255,19 +246,10 @@ private:
     return Val;
   }
 
-  const_pointer toPointer(const_pointer Val) const {
-    return Val;
-  }
-
   pointer toPointer(wrap *Val) {
     return &Val->get();
   }
 
-  const_pointer toPointer(const wrap *Val) const {
-    return &Val->get();
-  }
-
-
   storage_type *getStorage() {
     assert(!HasError && "Cannot get value when an error exists!");
     return reinterpret_cast<storage_type*>(TStorage.buffer);
index a7238e4ebc338b29fee796913c9af7106405b683..bbe4432d36b318a1a40de7dbd4887d44a1ed58c4 100644 (file)
@@ -318,10 +318,10 @@ RuntimeDyld::SymbolInfo MCJIT::findSymbol(const std::string &Name,
     object::Archive *A = OB.getBinary();
     // Look for our symbols in each Archive
     object::Archive::child_iterator ChildIt = A->findSym(Name);
-    if (*ChildIt && ChildIt != A->child_end()) {
+    if (ChildIt != A->child_end()) {
       // FIXME: Support nested archives?
       ErrorOr<std::unique_ptr<object::Binary>> ChildBinOrErr =
-        (*ChildIt)->getAsBinary();
+          ChildIt->getAsBinary();
       if (ChildBinOrErr.getError())
         continue;
       std::unique_ptr<object::Binary> &ChildBin = ChildBinOrErr.get();
index e52df2db79f2b31bc71c9501384ee46513178796..951993f75e4ceb2a0f173f579ce50e230079899d 100644 (file)
@@ -253,10 +253,10 @@ private:
       object::Archive *A = OB.getBinary();
       // Look for our symbols in each Archive
       object::Archive::child_iterator ChildIt = A->findSym(Name);
-      if (*ChildIt && ChildIt != A->child_end()) {
+      if (ChildIt != A->child_end()) {
         // FIXME: Support nested archives?
         ErrorOr<std::unique_ptr<object::Binary>> ChildBinOrErr =
-          (*ChildIt)->getAsBinary();
+            ChildIt->getAsBinary();
         if (ChildBinOrErr.getError())
           continue;
         std::unique_ptr<object::Binary> &ChildBin = ChildBinOrErr.get();
index 1cc3c48c6c3c818d279a92f59f6b9614e02623b0..667732baa279ebcfcfe668a54c33a6969496f5fa 100644 (file)
@@ -46,7 +46,7 @@ StringRef ArchiveMemberHeader::getName() const {
 ErrorOr<uint32_t> ArchiveMemberHeader::getSize() const {
   uint32_t Ret;
   if (llvm::StringRef(Size, sizeof(Size)).rtrim(" ").getAsInteger(10, Ret))
-    return object_error::parse_failed; // Size is not a decimal number.
+    return object_error::parse_failed;
   return Ret;
 }
 
@@ -82,8 +82,7 @@ unsigned ArchiveMemberHeader::getGID() const {
   return Ret;
 }
 
-Archive::Child::Child(const Archive *Parent, const char *Start,
-                      std::error_code *EC)
+Archive::Child::Child(const Archive *Parent, const char *Start)
     : Parent(Parent) {
   if (!Start)
     return;
@@ -91,13 +90,7 @@ Archive::Child::Child(const Archive *Parent, const char *Start,
   uint64_t Size = sizeof(ArchiveMemberHeader);
   Data = StringRef(Start, Size);
   if (!isThinMember()) {
-    ErrorOr<uint64_t> MemberSize = getRawSize();
-    if (MemberSize.getError()) {
-      assert (EC && "Error must be caught");
-      *EC = MemberSize.getError();
-      return;
-    }
-    Size += MemberSize.get();
+    Size += getRawSize();
     Data = StringRef(Start, Size);
   }
 
@@ -107,38 +100,26 @@ Archive::Child::Child(const Archive *Parent, const char *Start,
   StringRef Name = getRawName();
   if (Name.startswith("#1/")) {
     uint64_t NameSize;
-    if (Name.substr(3).rtrim(" ").getAsInteger(10, NameSize)) {
-      if (EC)
-        *EC = object_error::parse_failed; // Long name offset is not an integer.
-      return;
-    }
+    if (Name.substr(3).rtrim(" ").getAsInteger(10, NameSize))
+      llvm_unreachable("Long name length is not an integer");
     StartOfFile += NameSize;
   }
 }
 
-ErrorOr<std::unique_ptr<Archive::Child>> Archive::Child::create(
-  const Archive *Parent, const char *Start) {
-  std::error_code EC;
-  std::unique_ptr<Archive::Child> Ret(new Archive::Child(Parent, Start, &EC));
-  if (EC)
-    return EC;
-  return std::move(Ret);
-}
-
-ErrorOr<uint64_t> Archive::Child::getSize() const {
+uint64_t Archive::Child::getSize() const {
   if (Parent->IsThin) {
     ErrorOr<uint32_t> Size = getHeader()->getSize();
-    if (std::error_code EC = Size.getError())
-      return EC;
+    if (Size.getError())
+      return 0;
     return Size.get();
   }
   return Data.size() - StartOfFile;
 }
 
-ErrorOr<uint64_t> Archive::Child::getRawSize() const {
+uint64_t Archive::Child::getRawSize() const {
   ErrorOr<uint32_t> Size = getHeader()->getSize();
-  if (std::error_code EC = Size.getError())
-    return EC;
+  if (Size.getError())
+    return 0;
   return Size.get();
 }
 
@@ -148,12 +129,8 @@ bool Archive::Child::isThinMember() const {
 }
 
 ErrorOr<StringRef> Archive::Child::getBuffer() const {
-  if (!isThinMember()) {
-    ErrorOr<uint32_t> Size = getSize();
-    if (std::error_code EC = Size.getError())
-      return EC;
-    return StringRef(Data.data() + StartOfFile, Size.get());
-  }
+  if (!isThinMember())
+    return StringRef(Data.data() + StartOfFile, getSize());
   ErrorOr<StringRef> Name = getName();
   if (std::error_code EC = Name.getError())
     return EC;
@@ -167,28 +144,19 @@ ErrorOr<StringRef> Archive::Child::getBuffer() const {
   return Parent->ThinBuffers.back()->getBuffer();
 }
 
-ErrorOr<Archive::Child> Archive::Child::getNext() const {
+Archive::Child Archive::Child::getNext() const {
   size_t SpaceToSkip = Data.size();
   // If it's odd, add 1 to make it even.
-  size_t Pad = 0;
   if (SpaceToSkip & 1)
-    Pad++;
+    ++SpaceToSkip;
 
-  const char *NextLoc = Data.data() + SpaceToSkip + Pad;
-
-  // Check to see if this is at the end of the archive.
-  if (NextLoc == Parent->Data.getBufferEnd() ||
-      NextLoc == Parent->Data.getBufferEnd() - Pad )
-    return Child(Parent, nullptr, nullptr);
+  const char *NextLoc = Data.data() + SpaceToSkip;
 
   // Check to see if this is past the end of the archive.
-  if (NextLoc > Parent->Data.getBufferEnd())
-    return object_error::parse_failed;
+  if (NextLoc >= Parent->Data.getBufferEnd())
+    return Child(Parent, nullptr);
 
-  auto ChildOrErr = Child::create(Parent, NextLoc);
-  if (std::error_code EC = ChildOrErr.getError())
-    return EC;
-  return std::move(*ChildOrErr.get());
+  return Child(Parent, NextLoc);
 }
 
 uint64_t Archive::Child::getChildOffset() const {
@@ -210,23 +178,17 @@ ErrorOr<StringRef> Archive::Child::getName() const {
     // Get the offset.
     std::size_t offset;
     if (name.substr(1).rtrim(" ").getAsInteger(10, offset))
-      return object_error::parse_failed; // Long name offset is not an integer.
-    // Check for bad stringtable iterator.
-    if (std::error_code EC = Parent->StringTable->getError())
-      return EC;
-    const char *addr = (*Parent->StringTable)->Data.begin()
+      llvm_unreachable("Long name offset is not an integer");
+    const char *addr = Parent->StringTable->Data.begin()
                        + sizeof(ArchiveMemberHeader)
                        + offset;
     // Verify it.
-    auto Size = (*Parent->StringTable)->getSize();
-    if (std::error_code EC = Size.getError())
-      return EC;
     if (Parent->StringTable == Parent->child_end()
-        || addr < ((*Parent->StringTable)->Data.begin()
+        || addr < (Parent->StringTable->Data.begin()
                    + sizeof(ArchiveMemberHeader))
-        || addr > ((*Parent->StringTable)->Data.begin()
+        || addr > (Parent->StringTable->Data.begin()
                    + sizeof(ArchiveMemberHeader)
-                   + Size.get()))
+                   + Parent->StringTable->getSize()))
       return object_error::parse_failed;
 
     // GNU long file names end with a "/\n".
@@ -238,7 +200,7 @@ ErrorOr<StringRef> Archive::Child::getName() const {
   } else if (name.startswith("#1/")) {
     uint64_t name_size;
     if (name.substr(3).rtrim(" ").getAsInteger(10, name_size))
-      return object_error::parse_failed; // Long name offset is not an integer.
+      llvm_unreachable("Long name length is not an ingeter");
     return Data.substr(sizeof(ArchiveMemberHeader), name_size)
         .rtrim(StringRef("\0", 1));
   }
@@ -294,12 +256,12 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
   child_iterator i = child_begin(false);
   child_iterator e = child_end();
 
-  if (!*i || i == e) {
-    ec = i->getError();
+  if (i == e) {
+    ec = std::error_code();
     return;
   }
 
-  StringRef Name = (*i)->getRawName();
+  StringRef Name = i->getRawName();
 
   // Below is the pattern that is used to figure out the archive format
   // GNU archive format
@@ -324,11 +286,6 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
     Format = K_BSD;
     SymbolTable = i;
     ++i;
-    if (!*i) {
-      ec = i->getError();
-      return;
-    }
-
     FirstRegular = i;
     ec = std::error_code();
     return;
@@ -337,7 +294,7 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
   if (Name.startswith("#1/")) {
     Format = K_BSD;
     // We know this is BSD, so getName will work since there is no string table.
-    ErrorOr<StringRef> NameOrErr = (*i)->getName();
+    ErrorOr<StringRef> NameOrErr = i->getName();
     ec = NameOrErr.getError();
     if (ec)
       return;
@@ -345,10 +302,6 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
     if (Name == "__.SYMDEF SORTED" || Name == "__.SYMDEF") {
       SymbolTable = i;
       ++i;
-      if (!*i) {
-        ec = i->getError();
-        return;
-      }
     }
     FirstRegular = i;
     return;
@@ -366,21 +319,17 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
       has64SymTable = true;
 
     ++i;
-    if (!*i || i == e) {
-      ec = i->getError();
+    if (i == e) {
+      ec = std::error_code();
       return;
     }
-    Name = (*i)->getRawName();
+    Name = i->getRawName();
   }
 
   if (Name == "//") {
     Format = has64SymTable ? K_MIPS64 : K_GNU;
     StringTable = i;
     ++i;
-    if (!*i) {
-      ec = i->getError();
-      return;
-    }
     FirstRegular = i;
     ec = std::error_code();
     return;
@@ -402,25 +351,17 @@ Archive::Archive(MemoryBufferRef Source, std::error_code &ec)
   SymbolTable = i;
 
   ++i;
-  if (!*i) {
-    ec = i->getError();
-    return;
-  }
   if (i == e) {
     FirstRegular = i;
     ec = std::error_code();
     return;
   }
 
-  Name = (*i)->getRawName();
+  Name = i->getRawName();
 
   if (Name == "//") {
     StringTable = i;
     ++i;
-    if (!*i) {
-      ec = i->getError();
-      return;
-    }
   }
 
   FirstRegular = i;
@@ -435,20 +376,12 @@ Archive::child_iterator Archive::child_begin(bool SkipInternal) const {
     return FirstRegular;
 
   const char *Loc = Data.getBufferStart() + strlen(Magic);
-  auto ChildOrErr = Child::create(this, Loc);
-  if (std::error_code EC = ChildOrErr.getError())
-    return child_iterator(EC);
-  Child c = *(ChildOrErr.get());
-  return child_iterator(c);
+  Child c(this, Loc);
+  return c;
 }
 
 Archive::child_iterator Archive::child_end() const {
-  // This with a second argument of nullptr can't return an Error.
-  auto ChildOrErr = Child::create(this, nullptr);
-  if (ChildOrErr.getError())
-    llvm_unreachable("Can't create Archive::child_end().");
-  Child c = *(ChildOrErr.get());
-  return child_iterator(c);
+  return Child(this, nullptr);
 }
 
 StringRef Archive::Symbol::getName() const {
@@ -500,10 +433,7 @@ ErrorOr<Archive::child_iterator> Archive::Symbol::getMember() const {
   }
 
   const char *Loc = Parent->getData().begin() + Offset;
-  auto ChildOrErr = Child::create(Parent, Loc);
-  if (std::error_code EC = ChildOrErr.getError())
-    return EC;
-  child_iterator Iter(std::move(*ChildOrErr.get()));
+  child_iterator Iter(Child(Parent, Loc));
   return Iter;
 }
 
index 1f304ccfb75afe1c98ffa34bd50633fdc68b091e..dae0188a21e15b96baab7e7feee4588c02895026 100644 (file)
@@ -347,10 +347,10 @@ llvm::writeArchive(StringRef ArcName,
       MemberRef = Buffers.back()->getMemBufferRef();
     } else {
       object::Archive::child_iterator OldMember = Member.getOld();
-      assert((!Thin || (*OldMember && (*OldMember)->getParent()->isThin())) &&
+      assert((!Thin || OldMember->getParent()->isThin()) &&
              "Thin archives cannot refers to member of other archives");
       ErrorOr<MemoryBufferRef> MemberBufferOrErr =
-          (*OldMember)->getMemoryBufferRef();
+          OldMember->getMemoryBufferRef();
       if (auto EC = MemberBufferOrErr.getError())
         return std::make_pair("", EC);
       MemberRef = MemberBufferOrErr.get();
@@ -398,10 +398,10 @@ llvm::writeArchive(StringRef ArcName,
       Perms = Status.permissions();
     } else {
       object::Archive::child_iterator OldMember = I.getOld();
-      ModTime = (*OldMember)->getLastModified();
-      UID = (*OldMember)->getUID();
-      GID = (*OldMember)->getGID();
-      Perms = (*OldMember)->getAccessMode();
+      ModTime = OldMember->getLastModified();
+      UID = OldMember->getUID();
+      GID = OldMember->getGID();
+      Perms = OldMember->getAccessMode();
     }
 
     if (I.isNewMember()) {
@@ -412,11 +412,8 @@ llvm::writeArchive(StringRef ArcName,
                         Status.getSize());
     } else {
       object::Archive::child_iterator OldMember = I.getOld();
-      ErrorOr<uint32_t> Size = (*OldMember)->getSize();
-      if (std::error_code EC = Size.getError())
-        return std::make_pair("", EC);
       printMemberHeader(Out, Kind, Thin, I.getName(), StringMapIndexIter,
-                        ModTime, UID, GID, Perms, Size.get());
+                        ModTime, UID, GID, Perms, OldMember->getSize());
     }
 
     if (!Thin)
diff --git a/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus1.a b/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus1.a
deleted file mode 100644 (file)
index 510c145..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-!<arch>
-hello.c         1444941273  124   0     100644  10%       `
-#include <stdio.h>
-#include <stdlib.h>
-int
-main()
-{
-       printf("Hello World\n");
-       return EXIT_SUCCESS;
-}
-foo.c           1444941645  124   0     100644  1%        `
-void foo(void){}
-
diff --git a/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus2.a b/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus2.a
deleted file mode 100644 (file)
index 2ccb7f3..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-!<arch>
-hello.c         1444941273  124   0     100644  102       `
-#include <stdio.h>
-#include <stdlib.h>
-int
-main()
-{
-       printf("Hello World\n");
-       return EXIT_SUCCESS;
-}
-foo.c           1444941645  124   0     100644  1%        `
-void foo(void){}
-
diff --git a/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus3.a b/test/tools/llvm-objdump/Inputs/malformed-archives/libbogus3.a
deleted file mode 100644 (file)
index f15a732..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-!<arch>
-hello.c         1444941273  124   0     100644  102       `
-#include <stdio.h>
-#include <stdlib.h>
-int
-main()
-{
-       printf("Hello World\n");
-       return EXIT_SUCCESS;
-}
-foo.c           1444941645  124   0     100644  171       `
-void foo(void){}
-
-bar.c           1445026190  124   0     100644  17        `
-void foo(void){}
-
diff --git a/test/tools/llvm-objdump/malformed-archives.test b/test/tools/llvm-objdump/malformed-archives.test
deleted file mode 100644 (file)
index 5066cb5..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// These test checks that llvm-objdump will not crash with malformed Archive
-// files.  So the check line is not all that important but the bug fixes to
-// make sure llvm-objdump is robust is what matters.
-# RUN: llvm-objdump -macho -archive-headers \
-# RUN:   %p/Inputs/malformed-archives/libbogus1.a \
-# RUN:   2>&1 | FileCheck -check-prefix=bogus1 %s 
-
-# bogus1: Invalid data was encountered while parsing the file
-
-# RUN: llvm-objdump -macho -archive-headers \
-# RUN:   %p/Inputs/malformed-archives/libbogus2.a \
-# RUN:   2>&1 | FileCheck -check-prefix=bogus2 %s 
-
-# bogus2: hello.c
-
-# RUN: llvm-objdump -macho -archive-headers \
-# RUN:   %p/Inputs/malformed-archives/libbogus3.a \
-# RUN:   2>&1 | FileCheck -check-prefix=bogus3 %s 
-
-# bogus3: foo.c
index 01a49c9b1ee3e454ebe78ac56d635159e252b45d..7ff4fd699578ab4fe052457cd10849da4f17a96d 100644 (file)
@@ -109,10 +109,7 @@ BinaryHolder::GetArchiveMemberBuffers(StringRef Filename,
   Buffers.reserve(CurrentArchives.size());
 
   for (const auto &CurrentArchive : CurrentArchives) {
-    for (auto ChildOrErr : CurrentArchive->children()) {
-      if (auto Err = ChildOrErr.getError())
-        return Err;
-      const auto &Child = *ChildOrErr;
+    for (const auto &Child : CurrentArchive->children()) {
       if (auto NameOrErr = Child.getName()) {
         if (*NameOrErr == Filename) {
           if (Timestamp != sys::TimeValue::PosixZeroTime() &&
index ec81421b4aebf6cc146fa5052c7640f1dc1a41d5..ec3cfcb5cad014ed265afbd24eb9d76de9a170d4 100644 (file)
@@ -338,11 +338,7 @@ static void doDisplayTable(StringRef Name, const object::Archive::Child &C) {
     printMode(Mode & 007);
     outs() << ' ' << C.getUID();
     outs() << '/' << C.getGID();
-    ErrorOr<uint32_t> Size = C.getSize();
-    if (Size.getError())
-      outs() << ' ' << "bad size";
-    else
-      outs() << ' ' << format("%6llu", Size.get());
+    outs() << ' ' << format("%6llu", C.getSize());
     outs() << ' ' << C.getLastModified().str();
     outs() << ' ';
   }
@@ -407,14 +403,7 @@ static void performReadOperation(ArchiveOperation Operation,
   }
 
   bool Filter = !Members.empty();
-  for (auto &ChildOrErr : OldArchive->children()) {
-    if (ChildOrErr.getError()) {
-      errs() << ToolName << ": error reading '" << ArchiveName
-             << "': " << ChildOrErr.getError().message() << "!\n";
-      return;
-    }
-    const object::Archive::Child &C = *ChildOrErr;
-
+  for (const object::Archive::Child &C : OldArchive->children()) {
     ErrorOr<StringRef> NameOrErr = C.getName();
     failIfError(NameOrErr.getError());
     StringRef Name = NameOrErr.get();
@@ -459,9 +448,7 @@ void addMember(std::vector<NewArchiveIterator> &Members, StringRef FileName,
 void addMember(std::vector<NewArchiveIterator> &Members,
                object::Archive::child_iterator I, StringRef Name,
                int Pos = -1) {
-  if (I->getError())
-    fail("New member is not valid: " + I->getError().message());
-  if (Thin && !(*I)->getParent()->isThin())
+  if (Thin && !I->getParent()->isThin())
     fail("Cannot convert a regular archive to a thin one");
   NewArchiveIterator NI(I, Name);
   if (Pos == -1)
@@ -482,9 +469,6 @@ static InsertAction computeInsertAction(ArchiveOperation Operation,
                                         object::Archive::child_iterator I,
                                         StringRef Name,
                                         std::vector<StringRef>::iterator &Pos) {
-  if (I->getError())
-    fail("Invalid member: " + I->getError().message());
-
   if (Operation == QuickAppend || Members.empty())
     return IA_AddOldMember;
 
@@ -516,7 +500,7 @@ static InsertAction computeInsertAction(ArchiveOperation Operation,
     // operation.
     sys::fs::file_status Status;
     failIfError(sys::fs::status(*MI, Status), *MI);
-    if (Status.getLastModificationTime() < (*I)->getLastModified()) {
+    if (Status.getLastModificationTime() < I->getLastModified()) {
       if (PosName.empty())
         return IA_AddOldMember;
       return IA_MoveOldMember;
@@ -539,9 +523,7 @@ computeNewArchiveMembers(ArchiveOperation Operation,
   int InsertPos = -1;
   StringRef PosName = sys::path::filename(RelPos);
   if (OldArchive) {
-    for (auto &ChildOrErr : OldArchive->children()) {
-      failIfError(ChildOrErr.getError());
-      auto &Child = ChildOrErr.get();
+    for (auto &Child : OldArchive->children()) {
       int Pos = Ret.size();
       ErrorOr<StringRef> NameOrErr = Child.getName();
       failIfError(NameOrErr.getError());
@@ -744,9 +726,7 @@ static void runMRIScript() {
       failIfError(LibOrErr.getError(), "Could not parse library");
       Archives.push_back(std::move(*LibOrErr));
       object::Archive &Lib = *Archives.back();
-      for (auto &MemberOrErr : Lib.children()) {
-        failIfError(MemberOrErr.getError());
-        auto &Member = MemberOrErr.get();
+      for (auto &Member : Lib.children()) {
         ErrorOr<StringRef> NameOrErr = Member.getName();
         failIfError(NameOrErr.getError());
         addMember(NewMembers, Member, *NameOrErr);
index 96526c4ea4537f3b64ad6c4e8f3e2907af3b9a4a..d45a28a3b0f13463ef3fa518959a3ab3af5882f6 100644 (file)
@@ -482,12 +482,7 @@ static void dumpCXXData(const ObjectFile *Obj) {
 }
 
 static void dumpArchive(const Archive *Arc) {
-  for (auto &ErrorOrChild : Arc->children()) {
-    if (std::error_code EC = ErrorOrChild.getError()) {
-      reportError(Arc->getFileName(), EC.message());
-      break;
-    }
-    const Archive::Child &ArcC = *ErrorOrChild;
+  for (const Archive::Child &ArcC : Arc->children()) {
     ErrorOr<std::unique_ptr<Binary>> ChildOrErr = ArcC.getAsBinary();
     if (std::error_code EC = ChildOrErr.getError()) {
       // Ignore non-object files.
index fad9e582df0da838ea3495943de0582f919c4591..a0b5e9b4eaa477d90b26a6351eaf3537eaf23d1e 100644 (file)
@@ -945,11 +945,10 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
       if (I != E) {
         outs() << "Archive map\n";
         for (; I != E; ++I) {
-          ErrorOr<Archive::child_iterator> ErrorOrChild = I->getMember();
-          if (error(ErrorOrChild.getError()))
+          ErrorOr<Archive::child_iterator> C = I->getMember();
+          if (error(C.getError()))
             return;
-          auto &C = *(ErrorOrChild.get());
-          ErrorOr<StringRef> FileNameOrErr = C.get().getName();
+          ErrorOr<StringRef> FileNameOrErr = C.get()->getName();
           if (error(FileNameOrErr.getError()))
             return;
           StringRef SymName = I->getName();
@@ -961,10 +960,7 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
 
     for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
          I != E; ++I) {
-      if (I->getError())
-        break;
-      auto &C = I->get();
-      ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context);
+      ErrorOr<std::unique_ptr<Binary>> ChildOrErr = I->getAsBinary(&Context);
       if (ChildOrErr.getError())
         continue;
       if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {
@@ -1019,11 +1015,8 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
               for (Archive::child_iterator AI = A->child_begin(),
                                            AE = A->child_end();
                    AI != AE; ++AI) {
-                if(AI->getError())
-                  break;
-                auto &C = AI->get();
                 ErrorOr<std::unique_ptr<Binary>> ChildOrErr =
-                    C.getAsBinary(&Context);
+                    AI->getAsBinary(&Context);
                 if (ChildOrErr.getError())
                   continue;
                 if (SymbolicFile *O =
@@ -1076,11 +1069,8 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
             for (Archive::child_iterator AI = A->child_begin(),
                                          AE = A->child_end();
                  AI != AE; ++AI) {
-              if(AI->getError())
-                break;
-              auto &C = AI->get();
               ErrorOr<std::unique_ptr<Binary>> ChildOrErr =
-                  C.getAsBinary(&Context);
+                  AI->getAsBinary(&Context);
               if (ChildOrErr.getError())
                 continue;
               if (SymbolicFile *O =
@@ -1128,11 +1118,8 @@ static void dumpSymbolNamesFromFile(std::string &Filename) {
         std::unique_ptr<Archive> &A = *AOrErr;
         for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
              AI != AE; ++AI) {
-          if(AI->getError())
-            continue;
-          auto &C = AI->get();
           ErrorOr<std::unique_ptr<Binary>> ChildOrErr =
-              C.getAsBinary(&Context);
+              AI->getAsBinary(&Context);
           if (ChildOrErr.getError())
             continue;
           if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {
index 95869f2b952fc3dd080502ed9efb94bfe3ae9d37..6b70c011c0277ce107ee9f416effd9edc257f884 100644 (file)
@@ -1417,11 +1417,8 @@ static void printArchiveChild(Archive::Child &C, bool verbose,
   outs() << format("%3d/", UID);
   unsigned GID = C.getGID();
   outs() << format("%-3d ", GID);
-  ErrorOr<uint64_t> Size = C.getRawSize();
-  if (Size.getError())
-    outs() << "bad size" << " ";
-  else
-    outs() << format("%5" PRId64, Size.get()) << " ";
+  uint64_t Size = C.getRawSize();
+  outs() << format("%5" PRId64, Size) << " ";
 
   StringRef RawLastModified = C.getRawLastModified();
   if (verbose) {
@@ -1457,16 +1454,12 @@ static void printArchiveChild(Archive::Child &C, bool verbose,
 static void printArchiveHeaders(Archive *A, bool verbose, bool print_offset) {
   if (A->hasSymbolTable()) {
     Archive::child_iterator S = A->getSymbolTableChild();
-    if (!S->getError()) {
-      Archive::Child C = S->get();
-      printArchiveChild(C, verbose, print_offset);
-    }
+    Archive::Child C = *S;
+    printArchiveChild(C, verbose, print_offset);
   }
   for (Archive::child_iterator I = A->child_begin(), E = A->child_end(); I != E;
        ++I) {
-    if(I->getError())
-      break;
-    Archive::Child C = I->get();
+    Archive::Child C = *I;
     printArchiveChild(C, verbose, print_offset);
   }
 }
@@ -1503,10 +1496,7 @@ void llvm::ParseInputMachO(StringRef Filename) {
       printArchiveHeaders(A, !NonVerbose, ArchiveMemberOffsets);
     for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
          I != E; ++I) {
-      if (I->getError())
-        break;
-      auto &C = I->get();
-      ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
+      ErrorOr<std::unique_ptr<Binary>> ChildOrErr = I->getAsBinary();
       if (ChildOrErr.getError())
         continue;
       if (MachOObjectFile *O = dyn_cast<MachOObjectFile>(&*ChildOrErr.get())) {
@@ -1554,10 +1544,7 @@ void llvm::ParseInputMachO(StringRef Filename) {
               for (Archive::child_iterator AI = A->child_begin(),
                                            AE = A->child_end();
                    AI != AE; ++AI) {
-                if (AI->getError())
-                  break;
-                auto &C = AI->get();
-                ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
+                ErrorOr<std::unique_ptr<Binary>> ChildOrErr = AI->getAsBinary();
                 if (ChildOrErr.getError())
                   continue;
                 if (MachOObjectFile *O =
@@ -1599,10 +1586,7 @@ void llvm::ParseInputMachO(StringRef Filename) {
             for (Archive::child_iterator AI = A->child_begin(),
                                          AE = A->child_end();
                  AI != AE; ++AI) {
-              if (AI->getError())
-                break;
-              auto &C = AI->get();
-              ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
+              ErrorOr<std::unique_ptr<Binary>> ChildOrErr = AI->getAsBinary();
               if (ChildOrErr.getError())
                 continue;
               if (MachOObjectFile *O =
@@ -1638,10 +1622,7 @@ void llvm::ParseInputMachO(StringRef Filename) {
           printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
         for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
              AI != AE; ++AI) {
-          if (AI->getError())
-            break;
-          auto &C = AI->get();
-          ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
+          ErrorOr<std::unique_ptr<Binary>> ChildOrErr = AI->getAsBinary();
           if (ChildOrErr.getError())
             continue;
           if (MachOObjectFile *O =
index 34401937bd801b723fe1aaca33f97c2cb8ed58c6..7292841c55a11d94e32a34c48fe155b3f8f72a6a 100644 (file)
@@ -1536,12 +1536,7 @@ static void DumpObject(const ObjectFile *o) {
 
 /// @brief Dump each object file in \a a;
 static void DumpArchive(const Archive *a) {
-  for (auto &ErrorOrChild : a->children()) {
-    if (std::error_code EC = ErrorOrChild.getError()) {
-      report_error(a->getFileName(), EC);
-      break;
-    }
-    const Archive::Child &C = *ErrorOrChild;
+  for (const Archive::Child &C : a->children()) {
     ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
     if (std::error_code EC = ChildOrErr.getError())
       if (EC != object_error::invalid_file_type)
index b59579de49dba8ca1a836d7770f9c64fe9f689a3..cb0c9c6418e610737016b57075763f28cb5fc0d4 100644 (file)
@@ -377,12 +377,7 @@ static void dumpObject(const ObjectFile *Obj) {
 
 /// @brief Dumps each object file in \a Arc;
 static void dumpArchive(const Archive *Arc) {
-  for (auto &ErrorOrChild : Arc->children()) {
-    if (std::error_code EC = ErrorOrChild.getError()) {
-      reportError(Arc->getFileName(), EC.message());
-      break;
-    }
-    const auto &Child = *ErrorOrChild;
+  for (const auto &Child : Arc->children()) {
     ErrorOr<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary();
     if (std::error_code EC = ChildOrErr.getError()) {
       // Ignore non-object files.
index cc857624548afd030f2263a28ded918ac4e9a0ea..de2b0450523465421fef87f6cceca8751c74f0ac 100644 (file)
@@ -427,13 +427,7 @@ static void PrintFileSectionSizes(StringRef file) {
     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";
-        break;
-      }
-      auto &c = i->get();
-      ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
+      ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
       if (std::error_code EC = ChildOrErr.getError()) {
         errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
         continue;
@@ -495,13 +489,7 @@ static void PrintFileSectionSizes(StringRef file) {
               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";
-                  break;
-                }
-                auto &c = i->get();
-                ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
+                ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
                 if (std::error_code EC = ChildOrErr.getError()) {
                   errs() << ToolName << ": " << file << ": " << EC.message()
                          << ".\n";
@@ -578,13 +566,7 @@ static void PrintFileSectionSizes(StringRef file) {
             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";
-                break;
-              }
-              auto &c = i->get();
-              ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
+              ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
               if (std::error_code EC = ChildOrErr.getError()) {
                 errs() << ToolName << ": " << file << ": " << EC.message()
                        << ".\n";
@@ -648,13 +630,7 @@ static void PrintFileSectionSizes(StringRef file) {
         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";
-            break;
-          }
-          auto &c = i->get();
-          ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
+          ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
           if (std::error_code EC = ChildOrErr.getError()) {
             errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
             continue;