ELF: Make check() always return a value.

This patch corresponds to r275511 for COFF.

llvm-svn: 275521
This commit is contained in:
Rui Ueyama 2016-07-15 02:01:03 +00:00
parent b95dc4608d
commit f8292e9ac9
5 changed files with 32 additions and 32 deletions

View File

@ -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())

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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>