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-size/llvm-size.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-size/llvm-size.cpp')
| -rw-r--r-- | llvm/tools/llvm-size/llvm-size.cpp | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp index ecc0a0eac3c..c5966ead4b6 100644 --- a/llvm/tools/llvm-size/llvm-size.cpp +++ b/llvm/tools/llvm-size/llvm-size.cpp @@ -527,15 +527,12 @@ static void printFileSectionSizes(StringRef file) { if (Archive *a = dyn_cast<Archive>(&Bin)) { // This is an archive. Iterate over each member and display its sizes. - for (object::Archive::child_iterator i = a->child_begin(), - e = a->child_end(); - i != e; ++i) { - if (error(i->getError())) - exit(1); - Expected<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary(); + Error Err; + for (auto &C : a->children(Err)) { + Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(); if (!ChildOrErr) { if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) - error(std::move(E), a->getFileName(), i->get()); + error(std::move(E), a->getFileName(), C); continue; } if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) { @@ -555,6 +552,8 @@ static void printFileSectionSizes(StringRef file) { } } } + if (Err) + error(std::move(Err), a->getFileName()); } else if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Bin)) { // If we have a list of architecture flags specified dump only those. @@ -597,17 +596,13 @@ static void printFileSectionSizes(StringRef file) { std::unique_ptr<Archive> &UA = *AOrErr; // This is an archive. Iterate over each member and display its // sizes. - for (object::Archive::child_iterator i = UA->child_begin(), - e = UA->child_end(); - i != e; ++i) { - if (error(i->getError())) - exit(1); - Expected<std::unique_ptr<Binary>> ChildOrErr = - i->get().getAsBinary(); + Error Err; + for (auto &C : UA->children(Err)) { + Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(); if (!ChildOrErr) { if (auto E = isNotObjectErrorInvalidFileType( ChildOrErr.takeError())) - error(std::move(E), UA->getFileName(), i->get(), + error(std::move(E), UA->getFileName(), C, ArchFlags.size() > 1 ? StringRef(I->getArchTypeName()) : StringRef()); continue; @@ -637,6 +632,8 @@ static void printFileSectionSizes(StringRef file) { } } } + if (Err) + error(std::move(Err), UA->getFileName()); } else { consumeError(AOrErr.takeError()); error("Mach-O universal file: " + file + " for architecture " + @@ -688,17 +685,13 @@ static void printFileSectionSizes(StringRef file) { std::unique_ptr<Archive> &UA = *AOrErr; // This is an archive. Iterate over each member and display its // sizes. - for (object::Archive::child_iterator i = UA->child_begin(), - e = UA->child_end(); - i != e; ++i) { - if (error(i->getError())) - exit(1); - Expected<std::unique_ptr<Binary>> ChildOrErr = - i->get().getAsBinary(); + Error Err; + for (auto &C : UA->children(Err)) { + Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(); if (!ChildOrErr) { if (auto E = isNotObjectErrorInvalidFileType( ChildOrErr.takeError())) - error(std::move(E), UA->getFileName(), i->get()); + error(std::move(E), UA->getFileName(), C); continue; } if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) { @@ -721,6 +714,8 @@ static void printFileSectionSizes(StringRef file) { } } } + if (Err) + error(std::move(Err), UA->getFileName()); } else { consumeError(AOrErr.takeError()); error("Mach-O universal file: " + file + " for architecture " + @@ -765,16 +760,13 @@ static void printFileSectionSizes(StringRef file) { I->getAsArchive()) { std::unique_ptr<Archive> &UA = *AOrErr; // This is an archive. Iterate over each member and display its sizes. - for (object::Archive::child_iterator i = UA->child_begin(), - e = UA->child_end(); - i != e; ++i) { - if (error(i->getError())) - exit(1); - Expected<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary(); + Error Err; + for (auto &C : UA->children(Err)) { + Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(); if (!ChildOrErr) { if (auto E = isNotObjectErrorInvalidFileType( ChildOrErr.takeError())) - error(std::move(E), UA->getFileName(), i->get(), MoreThanOneArch ? + error(std::move(E), UA->getFileName(), C, MoreThanOneArch ? StringRef(I->getArchTypeName()) : StringRef()); continue; } @@ -798,6 +790,8 @@ static void printFileSectionSizes(StringRef file) { } } } + if (Err) + error(std::move(Err), UA->getFileName()); } else { consumeError(AOrErr.takeError()); error("Mach-O universal file: " + file + " for architecture " + |

