diff options
author | Lang Hames <lhames@gmail.com> | 2016-07-14 02:24:01 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-07-14 02:24:01 +0000 |
commit | fc209623e976118cf016c0d3c1dccacb6bfa27c1 (patch) | |
tree | 407a60990972f87acb6c6aed9c218ac6ab4b203a /llvm/lib/Object/Archive.cpp | |
parent | af7e8465e1fabdfff6c3a08a14cdb83ed79a10dc (diff) | |
download | bcm5719-llvm-fc209623e976118cf016c0d3c1dccacb6bfa27c1.tar.gz bcm5719-llvm-fc209623e976118cf016c0d3c1dccacb6bfa27c1.zip |
[Object] Re-apply r275316 now that I have the corresponding LLD patch ready.
llvm-svn: 275361
Diffstat (limited to 'llvm/lib/Object/Archive.cpp')
-rw-r--r-- | llvm/lib/Object/Archive.cpp | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp index 4720bf894e9..4827e58f5d3 100644 --- a/llvm/lib/Object/Archive.cpp +++ b/llvm/lib/Object/Archive.cpp @@ -298,12 +298,9 @@ Archive::Archive(MemoryBufferRef Source, Error &Err) } // Get the special members. - child_iterator I = child_begin(false); - std::error_code ec; - if ((ec = I->getError())) { - Err = errorCodeToError(ec); + child_iterator I = child_begin(Err, false); + if (Err) return; - } child_iterator E = child_end(); // This is at least a valid empty archive. Since an empty archive is the @@ -315,13 +312,13 @@ Archive::Archive(MemoryBufferRef Source, Error &Err) Err = Error::success(); return; } - const Child *C = &**I; + const Child *C = &*I; auto Increment = [&]() { ++I; - if ((Err = errorCodeToError(I->getError()))) + if (Err) return true; - C = &**I; + C = &*I; return false; }; @@ -366,8 +363,7 @@ Archive::Archive(MemoryBufferRef Source, Error &Err) Format = K_BSD; // We know this is BSD, so getName will work since there is no string table. ErrorOr<StringRef> NameOrErr = C->getName(); - ec = NameOrErr.getError(); - if (ec) { + if (auto ec = NameOrErr.getError()) { Err = errorCodeToError(ec); return; } @@ -465,23 +461,29 @@ Archive::Archive(MemoryBufferRef Source, Error &Err) Err = Error::success(); } -Archive::child_iterator Archive::child_begin(bool SkipInternal) const { +Archive::child_iterator Archive::child_begin(Error &Err, + bool SkipInternal) const { if (Data.getBufferSize() == 8) // empty archive. return child_end(); if (SkipInternal) - return Child(this, FirstRegularData, FirstRegularStartOfFile); + return child_iterator(Child(this, FirstRegularData, + FirstRegularStartOfFile), + &Err); const char *Loc = Data.getBufferStart() + strlen(Magic); std::error_code EC; - Child c(this, Loc, &EC); - if (EC) - return child_iterator(EC); - return child_iterator(c); + Child C(this, Loc, &EC); + if (EC) { + ErrorAsOutParameter ErrAsOutParam(Err); + Err = errorCodeToError(EC); + return child_end(); + } + return child_iterator(C, &Err); } Archive::child_iterator Archive::child_end() const { - return Child(this, nullptr, nullptr); + return child_iterator(Child(this, nullptr, nullptr), nullptr); } StringRef Archive::Symbol::getName() const { @@ -665,18 +667,20 @@ uint32_t Archive::getNumberOfSymbols() const { return read32le(buf); } -Archive::child_iterator Archive::findSym(StringRef name) const { +Archive::child_iterator Archive::findSym(Error &Err, StringRef name) const { Archive::symbol_iterator bs = symbol_begin(); Archive::symbol_iterator es = symbol_end(); for (; bs != es; ++bs) { StringRef SymName = bs->getName(); if (SymName == name) { - ErrorOr<Archive::child_iterator> ResultOrErr = bs->getMember(); - // FIXME: Should we really eat the error? - if (ResultOrErr.getError()) + if (auto MemberOrErr = bs->getMember()) { + return child_iterator(*MemberOrErr, &Err); + } else { + ErrorAsOutParameter ErrAsOutParam(Err); + Err = errorCodeToError(MemberOrErr.getError()); return child_end(); - return ResultOrErr.get(); + } } } return child_end(); |