COFF: Rename non-noreturn error -> check.

The new name is consistent with ELF.

llvm-svn: 275499
This commit is contained in:
Rui Ueyama 2016-07-14 23:37:10 +00:00
parent fbefee3bff
commit 7e75866c51
8 changed files with 32 additions and 33 deletions

View File

@ -62,7 +62,7 @@ static std::string getOutputPath(StringRef Path) {
// Newly created memory buffers are owned by this driver. // Newly created memory buffers are owned by this driver.
MemoryBufferRef LinkerDriver::openFile(StringRef Path) { MemoryBufferRef LinkerDriver::openFile(StringRef Path) {
auto MBOrErr = MemoryBuffer::getFile(Path); auto MBOrErr = MemoryBuffer::getFile(Path);
error(MBOrErr, Twine("Could not open ") + Path); check(MBOrErr, Twine("Could not open ") + Path);
std::unique_ptr<MemoryBuffer> &MB = *MBOrErr; std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
MemoryBufferRef MBRef = MB->getMemBufferRef(); MemoryBufferRef MBRef = MB->getMemBufferRef();
OwningMBs.push_back(std::move(MB)); // take ownership OwningMBs.push_back(std::move(MB)); // take ownership
@ -683,7 +683,7 @@ void LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
if (auto *Arg = Args.getLastArg(OPT_lldmap)) { if (auto *Arg = Args.getLastArg(OPT_lldmap)) {
std::error_code EC; std::error_code EC;
llvm::raw_fd_ostream Out(Arg->getValue(), EC, OpenFlags::F_Text); 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); Symtab.printMap(Out);
} }
// Call exit to avoid calling destructors. // Call exit to avoid calling destructors.

View File

@ -50,7 +50,7 @@ public:
void run() { void run() {
ErrorOr<std::string> ExeOrErr = llvm::sys::findProgramByName(Prog); ErrorOr<std::string> 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); const char *Exe = Saver.save(*ExeOrErr);
Args.insert(Args.begin(), Exe); Args.insert(Args.begin(), Exe);
Args.push_back(nullptr); Args.push_back(nullptr);
@ -283,11 +283,11 @@ static std::string createDefaultXml() {
// Create a temporary file. // Create a temporary file.
SmallString<128> Path; SmallString<128> Path;
std::error_code EC = sys::fs::createTemporaryFile("tmp", "manifest", 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. // Open the temporary file for writing.
llvm::raw_fd_ostream OS(Path, EC, sys::fs::F_Text); 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 // Emit the XML. Note that we do *not* verify that the XML attributes are
// syntactically correct. This is intentional for link.exe compatibility. // syntactically correct. This is intentional for link.exe compatibility.
@ -318,7 +318,7 @@ static std::string createDefaultXml() {
static std::string readFile(StringRef Path) { static std::string readFile(StringRef Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr = MemoryBuffer::getFile(Path); ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr = MemoryBuffer::getFile(Path);
error(BufOrErr, "Could not open " + Path); check(BufOrErr, "Could not open " + Path);
std::unique_ptr<MemoryBuffer> Buf(std::move(*BufOrErr)); std::unique_ptr<MemoryBuffer> Buf(std::move(*BufOrErr));
return Buf->getBuffer(); return Buf->getBuffer();
} }
@ -333,7 +333,7 @@ static std::string createManifestXml() {
// option, we need to merge them with the default manifest. // option, we need to merge them with the default manifest.
SmallString<128> Path2; SmallString<128> Path2;
std::error_code EC = sys::fs::createTemporaryFile("tmp", "manifest", 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 Remover1(Path1);
FileRemover Remover2(Path2); FileRemover Remover2(Path2);
@ -355,12 +355,12 @@ std::unique_ptr<MemoryBuffer> createManifestRes() {
// Create a temporary file for the resource script file. // Create a temporary file for the resource script file.
SmallString<128> RCPath; SmallString<128> RCPath;
std::error_code EC = sys::fs::createTemporaryFile("tmp", "rc", 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); FileRemover RCRemover(RCPath);
// Open the temporary file for writing. // Open the temporary file for writing.
llvm::raw_fd_ostream Out(RCPath, EC, sys::fs::F_Text); 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. // Write resource script to the RC file.
Out << "#define LANG_ENGLISH 9\n" Out << "#define LANG_ENGLISH 9\n"
@ -376,7 +376,7 @@ std::unique_ptr<MemoryBuffer> createManifestRes() {
// Create output resource file. // Create output resource file.
SmallString<128> ResPath; SmallString<128> ResPath;
EC = sys::fs::createTemporaryFile("tmp", "res", 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"); Executor E("rc.exe");
E.add("/fo"); E.add("/fo");
@ -385,7 +385,7 @@ std::unique_ptr<MemoryBuffer> createManifestRes() {
E.add(RCPath.str()); E.add(RCPath.str());
E.run(); E.run();
ErrorOr<std::unique_ptr<MemoryBuffer>> Ret = MemoryBuffer::getFile(ResPath); ErrorOr<std::unique_ptr<MemoryBuffer>> Ret = MemoryBuffer::getFile(ResPath);
error(Ret, Twine("Could not open ") + ResPath); check(Ret, Twine("Could not open ") + ResPath);
return std::move(*Ret); return std::move(*Ret);
} }
@ -395,7 +395,7 @@ void createSideBySideManifest() {
Path = (Twine(Config->OutputFile) + ".manifest").str(); Path = (Twine(Config->OutputFile) + ".manifest").str();
std::error_code EC; std::error_code EC;
llvm::raw_fd_ostream Out(Path, EC, llvm::sys::fs::F_Text); 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(); Out << createManifestXml();
} }
@ -565,7 +565,7 @@ convertResToCOFF(const std::vector<MemoryBufferRef> &MBs) {
E.add(MB.getBufferIdentifier()); E.add(MB.getBufferIdentifier());
E.run(); E.run();
ErrorOr<std::unique_ptr<MemoryBuffer>> Ret = MemoryBuffer::getFile(Path); ErrorOr<std::unique_ptr<MemoryBuffer>> Ret = MemoryBuffer::getFile(Path);
error(Ret, Twine("Could not open ") + Path); check(Ret, Twine("Could not open ") + Path);
return std::move(*Ret); return std::move(*Ret);
} }

View File

@ -20,13 +20,13 @@ void error(const Twine &Msg) {
exit(1); exit(1);
} }
void error(std::error_code EC, const Twine &Prefix) { void check(std::error_code EC, const Twine &Prefix) {
if (!EC) if (!EC)
return; return;
error(Prefix + ": " + EC.message()); error(Prefix + ": " + EC.message());
} }
void error(llvm::Error E, const Twine &Prefix) { void check(llvm::Error E, const Twine &Prefix) {
if (!E) if (!E)
return; return;
handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EIB) { handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EIB) {

View File

@ -17,11 +17,11 @@ namespace lld {
namespace coff { namespace coff {
LLVM_ATTRIBUTE_NORETURN void error(const Twine &Msg); LLVM_ATTRIBUTE_NORETURN void error(const Twine &Msg);
void error(std::error_code EC, const Twine &Prefix); void check(std::error_code EC, const Twine &Prefix);
void error(llvm::Error E, const Twine &Prefix); void check(llvm::Error E, const Twine &Prefix);
template <typename T> void error(const ErrorOr<T> &V, const Twine &Prefix) { template <typename T> void check(const ErrorOr<T> &V, const Twine &Prefix) {
error(V.getError(), Prefix); check(V.getError(), Prefix);
} }
template <class T> T check(Expected<T> E, const Twine &Prefix) { template <class T> T check(Expected<T> E, const Twine &Prefix) {

View File

@ -64,7 +64,7 @@ std::string InputFile::getShortName() {
void ArchiveFile::parse() { void ArchiveFile::parse() {
// Parse a MemoryBufferRef as an archive file. // Parse a MemoryBufferRef as an archive file.
auto ArchiveOrErr = Archive::create(MB); auto ArchiveOrErr = Archive::create(MB);
error(errorToErrorCode(ArchiveOrErr.takeError()), check(errorToErrorCode(ArchiveOrErr.takeError()),
"Failed to parse static library"); "Failed to parse static library");
File = std::move(*ArchiveOrErr); File = std::move(*ArchiveOrErr);
@ -82,21 +82,21 @@ void ArchiveFile::parse() {
Error Err; Error Err;
for (auto &Child : File->children(Err)) for (auto &Child : File->children(Err))
Seen[Child.getChildOffset()].clear(); 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. // Returns a buffer pointing to a member file containing a given symbol.
// This function is thread-safe. // This function is thread-safe.
MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) { MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) {
auto COrErr = Sym->getMember(); 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; const Archive::Child &C = *COrErr;
// Return an empty buffer if we have already returned the same buffer. // Return an empty buffer if we have already returned the same buffer.
if (Seen[C.getChildOffset()].test_and_set()) if (Seen[C.getChildOffset()].test_and_set())
return MemoryBufferRef(); return MemoryBufferRef();
ErrorOr<MemoryBufferRef> Ret = C.getMemoryBufferRef(); ErrorOr<MemoryBufferRef> 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()); Sym->getName());
return *Ret; return *Ret;
} }
@ -105,7 +105,7 @@ void ObjectFile::parse() {
// Parse a memory buffer as a COFF file. // Parse a memory buffer as a COFF file.
auto BinOrErr = createBinary(MB); auto BinOrErr = createBinary(MB);
if (!BinOrErr) if (!BinOrErr)
error(errorToErrorCode(BinOrErr.takeError()), check(errorToErrorCode(BinOrErr.takeError()),
"Failed to parse object file"); "Failed to parse object file");
std::unique_ptr<Binary> Bin = std::move(*BinOrErr); std::unique_ptr<Binary> Bin = std::move(*BinOrErr);
@ -130,9 +130,9 @@ void ObjectFile::initializeChunks() {
const coff_section *Sec; const coff_section *Sec;
StringRef Name; StringRef Name;
std::error_code EC = COFFObj->getSection(I, Sec); 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); EC = COFFObj->getSectionName(Sec, Name);
error(EC, Twine("getSectionName failed: #") + Twine(I)); check(EC, Twine("getSectionName failed: #") + Twine(I));
if (Name == ".sxdata") { if (Name == ".sxdata") {
SXData = Sec; SXData = Sec;
continue; continue;
@ -167,7 +167,7 @@ void ObjectFile::initializeSymbols() {
for (uint32_t I = 0; I < NumSymbols; ++I) { for (uint32_t I = 0; I < NumSymbols; ++I) {
// Get a COFFSymbolRef object. // Get a COFFSymbolRef object.
auto SymOrErr = COFFObj->getSymbol(I); auto SymOrErr = COFFObj->getSymbol(I);
error(SymOrErr, Twine("broken object file: ") + getName()); check(SymOrErr, Twine("broken object file: ") + getName());
COFFSymbolRef Sym = *SymOrErr; COFFSymbolRef Sym = *SymOrErr;
@ -334,7 +334,7 @@ void BitcodeFile::parse() {
Context.enableDebugTypeODRUniquing(); Context.enableDebugTypeODRUniquing();
ErrorOr<std::unique_ptr<LTOModule>> ModOrErr = LTOModule::createFromBuffer( ErrorOr<std::unique_ptr<LTOModule>> ModOrErr = LTOModule::createFromBuffer(
Context, MB.getBufferStart(), MB.getBufferSize(), llvm::TargetOptions()); 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); M = std::move(*ModOrErr);
llvm::StringSaver Saver(Alloc); llvm::StringSaver Saver(Alloc);

View File

@ -484,6 +484,5 @@ void lld::coff::writeImportLibrary() {
std::pair<StringRef, std::error_code> Result = std::pair<StringRef, std::error_code> Result =
writeArchive(Path, Members, /*WriteSymtab*/ true, object::Archive::K_GNU, writeArchive(Path, Members, /*WriteSymtab*/ true, object::Archive::K_GNU,
/*Deterministic*/ true, /*Thin*/ false); /*Deterministic*/ true, /*Thin*/ false);
error(Result.second, Twine("Failed to write ") + Path); check(Result.second, Twine("Failed to write ") + Path);
} }

View File

@ -38,7 +38,7 @@ void lld::coff::createPDB(StringRef Path) {
size_t FileSize = PageSize * 3; size_t FileSize = PageSize * 3;
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr = ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(Path, FileSize); FileOutputBuffer::create(Path, FileSize);
error(BufferOrErr, Twine("failed to open ") + Path); check(BufferOrErr, Twine("failed to open ") + Path);
std::unique_ptr<FileOutputBuffer> Buffer = std::move(*BufferOrErr); std::unique_ptr<FileOutputBuffer> Buffer = std::move(*BufferOrErr);
// Write the file header. // Write the file header.

View File

@ -239,7 +239,7 @@ void Writer::run() {
fixSafeSEHSymbols(); fixSafeSEHSymbols();
writeSections(); writeSections();
sortExceptionTable(); sortExceptionTable();
error(Buffer->commit(), "Failed to write the output file"); check(Buffer->commit(), "Failed to write the output file");
} }
static StringRef getOutputSection(StringRef Name) { static StringRef getOutputSection(StringRef Name) {
@ -653,7 +653,7 @@ template <typename PEHeaderTy> void Writer::writeHeader() {
void Writer::openFile(StringRef Path) { void Writer::openFile(StringRef Path) {
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr = ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(Path, FileSize, FileOutputBuffer::F_executable); 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); Buffer = std::move(*BufferOrErr);
} }