[PATCH] D57462: [llvm-objcopy][NFC] More error propagation (executeObjcopyOnArchive)
Jordan Rupprecht via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 1 09:08:11 PST 2019
This revision was automatically updated to reflect the committed changes.
rupprecht marked an inline comment as done.
Closed by commit rL352888: [llvm-objcopy][NFC] More error propagation (executeObjcopyOnArchive) (authored by rupprecht, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D57462?vs=184743&id=184767#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57462/new/
https://reviews.llvm.org/D57462
Files:
llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
Index: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
===================================================================
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -96,10 +96,13 @@
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 @@
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 @@
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57462.184767.patch
Type: text/x-patch
Size: 3085 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190201/d469f09e/attachment.bin>
More information about the llvm-commits
mailing list