summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-cxxdump
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2016-07-13 21:13:05 +0000
committerLang Hames <lhames@gmail.com>2016-07-13 21:13:05 +0000
commitc2773e97d248c396636464de9726c04efe47bf03 (patch)
treed06cf695118c691289eabb963bdd2613836388c2 /llvm/tools/llvm-cxxdump
parent02c15da062621032fbb9d72b73ee1996be9205ec (diff)
downloadbcm5719-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-cxxdump')
-rw-r--r--llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp b/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp
index 0c408ccb5ba..c92d20d6ccf 100644
--- a/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp
+++ b/llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp
@@ -50,6 +50,14 @@ static void error(std::error_code EC) {
exit(1);
}
+static void error(Error Err) {
+ if (Err) {
+ logAllUnhandledErrors(std::move(Err), outs(), "Error reading file: ");
+ outs().flush();
+ exit(1);
+ }
+}
+
} // namespace llvm
static void reportError(StringRef Input, StringRef Message) {
@@ -482,9 +490,8 @@ static void dumpCXXData(const ObjectFile *Obj) {
}
static void dumpArchive(const Archive *Arc) {
- for (auto &ErrorOrChild : Arc->children()) {
- error(ErrorOrChild.getError());
- const Archive::Child &ArcC = *ErrorOrChild;
+ Error Err;
+ for (auto &ArcC : Arc->children(Err)) {
Expected<std::unique_ptr<Binary>> ChildOrErr = ArcC.getAsBinary();
if (!ChildOrErr) {
// Ignore non-object files.
@@ -504,6 +511,7 @@ static void dumpArchive(const Archive *Arc) {
else
reportError(Arc->getFileName(), cxxdump_error::unrecognized_file_format);
}
+ error(std::move(Err));
}
static void dumpInput(StringRef File) {
OpenPOWER on IntegriCloud