From 7e75866c51d700981c6b4a98a66ffcad02b8ffe6 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 14 Jul 2016 23:37:10 +0000 Subject: [PATCH] COFF: Rename non-noreturn error -> check. The new name is consistent with ELF. llvm-svn: 275499 --- lld/COFF/Driver.cpp | 4 ++-- lld/COFF/DriverUtils.cpp | 22 +++++++++++----------- lld/COFF/Error.cpp | 4 ++-- lld/COFF/Error.h | 8 ++++---- lld/COFF/InputFiles.cpp | 18 +++++++++--------- lld/COFF/Librarian.cpp | 3 +-- lld/COFF/PDB.cpp | 2 +- lld/COFF/Writer.cpp | 4 ++-- 8 files changed, 32 insertions(+), 33 deletions(-) diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index dd6de03..a93abcf 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -62,7 +62,7 @@ static std::string getOutputPath(StringRef Path) { // Newly created memory buffers are owned by this driver. MemoryBufferRef LinkerDriver::openFile(StringRef Path) { auto MBOrErr = MemoryBuffer::getFile(Path); - error(MBOrErr, Twine("Could not open ") + Path); + check(MBOrErr, Twine("Could not open ") + Path); std::unique_ptr &MB = *MBOrErr; MemoryBufferRef MBRef = MB->getMemBufferRef(); OwningMBs.push_back(std::move(MB)); // take ownership @@ -683,7 +683,7 @@ void LinkerDriver::link(llvm::ArrayRef ArgsArr) { if (auto *Arg = Args.getLastArg(OPT_lldmap)) { std::error_code EC; llvm::raw_fd_ostream Out(Arg->getValue(), EC, OpenFlags::F_Text); - error(EC, "Could not create the symbol map"); + check(EC, "Could not create the symbol map"); Symtab.printMap(Out); } // Call exit to avoid calling destructors. diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index f3a7881..acfc027 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -50,7 +50,7 @@ public: void run() { ErrorOr ExeOrErr = llvm::sys::findProgramByName(Prog); - error(ExeOrErr, Twine("unable to find ") + Prog + " in PATH: "); + check(ExeOrErr, Twine("unable to find ") + Prog + " in PATH: "); const char *Exe = Saver.save(*ExeOrErr); Args.insert(Args.begin(), Exe); Args.push_back(nullptr); @@ -283,11 +283,11 @@ static std::string createDefaultXml() { // Create a temporary file. SmallString<128> Path; std::error_code EC = sys::fs::createTemporaryFile("tmp", "manifest", Path); - error(EC, "cannot create a temporary file"); + check(EC, "cannot create a temporary file"); // Open the temporary file for writing. llvm::raw_fd_ostream OS(Path, EC, sys::fs::F_Text); - error(EC, Twine("failed to open ") + Path); + check(EC, Twine("failed to open ") + Path); // Emit the XML. Note that we do *not* verify that the XML attributes are // syntactically correct. This is intentional for link.exe compatibility. @@ -318,7 +318,7 @@ static std::string createDefaultXml() { static std::string readFile(StringRef Path) { ErrorOr> BufOrErr = MemoryBuffer::getFile(Path); - error(BufOrErr, "Could not open " + Path); + check(BufOrErr, "Could not open " + Path); std::unique_ptr Buf(std::move(*BufOrErr)); return Buf->getBuffer(); } @@ -333,7 +333,7 @@ static std::string createManifestXml() { // option, we need to merge them with the default manifest. SmallString<128> Path2; std::error_code EC = sys::fs::createTemporaryFile("tmp", "manifest", Path2); - error(EC, "cannot create a temporary file"); + check(EC, "cannot create a temporary file"); FileRemover Remover1(Path1); FileRemover Remover2(Path2); @@ -355,12 +355,12 @@ std::unique_ptr createManifestRes() { // Create a temporary file for the resource script file. SmallString<128> RCPath; std::error_code EC = sys::fs::createTemporaryFile("tmp", "rc", RCPath); - error(EC, "cannot create a temporary file"); + check(EC, "cannot create a temporary file"); FileRemover RCRemover(RCPath); // Open the temporary file for writing. llvm::raw_fd_ostream Out(RCPath, EC, sys::fs::F_Text); - error(EC, Twine("failed to open ") + RCPath); + check(EC, Twine("failed to open ") + RCPath); // Write resource script to the RC file. Out << "#define LANG_ENGLISH 9\n" @@ -376,7 +376,7 @@ std::unique_ptr createManifestRes() { // Create output resource file. SmallString<128> ResPath; EC = sys::fs::createTemporaryFile("tmp", "res", ResPath); - error(EC, "cannot create a temporary file"); + check(EC, "cannot create a temporary file"); Executor E("rc.exe"); E.add("/fo"); @@ -385,7 +385,7 @@ std::unique_ptr createManifestRes() { E.add(RCPath.str()); E.run(); ErrorOr> Ret = MemoryBuffer::getFile(ResPath); - error(Ret, Twine("Could not open ") + ResPath); + check(Ret, Twine("Could not open ") + ResPath); return std::move(*Ret); } @@ -395,7 +395,7 @@ void createSideBySideManifest() { Path = (Twine(Config->OutputFile) + ".manifest").str(); std::error_code EC; llvm::raw_fd_ostream Out(Path, EC, llvm::sys::fs::F_Text); - error(EC, "failed to create manifest"); + check(EC, "failed to create manifest"); Out << createManifestXml(); } @@ -565,7 +565,7 @@ convertResToCOFF(const std::vector &MBs) { E.add(MB.getBufferIdentifier()); E.run(); ErrorOr> Ret = MemoryBuffer::getFile(Path); - error(Ret, Twine("Could not open ") + Path); + check(Ret, Twine("Could not open ") + Path); return std::move(*Ret); } diff --git a/lld/COFF/Error.cpp b/lld/COFF/Error.cpp index b5ec9a7..c5b0987 100644 --- a/lld/COFF/Error.cpp +++ b/lld/COFF/Error.cpp @@ -20,13 +20,13 @@ void error(const Twine &Msg) { exit(1); } -void error(std::error_code EC, const Twine &Prefix) { +void check(std::error_code EC, const Twine &Prefix) { if (!EC) return; error(Prefix + ": " + EC.message()); } -void error(llvm::Error E, const Twine &Prefix) { +void check(llvm::Error E, const Twine &Prefix) { if (!E) return; handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EIB) { diff --git a/lld/COFF/Error.h b/lld/COFF/Error.h index e0eb17a..d2aa0c3 100644 --- a/lld/COFF/Error.h +++ b/lld/COFF/Error.h @@ -17,11 +17,11 @@ namespace lld { namespace coff { LLVM_ATTRIBUTE_NORETURN void error(const Twine &Msg); -void error(std::error_code EC, const Twine &Prefix); -void error(llvm::Error E, const Twine &Prefix); +void check(std::error_code EC, const Twine &Prefix); +void check(llvm::Error E, const Twine &Prefix); -template void error(const ErrorOr &V, const Twine &Prefix) { - error(V.getError(), Prefix); +template void check(const ErrorOr &V, const Twine &Prefix) { + check(V.getError(), Prefix); } template T check(Expected E, const Twine &Prefix) { diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index 2ca8fb2a..eda1877 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -64,7 +64,7 @@ std::string InputFile::getShortName() { void ArchiveFile::parse() { // Parse a MemoryBufferRef as an archive file. auto ArchiveOrErr = Archive::create(MB); - error(errorToErrorCode(ArchiveOrErr.takeError()), + check(errorToErrorCode(ArchiveOrErr.takeError()), "Failed to parse static library"); File = std::move(*ArchiveOrErr); @@ -82,21 +82,21 @@ void ArchiveFile::parse() { Error Err; for (auto &Child : File->children(Err)) Seen[Child.getChildOffset()].clear(); - error(std::move(Err), "Failed to parse static library"); + check(std::move(Err), "Failed to parse static library"); } // Returns a buffer pointing to a member file containing a given symbol. // This function is thread-safe. MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) { auto COrErr = Sym->getMember(); - error(COrErr, Twine("Could not get the member for symbol ") + Sym->getName()); + check(COrErr, Twine("Could not get the member for symbol ") + Sym->getName()); const Archive::Child &C = *COrErr; // Return an empty buffer if we have already returned the same buffer. if (Seen[C.getChildOffset()].test_and_set()) return MemoryBufferRef(); ErrorOr Ret = C.getMemoryBufferRef(); - error(Ret, Twine("Could not get the buffer for the member defining symbol ") + + check(Ret, Twine("Could not get the buffer for the member defining symbol ") + Sym->getName()); return *Ret; } @@ -105,7 +105,7 @@ void ObjectFile::parse() { // Parse a memory buffer as a COFF file. auto BinOrErr = createBinary(MB); if (!BinOrErr) - error(errorToErrorCode(BinOrErr.takeError()), + check(errorToErrorCode(BinOrErr.takeError()), "Failed to parse object file"); std::unique_ptr Bin = std::move(*BinOrErr); @@ -130,9 +130,9 @@ void ObjectFile::initializeChunks() { const coff_section *Sec; StringRef Name; std::error_code EC = COFFObj->getSection(I, Sec); - error(EC, Twine("getSection failed: #") + Twine(I)); + check(EC, Twine("getSection failed: #") + Twine(I)); EC = COFFObj->getSectionName(Sec, Name); - error(EC, Twine("getSectionName failed: #") + Twine(I)); + check(EC, Twine("getSectionName failed: #") + Twine(I)); if (Name == ".sxdata") { SXData = Sec; continue; @@ -167,7 +167,7 @@ void ObjectFile::initializeSymbols() { for (uint32_t I = 0; I < NumSymbols; ++I) { // Get a COFFSymbolRef object. auto SymOrErr = COFFObj->getSymbol(I); - error(SymOrErr, Twine("broken object file: ") + getName()); + check(SymOrErr, Twine("broken object file: ") + getName()); COFFSymbolRef Sym = *SymOrErr; @@ -334,7 +334,7 @@ void BitcodeFile::parse() { Context.enableDebugTypeODRUniquing(); ErrorOr> ModOrErr = LTOModule::createFromBuffer( Context, MB.getBufferStart(), MB.getBufferSize(), llvm::TargetOptions()); - error(ModOrErr, "Could not create lto module"); + check(ModOrErr, "Could not create lto module"); M = std::move(*ModOrErr); llvm::StringSaver Saver(Alloc); diff --git a/lld/COFF/Librarian.cpp b/lld/COFF/Librarian.cpp index 02e9330..98e16c9 100644 --- a/lld/COFF/Librarian.cpp +++ b/lld/COFF/Librarian.cpp @@ -484,6 +484,5 @@ void lld::coff::writeImportLibrary() { std::pair Result = writeArchive(Path, Members, /*WriteSymtab*/ true, object::Archive::K_GNU, /*Deterministic*/ true, /*Thin*/ false); - error(Result.second, Twine("Failed to write ") + Path); + check(Result.second, Twine("Failed to write ") + Path); } - diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp index 786d287..7c60567 100644 --- a/lld/COFF/PDB.cpp +++ b/lld/COFF/PDB.cpp @@ -38,7 +38,7 @@ void lld::coff::createPDB(StringRef Path) { size_t FileSize = PageSize * 3; ErrorOr> BufferOrErr = FileOutputBuffer::create(Path, FileSize); - error(BufferOrErr, Twine("failed to open ") + Path); + check(BufferOrErr, Twine("failed to open ") + Path); std::unique_ptr Buffer = std::move(*BufferOrErr); // Write the file header. diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index fff8f07..56b1924 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -239,7 +239,7 @@ void Writer::run() { fixSafeSEHSymbols(); writeSections(); sortExceptionTable(); - error(Buffer->commit(), "Failed to write the output file"); + check(Buffer->commit(), "Failed to write the output file"); } static StringRef getOutputSection(StringRef Name) { @@ -653,7 +653,7 @@ template void Writer::writeHeader() { void Writer::openFile(StringRef Path) { ErrorOr> BufferOrErr = FileOutputBuffer::create(Path, FileSize, FileOutputBuffer::F_executable); - error(BufferOrErr, Twine("failed to open ") + Path); + check(BufferOrErr, Twine("failed to open ") + Path); Buffer = std::move(*BufferOrErr); } -- 2.7.4