From 75714f618c3997acce830434f85df768ea009bc6 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 3 Mar 2016 22:24:39 +0000 Subject: [PATCH] Rename 'fatal' to 'check' when it doesn't always fail. llvm-svn: 262666 --- lld/ELF/Driver.cpp | 6 +++--- lld/ELF/Error.cpp | 2 +- lld/ELF/Error.h | 6 +++--- lld/ELF/InputFiles.cpp | 32 ++++++++++++++++---------------- lld/ELF/InputSection.cpp | 4 ++-- lld/ELF/SymbolTable.cpp | 2 +- lld/ELF/Writer.cpp | 4 ++-- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index a84c95e..e476d5d 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -71,14 +71,14 @@ static std::pair parseEmulation(StringRef S) { // Each slice consists of a member file in the archive. static std::vector getArchiveMembers(MemoryBufferRef MB) { std::unique_ptr File = - fatal(Archive::create(MB), "Failed to parse archive"); + check(Archive::create(MB), "Failed to parse archive"); std::vector V; for (const ErrorOr &COrErr : File->children()) { - Archive::Child C = fatal(COrErr, "Could not get the child of the archive " + + Archive::Child C = check(COrErr, "Could not get the child of the archive " + File->getFileName()); MemoryBufferRef Mb = - fatal(C.getMemoryBufferRef(), + check(C.getMemoryBufferRef(), "Could not get the buffer for a child of the archive " + File->getFileName()); V.push_back(Mb); diff --git a/lld/ELF/Error.cpp b/lld/ELF/Error.cpp index 2835f56..9e42910 100644 --- a/lld/ELF/Error.cpp +++ b/lld/ELF/Error.cpp @@ -54,7 +54,7 @@ void fatal(const Twine &Msg, const Twine &Prefix) { fatal(Prefix + ": " + Msg); } -void fatal(std::error_code EC) { +void check(std::error_code EC) { if (EC) fatal(EC.message()); } diff --git a/lld/ELF/Error.h b/lld/ELF/Error.h index 6fadfbd..cf3bd89 100644 --- a/lld/ELF/Error.h +++ b/lld/ELF/Error.h @@ -35,15 +35,15 @@ template bool error(const ErrorOr &V) { LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg); LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg, const Twine &Prefix); -void fatal(std::error_code EC); +void check(std::error_code EC); -template T fatal(ErrorOr EO) { +template T check(ErrorOr EO) { if (EO) return std::move(*EO); fatal(EO.getError().message()); } -template T fatal(ErrorOr EO, const Twine &Prefix) { +template T check(ErrorOr EO, const Twine &Prefix) { if (EO) return std::move(*EO); fatal(EO.getError().message(), Prefix); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index bfe35856..b4696b8 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -29,7 +29,7 @@ template static ELFFile createELFObj(MemoryBufferRef MB) { std::error_code EC; ELFFile F(MB.getBuffer(), EC); - fatal(EC); + check(EC); return F; } @@ -73,7 +73,7 @@ uint32_t ELFFileBase::getSectionIndex(const Elf_Sym &Sym) const { template void ELFFileBase::initStringTable() { if (!Symtab) return; - StringTable = fatal(ELFObj.getStringTableForSymtab(*Symtab)); + StringTable = check(ELFObj.getStringTableForSymtab(*Symtab)); } template @@ -122,11 +122,11 @@ template StringRef elf::ObjectFile::getShtGroupSignature(const Elf_Shdr &Sec) { const ELFFile &Obj = this->ELFObj; uint32_t SymtabdSectionIndex = Sec.sh_link; - const Elf_Shdr *SymtabSec = fatal(Obj.getSection(SymtabdSectionIndex)); + const Elf_Shdr *SymtabSec = check(Obj.getSection(SymtabdSectionIndex)); uint32_t SymIndex = Sec.sh_info; const Elf_Sym *Sym = Obj.getSymbol(SymtabSec, SymIndex); - StringRef StringTable = fatal(Obj.getStringTableForSymtab(*SymtabSec)); - return fatal(Sym->getName(StringTable)); + StringRef StringTable = check(Obj.getStringTableForSymtab(*SymtabSec)); + return check(Sym->getName(StringTable)); } template @@ -134,7 +134,7 @@ ArrayRef::uint32_X> elf::ObjectFile::getShtGroupEntries(const Elf_Shdr &Sec) { const ELFFile &Obj = this->ELFObj; ArrayRef Entries = - fatal(Obj.template getSectionContentsAsArray(&Sec)); + check(Obj.template getSectionContentsAsArray(&Sec)); if (Entries.empty() || Entries[0] != GRP_COMDAT) fatal("Unsupported SHT_GROUP format"); return Entries.slice(1); @@ -194,7 +194,7 @@ void elf::ObjectFile::initializeSections( this->Symtab = &Sec; break; case SHT_SYMTAB_SHNDX: - this->SymtabSHNDX = fatal(Obj.getSHNDXTable(Sec)); + this->SymtabSHNDX = check(Obj.getSHNDXTable(Sec)); break; case SHT_STRTAB: case SHT_NULL: @@ -236,7 +236,7 @@ void elf::ObjectFile::initializeSections( template InputSectionBase * elf::ObjectFile::createInputSection(const Elf_Shdr &Sec) { - StringRef Name = fatal(this->ELFObj.getSectionName(&Sec)); + StringRef Name = check(this->ELFObj.getSectionName(&Sec)); // .note.GNU-stack is a marker section to control the presence of // PT_GNU_STACK segment in outputs. Since the presence of the segment @@ -286,7 +286,7 @@ elf::ObjectFile::getSection(const Elf_Sym &Sym) const { template SymbolBody *elf::ObjectFile::createSymbolBody(const Elf_Sym *Sym) { - StringRef Name = fatal(Sym->getName(this->StringTable)); + StringRef Name = check(Sym->getName(this->StringTable)); switch (Sym->st_shndx) { case SHN_UNDEF: @@ -312,7 +312,7 @@ SymbolBody *elf::ObjectFile::createSymbolBody(const Elf_Sym *Sym) { } void ArchiveFile::parse() { - File = fatal(Archive::create(MB), "Failed to parse archive"); + File = check(Archive::create(MB), "Failed to parse archive"); // Allocate a buffer for Lazy objects. size_t NumSyms = File->getNumberOfSymbols(); @@ -326,13 +326,13 @@ void ArchiveFile::parse() { // Returns a buffer pointing to a member file containing a given symbol. MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) { Archive::Child C = - fatal(Sym->getMember(), + check(Sym->getMember(), "Could not get the member for symbol " + Sym->getName()); if (!Seen.insert(C.getChildOffset()).second) return MemoryBufferRef(); - return fatal(C.getMemoryBufferRef(), + return check(C.getMemoryBufferRef(), "Could not get the buffer for the member defining symbol " + Sym->getName()); } @@ -347,7 +347,7 @@ SharedFile::getSection(const Elf_Sym &Sym) const { uint32_t Index = this->getSectionIndex(Sym); if (Index == 0) return nullptr; - return fatal(this->ELFObj.getSection(Index)); + return check(this->ELFObj.getSection(Index)); } // Partially parse the shared object file so that we can call @@ -369,7 +369,7 @@ template void SharedFile::parseSoName() { DynamicSec = &Sec; break; case SHT_SYMTAB_SHNDX: - this->SymtabSHNDX = fatal(Obj.getSHNDXTable(Sec)); + this->SymtabSHNDX = check(Obj.getSHNDXTable(Sec)); break; } } @@ -401,7 +401,7 @@ template void SharedFile::parseRest() { SymbolBodies.reserve(NumSymbols); for (const Elf_Sym &Sym : Syms) { ErrorOr NameOrErr = Sym.getName(this->StringTable); - fatal(NameOrErr.getError()); + check(NameOrErr.getError()); StringRef Name = *NameOrErr; if (Sym.isUndefined()) @@ -419,7 +419,7 @@ bool BitcodeFile::classof(const InputFile *F) { void BitcodeFile::parse(DenseSet &ComdatGroups) { LLVMContext Context; - std::unique_ptr Obj = fatal(IRObjectFile::create(MB, Context)); + std::unique_ptr Obj = check(IRObjectFile::create(MB, Context)); const Module &M = Obj->getModule(); DenseSet KeptComdats; diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index e98d7d6..66fc79c 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -39,12 +39,12 @@ InputSectionBase::InputSectionBase(ObjectFile *File, } template StringRef InputSectionBase::getSectionName() const { - return fatal(File->getObj().getSectionName(this->Header)); + return check(File->getObj().getSectionName(this->Header)); } template ArrayRef InputSectionBase::getSectionData() const { - return fatal(this->File->getObj().getSectionContents(this->Header)); + return check(this->File->getObj().getSectionContents(this->Header)); } template diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 205911b..589a91e 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -137,7 +137,7 @@ ObjectFile *SymbolTable::createCombinedLtoObject() { std::unique_ptr Buffer = MemoryBuffer::getMemBuffer(F->MB, false); std::unique_ptr M = - fatal(getLazyBitcodeModule(std::move(Buffer), Context, + check(getLazyBitcodeModule(std::move(Buffer), Context, /*ShouldLazyLoadMetadata*/ true)); L.linkInModule(std::move(M)); } diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index c6c18d3..886883b 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -221,7 +221,7 @@ template void Writer::run() { writeSections(); if (HasError) return; - fatal(Buffer->commit()); + check(Buffer->commit()); } namespace { @@ -564,7 +564,7 @@ template void Writer::copyLocalSymbols() { return; for (const std::unique_ptr> &F : Symtab.getObjectFiles()) { for (const Elf_Sym &Sym : F->getLocalSymbols()) { - StringRef SymName = fatal(Sym.getName(F->getStringTable())); + StringRef SymName = check(Sym.getName(F->getStringTable())); if (!shouldKeepInSymtab(*F, SymName, Sym)) continue; if (Sym.st_shndx != SHN_ABS) { -- 2.7.4