[lld] r262666 - Rename 'fatal' to 'check' when it doesn't always fail.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 3 14:24:39 PST 2016


Author: rafael
Date: Thu Mar  3 16:24:39 2016
New Revision: 262666

URL: http://llvm.org/viewvc/llvm-project?rev=262666&view=rev
Log:
Rename 'fatal' to 'check' when it doesn't always fail.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Error.cpp
    lld/trunk/ELF/Error.h
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=262666&r1=262665&r2=262666&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Mar  3 16:24:39 2016
@@ -71,14 +71,14 @@ static std::pair<ELFKind, uint16_t> pars
 // Each slice consists of a member file in the archive.
 static std::vector<MemoryBufferRef> getArchiveMembers(MemoryBufferRef MB) {
   std::unique_ptr<Archive> File =
-      fatal(Archive::create(MB), "Failed to parse archive");
+      check(Archive::create(MB), "Failed to parse archive");
 
   std::vector<MemoryBufferRef> V;
   for (const ErrorOr<Archive::Child> &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);

Modified: lld/trunk/ELF/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.cpp?rev=262666&r1=262665&r2=262666&view=diff
==============================================================================
--- lld/trunk/ELF/Error.cpp (original)
+++ lld/trunk/ELF/Error.cpp Thu Mar  3 16:24:39 2016
@@ -54,7 +54,7 @@ void fatal(const Twine &Msg, const Twine
   fatal(Prefix + ": " + Msg);
 }
 
-void fatal(std::error_code EC) {
+void check(std::error_code EC) {
   if (EC)
     fatal(EC.message());
 }

Modified: lld/trunk/ELF/Error.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.h?rev=262666&r1=262665&r2=262666&view=diff
==============================================================================
--- lld/trunk/ELF/Error.h (original)
+++ lld/trunk/ELF/Error.h Thu Mar  3 16:24:39 2016
@@ -35,15 +35,15 @@ template <typename T> bool error(const E
 
 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 <class T> T fatal(ErrorOr<T> EO) {
+template <class T> T check(ErrorOr<T> EO) {
   if (EO)
     return std::move(*EO);
   fatal(EO.getError().message());
 }
 
-template <class T> T fatal(ErrorOr<T> EO, const Twine &Prefix) {
+template <class T> T check(ErrorOr<T> EO, const Twine &Prefix) {
   if (EO)
     return std::move(*EO);
   fatal(EO.getError().message(), Prefix);

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=262666&r1=262665&r2=262666&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Mar  3 16:24:39 2016
@@ -29,7 +29,7 @@ template <class ELFT>
 static ELFFile<ELFT> createELFObj(MemoryBufferRef MB) {
   std::error_code EC;
   ELFFile<ELFT> F(MB.getBuffer(), EC);
-  fatal(EC);
+  check(EC);
   return F;
 }
 
@@ -73,7 +73,7 @@ uint32_t ELFFileBase<ELFT>::getSectionIn
 template <class ELFT> void ELFFileBase<ELFT>::initStringTable() {
   if (!Symtab)
     return;
-  StringTable = fatal(ELFObj.getStringTableForSymtab(*Symtab));
+  StringTable = check(ELFObj.getStringTableForSymtab(*Symtab));
 }
 
 template <class ELFT>
@@ -122,11 +122,11 @@ template <class ELFT>
 StringRef elf::ObjectFile<ELFT>::getShtGroupSignature(const Elf_Shdr &Sec) {
   const ELFFile<ELFT> &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 <class ELFT>
@@ -134,7 +134,7 @@ ArrayRef<typename elf::ObjectFile<ELFT>:
 elf::ObjectFile<ELFT>::getShtGroupEntries(const Elf_Shdr &Sec) {
   const ELFFile<ELFT> &Obj = this->ELFObj;
   ArrayRef<uint32_X> Entries =
-      fatal(Obj.template getSectionContentsAsArray<uint32_X>(&Sec));
+      check(Obj.template getSectionContentsAsArray<uint32_X>(&Sec));
   if (Entries.empty() || Entries[0] != GRP_COMDAT)
     fatal("Unsupported SHT_GROUP format");
   return Entries.slice(1);
@@ -194,7 +194,7 @@ void elf::ObjectFile<ELFT>::initializeSe
       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<ELFT>::initializeSe
 template <class ELFT>
 InputSectionBase<ELFT> *
 elf::ObjectFile<ELFT>::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<ELFT>::getSection(const
 
 template <class ELFT>
 SymbolBody *elf::ObjectFile<ELFT>::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<ELFT>::creat
 }
 
 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<ELFT>::getSection(const Elf_S
   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 <class ELFT> void SharedFile<EL
       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 <class ELFT> void SharedFile<EL
   SymbolBodies.reserve(NumSymbols);
   for (const Elf_Sym &Sym : Syms) {
     ErrorOr<StringRef> 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 InputFil
 
 void BitcodeFile::parse(DenseSet<StringRef> &ComdatGroups) {
   LLVMContext Context;
-  std::unique_ptr<IRObjectFile> Obj = fatal(IRObjectFile::create(MB, Context));
+  std::unique_ptr<IRObjectFile> Obj = check(IRObjectFile::create(MB, Context));
   const Module &M = Obj->getModule();
 
   DenseSet<const Comdat *> KeptComdats;

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=262666&r1=262665&r2=262666&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Mar  3 16:24:39 2016
@@ -39,12 +39,12 @@ InputSectionBase<ELFT>::InputSectionBase
 }
 
 template <class ELFT> StringRef InputSectionBase<ELFT>::getSectionName() const {
-  return fatal(File->getObj().getSectionName(this->Header));
+  return check(File->getObj().getSectionName(this->Header));
 }
 
 template <class ELFT>
 ArrayRef<uint8_t> InputSectionBase<ELFT>::getSectionData() const {
-  return fatal(this->File->getObj().getSectionContents(this->Header));
+  return check(this->File->getObj().getSectionContents(this->Header));
 }
 
 template <class ELFT>

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=262666&r1=262665&r2=262666&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Thu Mar  3 16:24:39 2016
@@ -137,7 +137,7 @@ ObjectFile<ELFT> *SymbolTable<ELFT>::cre
     std::unique_ptr<MemoryBuffer> Buffer =
         MemoryBuffer::getMemBuffer(F->MB, false);
     std::unique_ptr<Module> M =
-        fatal(getLazyBitcodeModule(std::move(Buffer), Context,
+        check(getLazyBitcodeModule(std::move(Buffer), Context,
                                    /*ShouldLazyLoadMetadata*/ true));
     L.linkInModule(std::move(M));
   }

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=262666&r1=262665&r2=262666&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Mar  3 16:24:39 2016
@@ -221,7 +221,7 @@ template <class ELFT> void Writer<ELFT>:
   writeSections();
   if (HasError)
     return;
-  fatal(Buffer->commit());
+  check(Buffer->commit());
 }
 
 namespace {
@@ -564,7 +564,7 @@ template <class ELFT> void Writer<ELFT>:
     return;
   for (const std::unique_ptr<ObjectFile<ELFT>> &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<ELFT>(*F, SymName, Sym))
         continue;
       if (Sym.st_shndx != SHN_ABS) {




More information about the llvm-commits mailing list