<div dir="ltr">Thanks. </div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 13, 2016 at 5:27 PM Lang Hames <<a href="mailto:lhames@gmail.com">lhames@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Vitaly,<div><br></div><div>Sorry about that - I'll take a look now and fix or revert as necessary.</div><div><br></div><div>Cheers,</div><div>Lang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 13, 2016 at 5:06 PM, Vitaly Buka <span dir="ltr"><<a href="mailto:vitalybuka@google.com" target="_blank">vitalybuka@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank">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><div class="m_-1373090458951156671HOEnZb"><div class="m_-1373090458951156671h5"><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" target="_blank">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>
</div></div></blockquote></div><br></div>
</blockquote></div>