diff options
author | Lang Hames <lhames@gmail.com> | 2016-07-13 21:13:05 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-07-13 21:13:05 +0000 |
commit | c2773e97d248c396636464de9726c04efe47bf03 (patch) | |
tree | d06cf695118c691289eabb963bdd2613836388c2 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 02c15da062621032fbb9d72b73ee1996be9205ec (diff) | |
download | bcm5719-llvm-c2773e97d248c396636464de9726c04efe47bf03.tar.gz bcm5719-llvm-c2773e97d248c396636464de9726c04efe47bf03.zip |
[Object] Change Archive::child_iterator for better interop with Error/Expected.
See http://reviews.llvm.org/D22079
Changes the Archive::child_begin and Archive::children to require a reference
to an Error. If iterator increment fails (because the archive header is
damaged) the iterator will be set to 'end()', and the error stored in the
given Error&. The Error value should be checked by the user immediately after
the loop. E.g.:
Error Err;
for (auto &C : A->children(Err)) {
// Do something with archive child C.
}
// Check the error immediately after the loop.
if (Err)
return Err;
Failure to check the Error will result in an abort() when the Error goes out of
scope (as guaranteed by the Error class).
llvm-svn: 275316
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index bb171ec3fc3..8414239cb50 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1702,10 +1702,8 @@ static void DumpObject(const ObjectFile *o, const Archive *a = nullptr) { /// @brief Dump each object file in \a a; static void DumpArchive(const Archive *a) { - for (auto &ErrorOrChild : a->children()) { - if (std::error_code EC = ErrorOrChild.getError()) - report_error(a->getFileName(), EC); - const Archive::Child &C = *ErrorOrChild; + Error Err; + for (auto &C : a->children(Err)) { Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(); if (!ChildOrErr) { if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) @@ -1717,6 +1715,8 @@ static void DumpArchive(const Archive *a) { else report_error(a->getFileName(), object_error::invalid_file_type); } + if (Err) + report_error(a->getFileName(), std::move(Err)); } /// @brief Open file and figure out how to dump it. |