<div dir="ltr">This patch is causing <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/14630/steps/build%20clang%2Fmsan/logs/stdio">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/14630/steps/build%20clang%2Fmsan/logs/stdio</a><br><div>Please let me know if you have a fix, or I'll have to revert it.</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 13, 2016 at 2:20 PM Lang Hames via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: lhames<br>
Date: Wed Jul 13 16:13:05 2016<br>
New Revision: 275316<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=275316&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=275316&view=rev</a><br>
Log:<br>
[Object] Change Archive::child_iterator for better interop with Error/Expected.<br>
<br>
See <a href="http://reviews.llvm.org/D22079" rel="noreferrer" target="_blank">http://reviews.llvm.org/D22079</a><br>
<br>
Changes the Archive::child_begin and Archive::children to require a reference<br>
to an Error. If iterator increment fails (because the archive header is<br>
damaged) the iterator will be set to 'end()', and the error stored in the<br>
given Error&. The Error value should be checked by the user immediately after<br>
the loop. E.g.:<br>
<br>
Error Err;<br>
for (auto &C : A->children(Err)) {<br>
 // Do something with archive child C.<br>
}<br>
// Check the error immediately after the loop.<br>
if (Err)<br>
 return Err;<br>
<br>
Failure to check the Error will result in an abort() when the Error goes out of<br>
scope (as guaranteed by the Error class).<br>
<br>
<br>
Modified:<br>
  llvm/trunk/include/llvm/Object/Archive.h<br>
  llvm/trunk/include/llvm/Support/Error.h<br>
  llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp<br>
  llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h<br>
  llvm/trunk/lib/Object/Archive.cpp<br>
  llvm/trunk/lib/Support/Error.cpp<br>
  llvm/trunk/tools/dsymutil/BinaryHolder.cpp<br>
  llvm/trunk/tools/llvm-ar/llvm-ar.cpp<br>
  llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp<br>
  llvm/trunk/tools/llvm-nm/llvm-nm.cpp<br>
  llvm/trunk/tools/llvm-objdump/MachODump.cpp<br>
  llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp<br>
  llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp<br>
  llvm/trunk/tools/llvm-size/llvm-size.cpp<br>
  llvm/trunk/tools/sancov/sancov.cc<br>
<br>
Modified: llvm/trunk/include/llvm/Object/Archive.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Object/Archive.h (original)<br>
+++ llvm/trunk/include/llvm/Object/Archive.h Wed Jul 13 16:13:05 2016<br>
@@ -106,21 +106,20 @@ public:<br>
  };<br>
<br>
  class child_iterator {<br>
-Â Â ErrorOr<Child> child;<br>
+Â Â Child C;<br>
+Â Â Error *E;<br>
<br>
  public:<br>
-Â Â child_iterator() : child(Child(nullptr, nullptr, nullptr)) {}<br>
-Â Â child_iterator(const Child &c) : child(c) {}<br>
-Â Â child_iterator(std::error_code EC) : child(EC) {}<br>
-Â Â const ErrorOr<Child> *operator->() const { return &child; }<br>
-Â Â const ErrorOr<Child> &operator*() const { return child; }<br>
+Â Â child_iterator() : C(Child(nullptr, nullptr, nullptr)), E(nullptr) {}<br>
+Â Â child_iterator(const Child &C, Error *E) : C(C), E(E) {}<br>
+Â Â const Child *operator->() const { return &C; }<br>
+Â Â const Child &operator*() const { return C; }<br>
<br>
   bool operator==(const child_iterator &other) const {<br>
-Â Â Â // We ignore error states so that comparisions with end() work, which<br>
-Â Â Â // allows range loops.<br>
-Â Â Â if (child.getError() || other.child.getError())<br>
-Â Â Â Â return false;<br>
-Â Â Â return *child == *other.child;<br>
+Â Â Â // Ignore errors here: If an error occurred during increment then getNext<br>
+Â Â Â // will have been set to child_end(), and the following comparison should<br>
+Â Â Â // do the right thing.<br>
+Â Â Â return C == other.C;<br>
   }<br>
<br>
   bool operator!=(const child_iterator &other) const {<br>
@@ -130,8 +129,15 @@ public:<br>
   // Code in loops with child_iterators must check for errors on each loop<br>
   // iteration. And if there is an error break out of the loop.<br>
   child_iterator &operator++() { // Preincrement<br>
-Â Â Â assert(child && "Can't increment iterator with error");<br>
-Â Â Â child = child->getNext();<br>
+Â Â Â assert(E && "Can't increment iterator with no Error attached");<br>
+Â Â Â if (auto ChildOrErr = C.getNext())<br>
+Â Â Â Â C = *ChildOrErr;<br>
+Â Â Â else {<br>
+Â Â Â Â ErrorAsOutParameter ErrAsOutParam(*E);<br>
+Â Â Â Â C = C.getParent()->child_end().C;<br>
+Â Â Â Â *E = errorCodeToError(ChildOrErr.getError());<br>
+Â Â Â Â E = nullptr;<br>
+Â Â Â }<br>
    return *this;<br>
   }<br>
  };<br>
@@ -190,10 +196,11 @@ public:<br>
  Kind kind() const { return (Kind)Format; }<br>
  bool isThin() const { return IsThin; }<br>
<br>
-Â child_iterator child_begin(bool SkipInternal = true) const;<br>
+Â child_iterator child_begin(Error &Err, bool SkipInternal = true) const;<br>
  child_iterator child_end() const;<br>
-Â iterator_range<child_iterator> children(bool SkipInternal = true) const {<br>
-Â Â return make_range(child_begin(SkipInternal), child_end());<br>
+Â iterator_range<child_iterator> children(Error &Err,<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â bool SkipInternal = true) const {<br>
+Â Â return make_range(child_begin(Err, SkipInternal), child_end());<br>
  }<br>
<br>
  symbol_iterator symbol_begin() const;<br>
@@ -208,7 +215,7 @@ public:<br>
  }<br>
<br>
  // check if a symbol is in the archive<br>
-Â child_iterator findSym(StringRef name) const;<br>
+Â child_iterator findSym(Error &Err, StringRef name) const;<br>
<br>
  bool hasSymbolTable() const;<br>
  StringRef getSymbolTable() const { return SymbolTable; }<br>
<br>
Modified: llvm/trunk/include/llvm/Support/Error.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Error.h?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Error.h?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/Error.h (original)<br>
+++ llvm/trunk/include/llvm/Support/Error.h Wed Jul 13 16:13:05 2016<br>
@@ -940,6 +940,11 @@ private:<br>
  std::function<int(const Error &)> GetExitCode;<br>
 };<br>
<br>
+/// Report a serious error, calling any installed error handler. See<br>
+/// ErrorHandling.h.<br>
+LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err,<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â bool gen_crash_diag = true);<br>
+<br>
 } // namespace llvm<br>
<br>
 #endif // LLVM_SUPPORT_ERROR_H<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp Wed Jul 13 16:13:05 2016<br>
@@ -327,13 +327,14 @@ RuntimeDyld::SymbolInfo MCJIT::findSymbo<br>
  for (object::OwningBinary<object::Archive> &OB : Archives) {<br>
   object::Archive *A = OB.getBinary();<br>
   // Look for our symbols in each Archive<br>
-Â Â object::Archive::child_iterator ChildIt = A->findSym(Name);<br>
-Â Â if (std::error_code EC = ChildIt->getError())<br>
-Â Â Â report_fatal_error(EC.message());<br>
+Â Â Error Err;<br>
+Â Â object::Archive::child_iterator ChildIt = A->findSym(Err, Name);<br>
+Â Â if (Err)<br>
+Â Â Â report_fatal_error(std::move(Err));<br>
   if (ChildIt != A->child_end()) {<br>
    // FIXME: Support nested archives?<br>
    Expected<std::unique_ptr<object::Binary>> ChildBinOrErr =<br>
-Â Â Â Â Â (*ChildIt)->getAsBinary();<br>
+Â Â Â Â Â ChildIt->getAsBinary();<br>
    if (!ChildBinOrErr) {<br>
     // TODO: Actually report errors helpfully.<br>
     consumeError(ChildBinOrErr.takeError());<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/Orc/OrcMCJITReplacement.h Wed Jul 13 16:13:05 2016<br>
@@ -258,13 +258,14 @@ private:<br>
   for (object::OwningBinary<object::Archive> &OB : Archives) {<br>
    object::Archive *A = OB.getBinary();<br>
    // Look for our symbols in each Archive<br>
-Â Â Â object::Archive::child_iterator ChildIt = A->findSym(Name);<br>
-Â Â Â if (std::error_code EC = ChildIt->getError())<br>
-Â Â Â Â report_fatal_error(EC.message());<br>
+Â Â Â Error Err;<br>
+Â Â Â object::Archive::child_iterator ChildIt = A->findSym(Err, Name);<br>
+Â Â Â if (Err)<br>
+Â Â Â Â report_fatal_error(std::move(Err));<br>
    if (ChildIt != A->child_end()) {<br>
     // FIXME: Support nested archives?<br>
     Expected<std::unique_ptr<object::Binary>> ChildBinOrErr =<br>
-Â Â Â Â Â Â (*ChildIt)->getAsBinary();<br>
+Â Â Â Â Â Â ChildIt->getAsBinary();<br>
     if (!ChildBinOrErr) {<br>
      // TODO: Actually report errors helpfully.<br>
      consumeError(ChildBinOrErr.takeError());<br>
<br>
Modified: llvm/trunk/lib/Object/Archive.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Object/Archive.cpp (original)<br>
+++ llvm/trunk/lib/Object/Archive.cpp Wed Jul 13 16:13:05 2016<br>
@@ -298,12 +298,9 @@ Archive::Archive(MemoryBufferRef Source,<br>
  }<br>
<br>
  // Get the special members.<br>
-Â child_iterator I = child_begin(false);<br>
-Â std::error_code ec;<br>
-Â if ((ec = I->getError())) {<br>
-Â Â Err = errorCodeToError(ec);<br>
+Â child_iterator I = child_begin(Err, false);<br>
+Â if (Err)<br>
   return;<br>
-Â }<br>
  child_iterator E = child_end();<br>
<br>
  // This is at least a valid empty archive. Since an empty archive is the<br>
@@ -315,13 +312,13 @@ Archive::Archive(MemoryBufferRef Source,<br>
   Err = Error::success();<br>
   return;<br>
  }<br>
-Â const Child *C = &**I;<br>
+Â const Child *C = &*I;<br>
<br>
  auto Increment = [&]() {<br>
   ++I;<br>
-Â Â if ((Err = errorCodeToError(I->getError())))<br>
+Â Â if (Err)<br>
    return true;<br>
-Â Â C = &**I;<br>
+Â Â C = &*I;<br>
   return false;<br>
  };<br>
<br>
@@ -366,8 +363,7 @@ Archive::Archive(MemoryBufferRef Source,<br>
   Format = K_BSD;<br>
   // We know this is BSD, so getName will work since there is no string table.<br>
   ErrorOr<StringRef> NameOrErr = C->getName();<br>
-Â Â ec = NameOrErr.getError();<br>
-Â Â if (ec) {<br>
+Â Â if (auto ec = NameOrErr.getError()) {<br>
    Err = errorCodeToError(ec);<br>
    return;<br>
   }<br>
@@ -465,23 +461,29 @@ Archive::Archive(MemoryBufferRef Source,<br>
  Err = Error::success();<br>
 }<br>
<br>
-Archive::child_iterator Archive::child_begin(bool SkipInternal) const {<br>
+Archive::child_iterator Archive::child_begin(Error &Err,<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â bool SkipInternal) const {<br>
  if (Data.getBufferSize() == 8) // empty archive.<br>
   return child_end();<br>
<br>
  if (SkipInternal)<br>
-Â Â return Child(this, FirstRegularData, FirstRegularStartOfFile);<br>
+Â Â return child_iterator(Child(this, FirstRegularData,<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â FirstRegularStartOfFile),<br>
+Â Â Â Â Â Â Â Â Â Â Â Â Â &Err);<br>
<br>
  const char *Loc = Data.getBufferStart() + strlen(Magic);<br>
  std::error_code EC;<br>
-Â Child c(this, Loc, &EC);<br>
-Â if (EC)<br>
-Â Â return child_iterator(EC);<br>
-Â return child_iterator(c);<br>
+Â Child C(this, Loc, &EC);<br>
+Â if (EC) {<br>
+Â Â ErrorAsOutParameter ErrAsOutParam(Err);<br>
+Â Â Err = errorCodeToError(EC);<br>
+Â Â return child_end();<br>
+Â }<br>
+Â return child_iterator(C, &Err);<br>
 }<br>
<br>
 Archive::child_iterator Archive::child_end() const {<br>
-Â return Child(this, nullptr, nullptr);<br>
+Â return child_iterator(Child(this, nullptr, nullptr), nullptr);<br>
 }<br>
<br>
 StringRef Archive::Symbol::getName() const {<br>
@@ -665,18 +667,20 @@ uint32_t Archive::getNumberOfSymbols() c<br>
  return read32le(buf);<br>
 }<br>
<br>
-Archive::child_iterator Archive::findSym(StringRef name) const {<br>
+Archive::child_iterator Archive::findSym(Error &Err, StringRef name) const {<br>
  Archive::symbol_iterator bs = symbol_begin();<br>
  Archive::symbol_iterator es = symbol_end();<br>
<br>
  for (; bs != es; ++bs) {<br>
   StringRef SymName = bs->getName();<br>
   if (SymName == name) {<br>
-Â Â Â ErrorOr<Archive::child_iterator> ResultOrErr = bs->getMember();<br>
-Â Â Â // FIXME: Should we really eat the error?<br>
-Â Â Â if (ResultOrErr.getError())<br>
+Â Â Â if (auto MemberOrErr = bs->getMember()) {<br>
+Â Â Â Â return child_iterator(*MemberOrErr, &Err);<br>
+Â Â Â } else {<br>
+Â Â Â Â ErrorAsOutParameter ErrAsOutParam(Err);<br>
+Â Â Â Â Err = errorCodeToError(MemberOrErr.getError());<br>
     return child_end();<br>
-Â Â Â return ResultOrErr.get();<br>
+Â Â Â }<br>
   }<br>
  }<br>
  return child_end();<br>
<br>
Modified: llvm/trunk/lib/Support/Error.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Error.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Error.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Error.cpp (original)<br>
+++ llvm/trunk/lib/Support/Error.cpp Wed Jul 13 16:13:05 2016<br>
@@ -64,6 +64,7 @@ void logAllUnhandledErrors(Error E, raw_<br>
  });<br>
 }<br>
<br>
+<br>
 std::error_code ErrorList::convertToErrorCode() const {<br>
  return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors),<br>
             *ErrorErrorCat);<br>
@@ -99,4 +100,14 @@ std::error_code StringError::convertToEr<br>
  return EC;<br>
 }<br>
<br>
+void report_fatal_error(Error Err, bool GenCrashDiag) {<br>
+Â assert(Err && "report_fatal_error called with success value");<br>
+Â std::string ErrMsg;<br>
+Â {<br>
+Â Â raw_string_ostream ErrStream(ErrMsg);<br>
+Â Â logAllUnhandledErrors(std::move(Err), ErrStream, "");<br>
+Â }<br>
+Â report_fatal_error(ErrMsg);<br>
+}<br>
+<br>
 }<br>
<br>
Modified: llvm/trunk/tools/dsymutil/BinaryHolder.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/BinaryHolder.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/BinaryHolder.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/dsymutil/BinaryHolder.cpp (original)<br>
+++ llvm/trunk/tools/dsymutil/BinaryHolder.cpp Wed Jul 13 16:13:05 2016<br>
@@ -102,10 +102,8 @@ BinaryHolder::GetArchiveMemberBuffers(St<br>
  Buffers.reserve(CurrentArchives.size());<br>
<br>
  for (const auto &CurrentArchive : CurrentArchives) {<br>
-Â Â for (auto ChildOrErr : CurrentArchive->children()) {<br>
-Â Â Â if (std::error_code Err = ChildOrErr.getError())<br>
-Â Â Â Â return Err;<br>
-Â Â Â const auto &Child = *ChildOrErr;<br>
+Â Â Error Err;<br>
+Â Â for (auto Child : CurrentArchive->children(Err)) {<br>
    if (auto NameOrErr = Child.getName()) {<br>
     if (*NameOrErr == Filename) {<br>
      if (Timestamp != sys::TimeValue::PosixZeroTime() &&<br>
@@ -123,6 +121,8 @@ BinaryHolder::GetArchiveMemberBuffers(St<br>
     }<br>
    }<br>
   }<br>
+Â Â if (Err)<br>
+Â Â Â return errorToErrorCode(std::move(Err));<br>
  }<br>
<br>
  if (Buffers.empty())<br>
<br>
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)<br>
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Wed Jul 13 16:13:05 2016<br>
@@ -405,35 +405,37 @@ static void performReadOperation(Archive<br>
   fail("extracting from a thin archive is not supported");<br>
<br>
  bool Filter = !Members.empty();<br>
-Â for (auto &ChildOrErr : OldArchive->children()) {<br>
-Â Â failIfError(ChildOrErr.getError());<br>
-Â Â const object::Archive::Child &C = *ChildOrErr;<br>
-<br>
-Â Â ErrorOr<StringRef> NameOrErr = C.getName();<br>
-Â Â failIfError(NameOrErr.getError());<br>
-Â Â StringRef Name = NameOrErr.get();<br>
-<br>
-Â Â if (Filter) {<br>
-Â Â Â auto I = std::find(Members.begin(), Members.end(), Name);<br>
-Â Â Â if (I == Members.end())<br>
-Â Â Â Â continue;<br>
-Â Â Â Members.erase(I);<br>
-Â Â }<br>
+Â {<br>
+Â Â Error Err;<br>
+Â Â for (auto &C : OldArchive->children(Err)) {<br>
+Â Â Â ErrorOr<StringRef> NameOrErr = C.getName();<br>
+Â Â Â failIfError(NameOrErr.getError());<br>
+Â Â Â StringRef Name = NameOrErr.get();<br>
<br>
-Â Â switch (Operation) {<br>
-Â Â default:<br>
-Â Â Â llvm_unreachable("Not a read operation");<br>
-Â Â case Print:<br>
-Â Â Â doPrint(Name, C);<br>
-Â Â Â break;<br>
-Â Â case DisplayTable:<br>
-Â Â Â doDisplayTable(Name, C);<br>
-Â Â Â break;<br>
-Â Â case Extract:<br>
-Â Â Â doExtract(Name, C);<br>
-Â Â Â break;<br>
+Â Â Â if (Filter) {<br>
+Â Â Â Â auto I = std::find(Members.begin(), Members.end(), Name);<br>
+Â Â Â Â if (I == Members.end())<br>
+Â Â Â Â Â continue;<br>
+Â Â Â Â Members.erase(I);<br>
+Â Â Â }<br>
+<br>
+Â Â Â switch (Operation) {<br>
+Â Â Â default:<br>
+Â Â Â Â llvm_unreachable("Not a read operation");<br>
+Â Â Â case Print:<br>
+Â Â Â Â doPrint(Name, C);<br>
+Â Â Â Â break;<br>
+Â Â Â case DisplayTable:<br>
+Â Â Â Â doDisplayTable(Name, C);<br>
+Â Â Â Â break;<br>
+Â Â Â case Extract:<br>
+Â Â Â Â doExtract(Name, C);<br>
+Â Â Â Â break;<br>
+Â Â Â }<br>
   }<br>
+Â Â failIfError(std::move(Err));<br>
  }<br>
+<br>
  if (Members.empty())<br>
   return;<br>
  for (StringRef Name : Members)<br>
@@ -531,9 +533,8 @@ computeNewArchiveMembers(ArchiveOperatio<br>
  int InsertPos = -1;<br>
  StringRef PosName = sys::path::filename(RelPos);<br>
  if (OldArchive) {<br>
-Â Â for (auto &ChildOrErr : OldArchive->children()) {<br>
-Â Â Â failIfError(ChildOrErr.getError());<br>
-Â Â Â auto &Child = ChildOrErr.get();<br>
+Â Â Error Err;<br>
+Â Â for (auto &Child : OldArchive->children(Err)) {<br>
    int Pos = Ret.size();<br>
    ErrorOr<StringRef> NameOrErr = Child.getName();<br>
    failIfError(NameOrErr.getError());<br>
@@ -568,6 +569,7 @@ computeNewArchiveMembers(ArchiveOperatio<br>
    if (MemberI != Members.end())<br>
     Members.erase(MemberI);<br>
   }<br>
+Â Â failIfError(std::move(Err));<br>
  }<br>
<br>
  if (Operation == Delete)<br>
@@ -764,9 +766,11 @@ static void runMRIScript() {<br>
          "Could not parse library");<br>
    Archives.push_back(std::move(*LibOrErr));<br>
    object::Archive &Lib = *Archives.back();<br>
-Â Â Â for (auto &MemberOrErr : Lib.children()) {<br>
-Â Â Â Â failIfError(MemberOrErr.getError());<br>
-Â Â Â Â addMember(NewMembers, *MemberOrErr);<br>
+Â Â Â {<br>
+Â Â Â Â Error Err;<br>
+Â Â Â Â for (auto &Member : Lib.children(Err))<br>
+Â Â Â Â Â addMember(NewMembers, Member);<br>
+Â Â Â Â failIfError(std::move(Err));<br>
    }<br>
    break;<br>
   }<br>
<br>
Modified: llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp (original)<br>
+++ llvm/trunk/tools/llvm-cxxdump/llvm-cxxdump.cpp Wed Jul 13 16:13:05 2016<br>
@@ -50,6 +50,14 @@ static void error(std::error_code EC) {<br>
  exit(1);<br>
 }<br>
<br>
+static void error(Error Err) {<br>
+Â if (Err) {<br>
+Â Â logAllUnhandledErrors(std::move(Err), outs(), "Error reading file: ");<br>
+Â Â outs().flush();<br>
+Â Â exit(1);<br>
+Â }<br>
+}<br>
+<br>
 } // namespace llvm<br>
<br>
 static void reportError(StringRef Input, StringRef Message) {<br>
@@ -482,9 +490,8 @@ static void dumpCXXData(const ObjectFile<br>
 }<br>
<br>
 static void dumpArchive(const Archive *Arc) {<br>
-Â for (auto &ErrorOrChild : Arc->children()) {<br>
-Â Â error(ErrorOrChild.getError());<br>
-Â Â const Archive::Child &ArcC = *ErrorOrChild;<br>
+Â Error Err;<br>
+Â for (auto &ArcC : Arc->children(Err)) {<br>
   Expected<std::unique_ptr<Binary>> ChildOrErr = ArcC.getAsBinary();<br>
   if (!ChildOrErr) {<br>
    // Ignore non-object files.<br>
@@ -504,6 +511,7 @@ static void dumpArchive(const Archive *A<br>
   else<br>
    reportError(Arc->getFileName(), cxxdump_error::unrecognized_file_format);<br>
  }<br>
+Â error(std::move(Err));<br>
 }<br>
<br>
 static void dumpInput(StringRef File) {<br>
<br>
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)<br>
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Wed Jul 13 16:13:05 2016<br>
@@ -1109,30 +1109,31 @@ static void dumpSymbolNamesFromFile(std:<br>
    }<br>
   }<br>
<br>
-Â Â for (Archive::child_iterator I = A->child_begin(), E = A->child_end();<br>
-Â Â Â Â Â I != E; ++I) {<br>
-Â Â Â if (error(I->getError()))<br>
-Â Â Â Â return;<br>
-Â Â Â auto &C = I->get();<br>
-Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context);<br>
-Â Â Â if (!ChildOrErr) {<br>
-Â Â Â Â if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))<br>
-Â Â Â Â Â error(std::move(E), Filename, C);<br>
-Â Â Â Â continue;<br>
-Â Â Â }<br>
-Â Â Â if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {<br>
-Â Â Â Â if (!checkMachOAndArchFlags(O, Filename))<br>
-Â Â Â Â Â return;<br>
-Â Â Â Â if (!PrintFileName) {<br>
-Â Â Â Â Â outs() << "\n";<br>
-Â Â Â Â Â if (isa<MachOObjectFile>(O)) {<br>
-Â Â Â Â Â Â outs() << Filename << "(" << O->getFileName() << ")";<br>
-Â Â Â Â Â } else<br>
-Â Â Â Â Â Â outs() << O->getFileName();<br>
-Â Â Â Â Â outs() << ":\n";<br>
+Â Â {<br>
+Â Â Â Error Err;<br>
+Â Â Â for (auto &C : A->children(Err)) {<br>
+Â Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context);<br>
+Â Â Â Â if (!ChildOrErr) {<br>
+Â Â Â Â Â if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))<br>
+Â Â Â Â Â Â error(std::move(E), Filename, C);<br>
+Â Â Â Â Â continue;<br>
+Â Â Â Â }<br>
+Â Â Â Â if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {<br>
+Â Â Â Â Â if (!checkMachOAndArchFlags(O, Filename))<br>
+Â Â Â Â Â Â return;<br>
+Â Â Â Â Â if (!PrintFileName) {<br>
+Â Â Â Â Â Â outs() << "\n";<br>
+Â Â Â Â Â Â if (isa<MachOObjectFile>(O)) {<br>
+Â Â Â Â Â Â Â outs() << Filename << "(" << O->getFileName() << ")";<br>
+Â Â Â Â Â Â } else<br>
+Â Â Â Â Â Â Â outs() << O->getFileName();<br>
+Â Â Â Â Â Â outs() << ":\n";<br>
+Â Â Â Â Â }<br>
+Â Â Â Â Â dumpSymbolNamesFromObject(*O, false, Filename);<br>
     }<br>
-Â Â Â Â dumpSymbolNamesFromObject(*O, false, Filename);<br>
    }<br>
+Â Â Â if (Err)<br>
+Â Â Â Â error(std::move(Err), A->getFileName());<br>
   }<br>
   return;<br>
  }<br>
@@ -1174,12 +1175,8 @@ static void dumpSymbolNamesFromFile(std:<br>
       } else if (Expected<std::unique_ptr<Archive>> AOrErr =<br>
              I->getAsArchive()) {<br>
        std::unique_ptr<Archive> &A = *AOrErr;<br>
-Â Â Â Â Â Â Â for (Archive::child_iterator AI = A->child_begin(),<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â AE = A->child_end();<br>
-Â Â Â Â Â Â Â Â Â Â AI != AE; ++AI) {<br>
-Â Â Â Â Â Â Â Â if (error(AI->getError()))<br>
-Â Â Â Â Â Â Â Â Â return;<br>
-Â Â Â Â Â Â Â Â auto &C = AI->get();<br>
+Â Â Â Â Â Â Â Error Err;<br>
+Â Â Â Â Â Â Â for (auto &C : A->children(Err)) {<br>
         Expected<std::unique_ptr<Binary>> ChildOrErr =<br>
           C.getAsBinary(&Context);<br>
         if (!ChildOrErr) {<br>
@@ -1209,6 +1206,8 @@ static void dumpSymbolNamesFromFile(std:<br>
                       ArchitectureName);<br>
         }<br>
        }<br>
+Â Â Â Â Â Â Â if (Err)<br>
+Â Â Â Â Â Â Â Â error(std::move(Err), A->getFileName());<br>
       } else {<br>
        consumeError(AOrErr.takeError());<br>
        error(Filename + " for architecture " +<br>
@@ -1247,12 +1246,8 @@ static void dumpSymbolNamesFromFile(std:<br>
      } else if (Expected<std::unique_ptr<Archive>> AOrErr =<br>
             I->getAsArchive()) {<br>
       std::unique_ptr<Archive> &A = *AOrErr;<br>
-Â Â Â Â Â Â for (Archive::child_iterator AI = A->child_begin(),<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â AE = A->child_end();<br>
-Â Â Â Â Â Â Â Â Â AI != AE; ++AI) {<br>
-Â Â Â Â Â Â Â if (error(AI->getError()))<br>
-Â Â Â Â Â Â Â Â return;<br>
-Â Â Â Â Â Â Â auto &C = AI->get();<br>
+Â Â Â Â Â Â Error Err;<br>
+Â Â Â Â Â Â for (auto &C : A->children(Err)) {<br>
        Expected<std::unique_ptr<Binary>> ChildOrErr =<br>
          C.getAsBinary(&Context);<br>
        if (!ChildOrErr) {<br>
@@ -1272,6 +1267,8 @@ static void dumpSymbolNamesFromFile(std:<br>
         dumpSymbolNamesFromObject(*O, false, ArchiveName);<br>
        }<br>
       }<br>
+Â Â Â Â Â Â if (Err)<br>
+Â Â Â Â Â Â Â error(std::move(Err), A->getFileName());<br>
      } else {<br>
       consumeError(AOrErr.takeError());<br>
       error(Filename + " for architecture " +<br>
@@ -1316,11 +1313,8 @@ static void dumpSymbolNamesFromFile(std:<br>
    } else if (Expected<std::unique_ptr<Archive>> AOrErr =<br>
          I->getAsArchive()) {<br>
     std::unique_ptr<Archive> &A = *AOrErr;<br>
-Â Â Â Â for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();<br>
-Â Â Â Â Â Â Â AI != AE; ++AI) {<br>
-Â Â Â Â Â if (error(AI->getError()))<br>
-Â Â Â Â Â Â return;<br>
-Â Â Â Â Â auto &C = AI->get();<br>
+Â Â Â Â Error Err;<br>
+Â Â Â Â for (auto &C : A->children(Err)) {<br>
      Expected<std::unique_ptr<Binary>> ChildOrErr =<br>
       C.getAsBinary(&Context);<br>
      if (!ChildOrErr) {<br>
@@ -1349,6 +1343,8 @@ static void dumpSymbolNamesFromFile(std:<br>
       dumpSymbolNamesFromObject(*O, false, ArchiveName, ArchitectureName);<br>
      }<br>
     }<br>
+Â Â Â Â if (Err)<br>
+Â Â Â Â Â error(std::move(Err), A->getFileName());<br>
    } else {<br>
     consumeError(AOrErr.takeError());<br>
     error(Filename + " for architecture " +<br>
<br>
Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)<br>
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Wed Jul 13 16:13:05 2016<br>
@@ -1535,13 +1535,11 @@ static void printArchiveChild(const Arch<br>
 }<br>
<br>
 static void printArchiveHeaders(Archive *A, bool verbose, bool print_offset) {<br>
-Â for (Archive::child_iterator I = A->child_begin(false), E = A->child_end();<br>
-Â Â Â Â I != E; ++I) {<br>
-Â Â if (std::error_code EC = I->getError())<br>
-Â Â Â report_fatal_error(EC.message());<br>
-Â Â const Archive::Child &C = **I;<br>
+Â Error Err;<br>
+Â for (const auto &C : A->children(Err, false))<br>
   printArchiveChild(C, verbose, print_offset);<br>
-Â }<br>
+Â if (Err)<br>
+Â Â report_fatal_error(std::move(Err));<br>
 }<br>
<br>
 // ParseInputMachO() parses the named Mach-O file in Filename and handles the<br>
@@ -1572,11 +1570,8 @@ void llvm::ParseInputMachO(StringRef Fil<br>
   outs() << "Archive : " << Filename << "\n";<br>
   if (ArchiveHeaders)<br>
    printArchiveHeaders(A, !NonVerbose, ArchiveMemberOffsets);<br>
-Â Â for (Archive::child_iterator I = A->child_begin(), E = A->child_end();<br>
-Â Â Â Â Â I != E; ++I) {<br>
-Â Â Â if (std::error_code EC = I->getError())<br>
-Â Â Â Â report_error(Filename, EC);<br>
-Â Â Â auto &C = I->get();<br>
+Â Â Error Err;<br>
+Â Â for (auto &C : A->children(Err)) {<br>
    Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();<br>
    if (!ChildOrErr) {<br>
     if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))<br>
@@ -1589,6 +1584,8 @@ void llvm::ParseInputMachO(StringRef Fil<br>
     ProcessMachO(Filename, O, O->getFileName());<br>
    }<br>
   }<br>
+Â Â if (Err)<br>
+Â Â Â report_error(Filename, std::move(Err));<br>
   return;<br>
  }<br>
  if (UniversalHeaders) {<br>
@@ -1630,12 +1627,8 @@ void llvm::ParseInputMachO(StringRef Fil<br>
        outs() << "\n";<br>
        if (ArchiveHeaders)<br>
         printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);<br>
-Â Â Â Â Â Â Â for (Archive::child_iterator AI = A->child_begin(),<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â AE = A->child_end();<br>
-Â Â Â Â Â Â Â Â Â Â AI != AE; ++AI) {<br>
-Â Â Â Â Â Â Â Â if (std::error_code EC = AI->getError())<br>
-Â Â Â Â Â Â Â Â Â report_error(Filename, EC);<br>
-Â Â Â Â Â Â Â Â auto &C = AI->get();<br>
+Â Â Â Â Â Â Â Error Err;<br>
+Â Â Â Â Â Â Â for (auto &C : A->children(Err)) {<br>
         Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();<br>
         if (!ChildOrErr) {<br>
          if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))<br>
@@ -1646,6 +1639,8 @@ void llvm::ParseInputMachO(StringRef Fil<br>
             dyn_cast<MachOObjectFile>(&*ChildOrErr.get()))<br>
          ProcessMachO(Filename, O, O->getFileName(), ArchitectureName);<br>
        }<br>
+Â Â Â Â Â Â Â if (Err)<br>
+Â Â Â Â Â Â Â Â report_error(Filename, std::move(Err));<br>
       } else {<br>
        consumeError(AOrErr.takeError());<br>
        error("Mach-O universal file: " + Filename + " for " +<br>
@@ -1687,12 +1682,8 @@ void llvm::ParseInputMachO(StringRef Fil<br>
       outs() << "Archive : " << Filename << "\n";<br>
       if (ArchiveHeaders)<br>
        printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);<br>
-Â Â Â Â Â Â for (Archive::child_iterator AI = A->child_begin(),<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â AE = A->child_end();<br>
-Â Â Â Â Â Â Â Â Â AI != AE; ++AI) {<br>
-Â Â Â Â Â Â Â if (std::error_code EC = AI->getError())<br>
-Â Â Â Â Â Â Â Â report_error(Filename, EC);<br>
-Â Â Â Â Â Â Â auto &C = AI->get();<br>
+Â Â Â Â Â Â Error Err;<br>
+Â Â Â Â Â Â for (auto &C : A->children(Err)) {<br>
        Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();<br>
        if (!ChildOrErr) {<br>
         if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))<br>
@@ -1703,6 +1694,8 @@ void llvm::ParseInputMachO(StringRef Fil<br>
            dyn_cast<MachOObjectFile>(&*ChildOrErr.get()))<br>
         ProcessMachO(Filename, O, O->getFileName());<br>
       }<br>
+Â Â Â Â Â Â if (Err)<br>
+Â Â Â Â Â Â Â report_error(Filename, std::move(Err));<br>
      } else {<br>
       consumeError(AOrErr.takeError());<br>
       error("Mach-O universal file: " + Filename + " for architecture " +<br>
@@ -1740,11 +1733,8 @@ void llvm::ParseInputMachO(StringRef Fil<br>
     outs() << "\n";<br>
     if (ArchiveHeaders)<br>
      printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);<br>
-Â Â Â Â for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();<br>
-Â Â Â Â Â Â Â AI != AE; ++AI) {<br>
-Â Â Â Â Â if (std::error_code EC = AI->getError())<br>
-Â Â Â Â Â Â report_error(Filename, EC);<br>
-Â Â Â Â Â auto &C = AI->get();<br>
+Â Â Â Â Error Err;<br>
+Â Â Â Â for (auto &C : A->children(Err)) {<br>
      Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();<br>
      if (!ChildOrErr) {<br>
       if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))<br>
@@ -1758,6 +1748,8 @@ void llvm::ParseInputMachO(StringRef Fil<br>
              ArchitectureName);<br>
      }<br>
     }<br>
+Â Â Â Â if (Err)<br>
+Â Â Â Â Â report_error(Filename, std::move(Err));<br>
    } else {<br>
     consumeError(AOrErr.takeError());<br>
     error("Mach-O universal file: " + Filename + " for architecture " +<br>
<br>
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)<br>
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Jul 13 16:13:05 2016<br>
@@ -1702,10 +1702,8 @@ static void DumpObject(const ObjectFile<br>
<br>
 /// @brief Dump each object file in \a a;<br>
 static void DumpArchive(const Archive *a) {<br>
-Â for (auto &ErrorOrChild : a->children()) {<br>
-Â Â if (std::error_code EC = ErrorOrChild.getError())<br>
-Â Â Â report_error(a->getFileName(), EC);<br>
-Â Â const Archive::Child &C = *ErrorOrChild;<br>
+Â Error Err;<br>
+Â for (auto &C : a->children(Err)) {<br>
   Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();<br>
   if (!ChildOrErr) {<br>
    if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))<br>
@@ -1717,6 +1715,8 @@ static void DumpArchive(const Archive *a<br>
   else<br>
    report_error(a->getFileName(), object_error::invalid_file_type);<br>
  }<br>
+Â if (Err)<br>
+Â Â report_error(a->getFileName(), std::move(Err));<br>
 }<br>
<br>
 /// @brief Open file and figure out how to dump it.<br>
<br>
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)<br>
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Wed Jul 13 16:13:05 2016<br>
@@ -295,6 +295,17 @@ static void reportError(StringRef Input,<br>
  reportError(Twine(Input) + ": " + Message);<br>
 }<br>
<br>
+static void reportError(StringRef Input, Error Err) {<br>
+Â if (Input == "-")<br>
+Â Â Input = "<stdin>";<br>
+Â std::string ErrMsg;<br>
+Â {<br>
+Â Â raw_string_ostream ErrStream(ErrMsg);<br>
+Â Â logAllUnhandledErrors(std::move(Err), ErrStream, Input + ": ");<br>
+Â }<br>
+Â reportError(ErrMsg);<br>
+}<br>
+<br>
 static bool isMipsArch(unsigned Arch) {<br>
  switch (Arch) {<br>
  case llvm::Triple::mips:<br>
@@ -424,10 +435,8 @@ static void dumpObject(const ObjectFile<br>
<br>
 /// @brief Dumps each object file in \a Arc;<br>
 static void dumpArchive(const Archive *Arc) {<br>
-Â for (auto &ErrorOrChild : Arc->children()) {<br>
-Â Â if (std::error_code EC = ErrorOrChild.getError())<br>
-Â Â Â reportError(Arc->getFileName(), EC.message());<br>
-Â Â const auto &Child = *ErrorOrChild;<br>
+Â Error Err;<br>
+Â for (auto &Child : Arc->children(Err)) {<br>
   Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary();<br>
   if (!ChildOrErr) {<br>
    if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) {<br>
@@ -444,6 +453,8 @@ static void dumpArchive(const Archive *A<br>
   else<br>
    reportError(Arc->getFileName(), readobj_error::unrecognized_file_format);<br>
  }<br>
+Â if (Err)<br>
+Â Â reportError(Arc->getFileName(), std::move(Err));<br>
 }<br>
<br>
 /// @brief Dumps each object file in \a MachO Universal Binary;<br>
<br>
Modified: llvm/trunk/tools/llvm-size/llvm-size.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-size/llvm-size.cpp?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-size/llvm-size.cpp?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-size/llvm-size.cpp (original)<br>
+++ llvm/trunk/tools/llvm-size/llvm-size.cpp Wed Jul 13 16:13:05 2016<br>
@@ -527,15 +527,12 @@ static void printFileSectionSizes(String<br>
<br>
  if (Archive *a = dyn_cast<Archive>(&Bin)) {<br>
   // This is an archive. Iterate over each member and display its sizes.<br>
-Â Â for (object::Archive::child_iterator i = a->child_begin(),<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â e = a->child_end();<br>
-Â Â Â Â Â i != e; ++i) {<br>
-Â Â Â if (error(i->getError()))<br>
-Â Â Â Â exit(1);<br>
-Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary();<br>
+Â Â Error Err;<br>
+Â Â for (auto &C : a->children(Err)) {<br>
+Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();<br>
    if (!ChildOrErr) {<br>
     if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))<br>
-Â Â Â Â Â error(std::move(E), a->getFileName(), i->get());<br>
+Â Â Â Â Â error(std::move(E), a->getFileName(), C);<br>
     continue;<br>
    }<br>
    if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {<br>
@@ -555,6 +552,8 @@ static void printFileSectionSizes(String<br>
     }<br>
    }<br>
   }<br>
+Â Â if (Err)<br>
+Â Â Â error(std::move(Err), a->getFileName());<br>
  } else if (MachOUniversalBinary *UB =<br>
         dyn_cast<MachOUniversalBinary>(&Bin)) {<br>
   // If we have a list of architecture flags specified dump only those.<br>
@@ -597,17 +596,13 @@ static void printFileSectionSizes(String<br>
        std::unique_ptr<Archive> &UA = *AOrErr;<br>
        // This is an archive. Iterate over each member and display its<br>
        // sizes.<br>
-Â Â Â Â Â Â Â for (object::Archive::child_iterator i = UA->child_begin(),<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â e = UA->child_end();<br>
-Â Â Â Â Â Â Â Â Â Â i != e; ++i) {<br>
-Â Â Â Â Â Â Â Â if (error(i->getError()))<br>
-Â Â Â Â Â Â Â Â Â exit(1);<br>
-Â Â Â Â Â Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr =<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â i->get().getAsBinary();<br>
+Â Â Â Â Â Â Â Error Err;<br>
+Â Â Â Â Â Â Â for (auto &C : UA->children(Err)) {<br>
+Â Â Â Â Â Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();<br>
         if (!ChildOrErr) {<br>
          if (auto E = isNotObjectErrorInvalidFileType(<br>
                   ChildOrErr.takeError()))<br>
-Â Â Â Â Â Â Â Â Â Â error(std::move(E), UA->getFileName(), i->get(),<br>
+Â Â Â Â Â Â Â Â Â Â error(std::move(E), UA->getFileName(), C,<br>
              ArchFlags.size() > 1 ?<br>
              StringRef(I->getArchTypeName()) : StringRef());<br>
          continue;<br>
@@ -637,6 +632,8 @@ static void printFileSectionSizes(String<br>
          }<br>
         }<br>
        }<br>
+Â Â Â Â Â Â Â if (Err)<br>
+Â Â Â Â Â Â Â Â error(std::move(Err), UA->getFileName());<br>
       } else {<br>
        consumeError(AOrErr.takeError());<br>
        error("Mach-O universal file: " + file + " for architecture " +<br>
@@ -688,17 +685,13 @@ static void printFileSectionSizes(String<br>
       std::unique_ptr<Archive> &UA = *AOrErr;<br>
       // This is an archive. Iterate over each member and display its<br>
       // sizes.<br>
-Â Â Â Â Â Â for (object::Archive::child_iterator i = UA->child_begin(),<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â e = UA->child_end();<br>
-Â Â Â Â Â Â Â Â Â i != e; ++i) {<br>
-Â Â Â Â Â Â Â if (error(i->getError()))<br>
-Â Â Â Â Â Â Â Â exit(1);<br>
-Â Â Â Â Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr =<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â i->get().getAsBinary();<br>
+Â Â Â Â Â Â Error Err;<br>
+Â Â Â Â Â Â for (auto &C : UA->children(Err)) {<br>
+Â Â Â Â Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();<br>
        if (!ChildOrErr) {<br>
         if (auto E = isNotObjectErrorInvalidFileType(<br>
                 ChildOrErr.takeError()))<br>
-Â Â Â Â Â Â Â Â Â error(std::move(E), UA->getFileName(), i->get());<br>
+Â Â Â Â Â Â Â Â Â error(std::move(E), UA->getFileName(), C);<br>
         continue;<br>
        }<br>
        if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) {<br>
@@ -721,6 +714,8 @@ static void printFileSectionSizes(String<br>
         }<br>
        }<br>
       }<br>
+Â Â Â Â Â Â if (Err)<br>
+Â Â Â Â Â Â Â error(std::move(Err), UA->getFileName());<br>
      } else {<br>
       consumeError(AOrErr.takeError());<br>
       error("Mach-O universal file: " + file + " for architecture " +<br>
@@ -765,16 +760,13 @@ static void printFileSectionSizes(String<br>
             I->getAsArchive()) {<br>
     std::unique_ptr<Archive> &UA = *AOrErr;<br>
     // This is an archive. Iterate over each member and display its sizes.<br>
-Â Â Â Â for (object::Archive::child_iterator i = UA->child_begin(),<br>
-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â e = UA->child_end();<br>
-Â Â Â Â Â Â Â i != e; ++i) {<br>
-Â Â Â Â Â if (error(i->getError()))<br>
-Â Â Â Â Â Â exit(1);<br>
-Â Â Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary();<br>
+Â Â Â Â Error Err;<br>
+Â Â Â Â for (auto &C : UA->children(Err)) {<br>
+Â Â Â Â Â Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();<br>
      if (!ChildOrErr) {<br>
       if (auto E = isNotObjectErrorInvalidFileType(<br>
                ChildOrErr.takeError()))<br>
-Â Â Â Â Â Â Â error(std::move(E), UA->getFileName(), i->get(), MoreThanOneArch ?<br>
+Â Â Â Â Â Â Â error(std::move(E), UA->getFileName(), C, MoreThanOneArch ?<br>
           StringRef(I->getArchTypeName()) : StringRef());<br>
       continue;<br>
      }<br>
@@ -798,6 +790,8 @@ static void printFileSectionSizes(String<br>
       }<br>
      }<br>
     }<br>
+Â Â Â Â if (Err)<br>
+Â Â Â Â Â error(std::move(Err), UA->getFileName());<br>
    } else {<br>
     consumeError(AOrErr.takeError());<br>
     error("Mach-O universal file: " + file + " for architecture " +<br>
<br>
Modified: llvm/trunk/tools/sancov/sancov.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/sancov.cc?rev=275316&r1=275315&r2=275316&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/sancov.cc?rev=275316&r1=275315&r2=275316&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/sancov/sancov.cc (original)<br>
+++ llvm/trunk/tools/sancov/sancov.cc Wed Jul 13 16:13:05 2016<br>
@@ -135,10 +135,15 @@ template <typename T> static void FailIf<br>
  FailIfError(E.getError());<br>
 }<br>
<br>
+static void FailIfError(Error Err) {<br>
+Â if (Err) {<br>
+Â Â logAllUnhandledErrors(std::move(Err), errs(), "Error: ");<br>
+Â Â exit(1);<br>
+Â }<br>
+}<br>
+<br>
 template <typename T> static void FailIfError(Expected<T> &E) {<br>
-Â if (E)<br>
-Â Â return;<br>
-Â logAllUnhandledErrors(E.takeError(), errs(), "Error: ");<br>
+Â FailIfError(E.takeError());<br>
 }<br>
<br>
 static void FailIfNotEmpty(const llvm::Twine &E) {<br>
@@ -417,9 +422,8 @@ static void getObjectCoveragePoints(cons<br>
 static void<br>
 visitObjectFiles(const object::Archive &A,<br>
         function_ref<void(const object::ObjectFile &)> Fn) {<br>
-Â for (auto &ErrorOrChild : A.children()) {<br>
-Â Â FailIfError(ErrorOrChild);<br>
-Â Â const object::Archive::Child &C = *ErrorOrChild;<br>
+Â Error Err;<br>
+Â for (auto &C : A.children(Err)) {<br>
   Expected<std::unique_ptr<object::Binary>> ChildOrErr = C.getAsBinary();<br>
   FailIfError(errorToErrorCode(ChildOrErr.takeError()));<br>
   if (auto *O = dyn_cast<object::ObjectFile>(&*ChildOrErr.get()))<br>
@@ -427,6 +431,7 @@ visitObjectFiles(const object::Archive &<br>
   else<br>
    FailIfError(object::object_error::invalid_file_type);<br>
  }<br>
+Â FailIfError(std::move(Err));<br>
 }<br>
<br>
 static void<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>