COFF: Rename non-noreturn error -> check.
The new name is consistent with ELF. llvm-svn: 275499
This commit is contained in:
parent
fbefee3bff
commit
7e75866c51
|
@ -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<MemoryBuffer> &MB = *MBOrErr;
|
||||
MemoryBufferRef MBRef = MB->getMemBufferRef();
|
||||
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)) {
|
||||
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.
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
void run() {
|
||||
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);
|
||||
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<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));
|
||||
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<MemoryBuffer> 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<MemoryBuffer> 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<MemoryBuffer> createManifestRes() {
|
|||
E.add(RCPath.str());
|
||||
E.run();
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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<MemoryBufferRef> &MBs) {
|
|||
E.add(MB.getBufferIdentifier());
|
||||
E.run();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 <typename T> void error(const ErrorOr<T> &V, const Twine &Prefix) {
|
||||
error(V.getError(), Prefix);
|
||||
template <typename T> void check(const ErrorOr<T> &V, const Twine &Prefix) {
|
||||
check(V.getError(), Prefix);
|
||||
}
|
||||
|
||||
template <class T> T check(Expected<T> E, const Twine &Prefix) {
|
||||
|
|
|
@ -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<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());
|
||||
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<Binary> 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<std::unique_ptr<LTOModule>> 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);
|
||||
|
|
|
@ -484,6 +484,5 @@ void lld::coff::writeImportLibrary() {
|
|||
std::pair<StringRef, std::error_code> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ void lld::coff::createPDB(StringRef Path) {
|
|||
size_t FileSize = PageSize * 3;
|
||||
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
|
||||
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);
|
||||
|
||||
// Write the file header.
|
||||
|
|
|
@ -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 <typename PEHeaderTy> void Writer::writeHeader() {
|
|||
void Writer::openFile(StringRef Path) {
|
||||
ErrorOr<std::unique_ptr<FileOutputBuffer>> 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue