diff options
Diffstat (limited to 'lld')
| -rw-r--r-- | lld/ELF/Driver.cpp | 3 | ||||
| -rw-r--r-- | lld/ELF/Error.h | 37 | ||||
| -rw-r--r-- | lld/ELF/InputFiles.cpp | 3 | ||||
| -rw-r--r-- | lld/ELF/LTO.cpp | 18 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 3 |
5 files changed, 32 insertions, 32 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index ea1f58fc6d5..630d8d741fa 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -100,7 +100,8 @@ LinkerDriver::getArchiveMembers(MemoryBufferRef MB) { File->getFileName()); V.push_back(MBRef); } - check(std::move(Err)); + if (Err) + Error(Err); // Take ownership of memory buffers created for members of thin archives. for (std::unique_ptr<MemoryBuffer> &MB : File->takeThinBuffers()) diff --git a/lld/ELF/Error.h b/lld/ELF/Error.h index b27af01f07f..552f5049846 100644 --- a/lld/ELF/Error.h +++ b/lld/ELF/Error.h @@ -31,33 +31,28 @@ template <typename T> void error(const ErrorOr<T> &V, const Twine &Prefix) { LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg); LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg, const Twine &Prefix); -void check(std::error_code EC); -void check(Error Err); - -template <class T> T check(ErrorOr<T> EO) { - if (EO) - return std::move(*EO); - fatal(EO.getError().message()); +template <class T> T check(ErrorOr<T> E) { + if (auto EC = E.getError()) + fatal(EC.message()); + return std::move(*E); } -template <class T> T check(Expected<T> EO) { - if (EO) - return std::move(*EO); - check(EO.takeError()); - return T(); +template <class T> T check(Expected<T> E) { + if (!E) + fatal(errorToErrorCode(E.takeError()).message()); + return std::move(*E); } -template <class T> T check(ErrorOr<T> EO, const Twine &Prefix) { - if (EO) - return std::move(*EO); - fatal(EO.getError().message(), Prefix); +template <class T> T check(ErrorOr<T> E, const Twine &Prefix) { + if (auto EC = E.getError()) + fatal(EC.message(), Prefix); + return std::move(*E); } -template <class T> T check(Expected<T> EO, const Twine &Prefix) { - if (EO) - return std::move(*EO); - error(errorToErrorCode(EO.takeError()), Prefix); - return T(); +template <class T> T check(Expected<T> E, const Twine &Prefix) { + if (!E) + fatal(errorToErrorCode(E.takeError()).message(), Prefix); + return std::move(*E); } } // namespace elf diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index de38fc42ef7..a05007ea66d 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -41,7 +41,8 @@ template <class ELFT> static ELFFile<ELFT> createELFObj(MemoryBufferRef MB) { std::error_code EC; ELFFile<ELFT> F(MB.getBuffer(), EC); - check(EC); + if (EC) + error(EC, "failed to read " + MB.getBufferIdentifier()); return F; } diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 33d18c5e8e7..3c2c212b640 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -44,22 +44,24 @@ using namespace lld::elf; // This is for use when debugging LTO. static void saveLtoObjectFile(StringRef Buffer, unsigned I, bool Many) { - SmallString<128> Filename = Config->OutputFile; + SmallString<128> Path = Config->OutputFile; if (Many) - Filename += utostr(I); - Filename += ".lto.o"; + Path += utostr(I); + Path += ".lto.o"; std::error_code EC; - raw_fd_ostream OS(Filename, EC, sys::fs::OpenFlags::F_None); - check(EC); + raw_fd_ostream OS(Path, EC, sys::fs::OpenFlags::F_None); + if (EC) + error(EC, "cannot create " + Path); OS << Buffer; } // This is for use when debugging LTO. static void saveBCFile(Module &M, StringRef Suffix) { + std::string Path = (Config->OutputFile + Suffix).str(); std::error_code EC; - raw_fd_ostream OS(Config->OutputFile.str() + Suffix.str(), EC, - sys::fs::OpenFlags::F_None); - check(EC); + raw_fd_ostream OS(Path, EC, sys::fs::OpenFlags::F_None); + if (EC) + error(EC, "cannot create " + Path); WriteBitcodeToFile(&M, OS, /* ShouldPreserveUseListOrder */ true); } diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 7b9d9402ae8..3ac0191503b 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -261,7 +261,8 @@ template <class ELFT> void Writer<ELFT>::run() { writeBuildId(); if (HasError) return; - check(Buffer->commit()); + if (auto EC = Buffer->commit()) + error(EC, "failed to write to the output file"); } template <class ELFT> |

