mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
[llvm-objcopy][NFC] More error propagation (executeObjcopyOnArchive)
Summary: Replace some reportError() calls with error propagation that was missed from rL352625. Note this also adds an error check during Archive iteration that was being hidden by a different error check before: ``` for (const Archive::Child &Child : Ar.children(Err)) { Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary(); if (!ChildOrErr) // This aborts, so Err is never checked reportError(Ar.getFileName(), ChildOrErr.takeError()); ``` Err is being checked after the loop, so during happy runs, everything is fine. But when reportError is changed to return the error instead of aborting, the fact that Err is never checked is now noticed in tests that trigger an error during the loop. Reviewers: jhenderson, dblaikie, alexshap Reviewed By: dblaikie Subscribers: llvm-commits, lhames, jakehehrlich Tags: #llvm Differential Revision: https://reviews.llvm.org/D57462 llvm-svn: 352888
This commit is contained in:
parent
9c7ac47512
commit
9d0b5151fc
@ -96,10 +96,13 @@ static Error deepWriteArchive(StringRef ArcName,
|
||||
ArrayRef<NewArchiveMember> NewMembers,
|
||||
bool WriteSymtab, object::Archive::Kind Kind,
|
||||
bool Deterministic, bool Thin) {
|
||||
Error E =
|
||||
writeArchive(ArcName, NewMembers, WriteSymtab, Kind, Deterministic, Thin);
|
||||
if (!Thin || E)
|
||||
return E;
|
||||
if (Error E = writeArchive(ArcName, NewMembers, WriteSymtab, Kind,
|
||||
Deterministic, Thin))
|
||||
return createFileError(ArcName, std::move(E));
|
||||
|
||||
if (!Thin)
|
||||
return Error::success();
|
||||
|
||||
for (const NewArchiveMember &Member : NewMembers) {
|
||||
// Internally, FileBuffer will use the buffer created by
|
||||
// FileOutputBuffer::create, for regular files (that is the case for
|
||||
@ -149,14 +152,17 @@ static Error executeObjcopyOnArchive(const CopyConfig &Config,
|
||||
std::vector<NewArchiveMember> NewArchiveMembers;
|
||||
Error Err = Error::success();
|
||||
for (const Archive::Child &Child : Ar.children(Err)) {
|
||||
// FIXME: Archive::child_iterator requires that Err be checked *during* loop
|
||||
// iteration, and hence does not allow early returns.
|
||||
cantFail(std::move(Err));
|
||||
Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary();
|
||||
if (!ChildOrErr)
|
||||
reportError(Ar.getFileName(), ChildOrErr.takeError());
|
||||
return createFileError(Ar.getFileName(), ChildOrErr.takeError());
|
||||
Binary *Bin = ChildOrErr->get();
|
||||
|
||||
Expected<StringRef> ChildNameOrErr = Child.getName();
|
||||
if (!ChildNameOrErr)
|
||||
reportError(Ar.getFileName(), ChildNameOrErr.takeError());
|
||||
return createFileError(Ar.getFileName(), ChildNameOrErr.takeError());
|
||||
|
||||
MemBuffer MB(ChildNameOrErr.get());
|
||||
if (Error E = executeObjcopyOnBinary(Config, *Bin, MB))
|
||||
@ -165,19 +171,17 @@ static Error executeObjcopyOnArchive(const CopyConfig &Config,
|
||||
Expected<NewArchiveMember> Member =
|
||||
NewArchiveMember::getOldMember(Child, Config.DeterministicArchives);
|
||||
if (!Member)
|
||||
reportError(Ar.getFileName(), Member.takeError());
|
||||
return createFileError(Ar.getFileName(), Member.takeError());
|
||||
Member->Buf = MB.releaseMemoryBuffer();
|
||||
Member->MemberName = Member->Buf->getBufferIdentifier();
|
||||
NewArchiveMembers.push_back(std::move(*Member));
|
||||
}
|
||||
|
||||
if (Err)
|
||||
reportError(Config.InputFilename, std::move(Err));
|
||||
if (Error E = deepWriteArchive(Config.OutputFilename, NewArchiveMembers,
|
||||
Ar.hasSymbolTable(), Ar.kind(),
|
||||
Config.DeterministicArchives, Ar.isThin()))
|
||||
reportError(Config.OutputFilename, std::move(E));
|
||||
return Error::success();
|
||||
return createFileError(Config.InputFilename, std::move(Err));
|
||||
|
||||
return deepWriteArchive(Config.OutputFilename, NewArchiveMembers,
|
||||
Ar.hasSymbolTable(), Ar.kind(),
|
||||
Config.DeterministicArchives, Ar.isThin());
|
||||
}
|
||||
|
||||
static void restoreDateOnFile(StringRef Filename,
|
||||
|
Loading…
Reference in New Issue
Block a user