<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>