[llvm] c51f947 - [NFC][llvm-libtool-darwin] Remove unnecessary conditionals around errors
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 8 10:34:14 PST 2021
Author: Roger Kim
Date: 2021-11-08T10:33:52-08:00
New Revision: c51f947a1351509dd68d8fe5843794ce0201b937
URL: https://github.com/llvm/llvm-project/commit/c51f947a1351509dd68d8fe5843794ce0201b937
DIFF: https://github.com/llvm/llvm-project/commit/c51f947a1351509dd68d8fe5843794ce0201b937.diff
LOG: [NFC][llvm-libtool-darwin] Remove unnecessary conditionals around errors
The existing code has unnecessary logic to indirectly pass
errors through function calls. This diff gets rid of the fluff.
Test Plan: Existing unit tests
Reviewed By: jhenderson, drodriguez, alexander-shaposhnikov
Differential Revision: https://reviews.llvm.org/D113301
Added:
Modified:
llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
index ef4aec58d2e67..77bd042440215 100644
--- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -309,10 +309,7 @@ static Error addChildMember(MembersPerArchitectureMap &Members,
if (Magic == file_magic::bitcode)
return verifyAndAddIRObject(Members, std::move(*NMOrErr), C);
- if (Error E = verifyAndAddMachOObject(Members, std::move(*NMOrErr), C))
- return E;
-
- return Error::success();
+ return verifyAndAddMachOObject(Members, std::move(*NMOrErr), C);
}
static Error processArchive(MembersPerArchitectureMap &Members,
@@ -441,9 +438,7 @@ static Error addMember(MembersPerArchitectureMap &Members,
if (Magic == file_magic::bitcode)
return verifyAndAddIRObject(Members, std::move(*NMOrErr), C);
- if (Error E = verifyAndAddMachOObject(Members, std::move(*NMOrErr), C))
- return E;
- return Error::success();
+ return verifyAndAddMachOObject(Members, std::move(*NMOrErr), C);
}
static Expected<SmallVector<Slice, 2>>
@@ -477,45 +472,41 @@ static Error createStaticLibrary(const Config &C) {
}
if (NewMembers.size() == 1) {
- if (Error E =
- writeArchive(OutputFile, NewMembers.begin()->second,
- /*WriteSymtab=*/true,
- /*Kind=*/object::Archive::K_DARWIN, C.Deterministic,
- /*Thin=*/false))
- return E;
- } else {
- SmallVector<OwningBinary<Archive>, 2> OutputBinaries;
- for (const std::pair<const uint64_t, std::vector<NewArchiveMember>> &M :
- NewMembers) {
- Expected<std::unique_ptr<MemoryBuffer>> OutputBufferOrErr =
- writeArchiveToBuffer(M.second,
- /*WriteSymtab=*/true,
- /*Kind=*/object::Archive::K_DARWIN,
- C.Deterministic,
- /*Thin=*/false);
- if (!OutputBufferOrErr)
- return OutputBufferOrErr.takeError();
- std::unique_ptr<MemoryBuffer> &OutputBuffer = OutputBufferOrErr.get();
-
- Expected<std::unique_ptr<Archive>> ArchiveOrError =
- Archive::create(OutputBuffer->getMemBufferRef());
- if (!ArchiveOrError)
- return ArchiveOrError.takeError();
- std::unique_ptr<Archive> &A = ArchiveOrError.get();
-
- OutputBinaries.push_back(
- OwningBinary<Archive>(std::move(A), std::move(OutputBuffer)));
- }
-
- Expected<SmallVector<Slice, 2>> Slices = buildSlices(OutputBinaries);
- if (!Slices)
- return Slices.takeError();
+ return writeArchive(OutputFile, NewMembers.begin()->second,
+ /*WriteSymtab=*/true,
+ /*Kind=*/object::Archive::K_DARWIN, C.Deterministic,
+ /*Thin=*/false);
+ }
- llvm::stable_sort(*Slices);
- if (Error E = writeUniversalBinary(*Slices, OutputFile))
- return E;
+ SmallVector<OwningBinary<Archive>, 2> OutputBinaries;
+ for (const std::pair<const uint64_t, std::vector<NewArchiveMember>> &M :
+ NewMembers) {
+ Expected<std::unique_ptr<MemoryBuffer>> OutputBufferOrErr =
+ writeArchiveToBuffer(M.second,
+ /*WriteSymtab=*/true,
+ /*Kind=*/object::Archive::K_DARWIN,
+ C.Deterministic,
+ /*Thin=*/false);
+ if (!OutputBufferOrErr)
+ return OutputBufferOrErr.takeError();
+ std::unique_ptr<MemoryBuffer> &OutputBuffer = OutputBufferOrErr.get();
+
+ Expected<std::unique_ptr<Archive>> ArchiveOrError =
+ Archive::create(OutputBuffer->getMemBufferRef());
+ if (!ArchiveOrError)
+ return ArchiveOrError.takeError();
+ std::unique_ptr<Archive> &A = ArchiveOrError.get();
+
+ OutputBinaries.push_back(
+ OwningBinary<Archive>(std::move(A), std::move(OutputBuffer)));
}
- return Error::success();
+
+ Expected<SmallVector<Slice, 2>> Slices = buildSlices(OutputBinaries);
+ if (!Slices)
+ return Slices.takeError();
+
+ llvm::stable_sort(*Slices);
+ return writeUniversalBinary(*Slices, OutputFile);
}
static Expected<Config> parseCommandLine(int Argc, char **Argv) {
More information about the llvm-commits
mailing list