[lld] r320005 - Remove checkToString functions and use toString instead.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 19:24:57 PST 2017


Author: ruiu
Date: Wed Dec  6 19:24:57 2017
New Revision: 320005

URL: http://llvm.org/viewvc/llvm-project?rev=320005&view=rev
Log:
Remove checkToString functions and use toString instead.

Differential Revision: https://reviews.llvm.org/D40928

Modified:
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/include/lld/Common/ErrorHandler.h

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=320005&r1=320004&r2=320005&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Wed Dec  6 19:24:57 2017
@@ -63,7 +63,7 @@ ArchiveFile::ArchiveFile(MemoryBufferRef
 
 void ArchiveFile::parse() {
   // Parse a MemoryBufferRef as an archive file.
-  File = CHECK(Archive::create(MB), toString(this));
+  File = CHECK(Archive::create(MB), this);
 
   // Read the symbol table to construct Lazy objects.
   for (const Archive::Symbol &Sym : File->symbols())
@@ -104,7 +104,7 @@ std::vector<MemoryBufferRef> getArchiveM
 
 void ObjFile::parse() {
   // Parse a memory buffer as a COFF file.
-  std::unique_ptr<Binary> Bin = CHECK(createBinary(MB), toString(this));
+  std::unique_ptr<Binary> Bin = CHECK(createBinary(MB), this);
 
   if (auto *Obj = dyn_cast<COFFObjectFile>(Bin.get())) {
     Bin.release();

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=320005&r1=320004&r2=320005&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Dec  6 19:24:57 2017
@@ -209,20 +209,19 @@ typename ELFT::SymRange ELFFileBase<ELFT
 
 template <class ELFT>
 uint32_t ELFFileBase<ELFT>::getSectionIndex(const Elf_Sym &Sym) const {
-  return CHECK(getObj().getSectionIndex(&Sym, ELFSyms, SymtabSHNDX),
-               toString(this));
+  return CHECK(getObj().getSectionIndex(&Sym, ELFSyms, SymtabSHNDX), this);
 }
 
 template <class ELFT>
 void ELFFileBase<ELFT>::initSymtab(ArrayRef<Elf_Shdr> Sections,
                                    const Elf_Shdr *Symtab) {
   FirstNonLocal = Symtab->sh_info;
-  ELFSyms = CHECK(getObj().symbols(Symtab), toString(this));
+  ELFSyms = CHECK(getObj().symbols(Symtab), this);
   if (FirstNonLocal == 0 || FirstNonLocal > ELFSyms.size())
     fatal(toString(this) + ": invalid sh_info in symbol table");
 
-  StringTable = CHECK(getObj().getStringTableForSymtab(*Symtab, Sections),
-                      toString(this));
+  StringTable =
+      CHECK(getObj().getStringTableForSymtab(*Symtab, Sections), this);
 }
 
 template <class ELFT>
@@ -254,12 +253,11 @@ StringRef ObjFile<ELFT>::getShtGroupSign
   // sh_info contains a symbol index, so we fetch a symbol and read its name.
   if (this->ELFSyms.empty())
     this->initSymtab(
-        Sections,
-        CHECK(object::getSection<ELFT>(Sections, Sec.sh_link), toString(this)));
+        Sections, CHECK(object::getSection<ELFT>(Sections, Sec.sh_link), this));
 
-  const Elf_Sym *Sym = CHECK(
-      object::getSymbol<ELFT>(this->ELFSyms, Sec.sh_info), toString(this));
-  StringRef Signature = CHECK(Sym->getName(this->StringTable), toString(this));
+  const Elf_Sym *Sym =
+      CHECK(object::getSymbol<ELFT>(this->ELFSyms, Sec.sh_info), this);
+  StringRef Signature = CHECK(Sym->getName(this->StringTable), this);
 
   // As a special case, if a symbol is a section symbol and has no name,
   // we use a section name as a signature.
@@ -277,8 +275,8 @@ template <class ELFT>
 ArrayRef<typename ObjFile<ELFT>::Elf_Word>
 ObjFile<ELFT>::getShtGroupEntries(const Elf_Shdr &Sec) {
   const ELFFile<ELFT> &Obj = this->getObj();
-  ArrayRef<Elf_Word> Entries = CHECK(
-      Obj.template getSectionContentsAsArray<Elf_Word>(&Sec), toString(this));
+  ArrayRef<Elf_Word> Entries =
+      CHECK(Obj.template getSectionContentsAsArray<Elf_Word>(&Sec), this);
   if (Entries.empty() || Entries[0] != GRP_COMDAT)
     fatal(toString(this) + ": unsupported SHT_GROUP format");
   return Entries.slice(1);
@@ -323,12 +321,11 @@ void ObjFile<ELFT>::initializeSections(
     DenseSet<CachedHashStringRef> &ComdatGroups) {
   const ELFFile<ELFT> &Obj = this->getObj();
 
-  ArrayRef<Elf_Shdr> ObjSections =
-      CHECK(this->getObj().sections(), toString(this));
+  ArrayRef<Elf_Shdr> ObjSections = CHECK(this->getObj().sections(), this);
   uint64_t Size = ObjSections.size();
   this->Sections.resize(Size);
   this->SectionStringTable =
-      CHECK(Obj.getSectionStringTable(ObjSections), toString(this));
+      CHECK(Obj.getSectionStringTable(ObjSections), this);
 
   for (size_t I = 0, E = ObjSections.size(); I < E; I++) {
     if (this->Sections[I] == &InputSection::Discarded)
@@ -374,8 +371,7 @@ void ObjFile<ELFT>::initializeSections(
       this->initSymtab(ObjSections, &Sec);
       break;
     case SHT_SYMTAB_SHNDX:
-      this->SymtabSHNDX =
-          CHECK(Obj.getSHNDXTable(Sec, ObjSections), toString(this));
+      this->SymtabSHNDX = CHECK(Obj.getSHNDXTable(Sec, ObjSections), this);
       break;
     case SHT_STRTAB:
     case SHT_NULL:
@@ -520,13 +516,12 @@ InputSectionBase *ObjFile<ELFT>::createI
 
     size_t NumRelocations;
     if (Sec.sh_type == SHT_RELA) {
-      ArrayRef<Elf_Rela> Rels =
-          CHECK(this->getObj().relas(&Sec), toString(this));
+      ArrayRef<Elf_Rela> Rels = CHECK(this->getObj().relas(&Sec), this);
       Target->FirstRelocation = Rels.begin();
       NumRelocations = Rels.size();
       Target->AreRelocsRela = true;
     } else {
-      ArrayRef<Elf_Rel> Rels = CHECK(this->getObj().rels(&Sec), toString(this));
+      ArrayRef<Elf_Rel> Rels = CHECK(this->getObj().rels(&Sec), this);
       Target->FirstRelocation = Rels.begin();
       NumRelocations = Rels.size();
       Target->AreRelocsRela = false;
@@ -595,8 +590,7 @@ InputSectionBase *ObjFile<ELFT>::createI
 
 template <class ELFT>
 StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &Sec) {
-  return CHECK(this->getObj().getSectionName(&Sec, SectionStringTable),
-               toString(this));
+  return CHECK(this->getObj().getSectionName(&Sec, SectionStringTable), this);
 }
 
 template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
@@ -628,7 +622,7 @@ template <class ELFT> Symbol *ObjFile<EL
 
   if (Binding == STB_LOCAL) {
     if (Sym->getType() == STT_FILE)
-      SourceFile = CHECK(Sym->getName(this->StringTable), toString(this));
+      SourceFile = CHECK(Sym->getName(this->StringTable), this);
 
     if (this->StringTable.size() <= Sym->st_name)
       fatal(toString(this) + ": invalid symbol name offset");
@@ -640,7 +634,7 @@ template <class ELFT> Symbol *ObjFile<EL
     return make<Defined>(this, Name, Binding, StOther, Type, Value, Size, Sec);
   }
 
-  StringRef Name = CHECK(Sym->getName(this->StringTable), toString(this));
+  StringRef Name = CHECK(Sym->getName(this->StringTable), this);
 
   switch (Sym->st_shndx) {
   case SHN_UNDEF:
@@ -695,8 +689,7 @@ ArchiveFile::getMember(const Archive::Sy
                 Sym->getName());
 
   if (C.getParent()->isThin() && Tar)
-    Tar->append(relativeToRoot(CHECK(C.getFullName(), toString(this))),
-                Ret.getBuffer());
+    Tar->append(relativeToRoot(CHECK(C.getFullName(), this)), Ret.getBuffer());
   if (C.getParent()->isThin())
     return {Ret, 0};
   return {Ret, C.getChildOffset()};
@@ -712,7 +705,7 @@ SharedFile<ELFT>::SharedFile(MemoryBuffe
 template <class ELFT> void SharedFile<ELFT>::parseSoName() {
   const Elf_Shdr *DynamicSec = nullptr;
   const ELFFile<ELFT> Obj = this->getObj();
-  ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), toString(this));
+  ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), this);
 
   // Search for .dynsym, .dynamic, .symtab, .gnu.version and .gnu.version_d.
   for (const Elf_Shdr &Sec : Sections) {
@@ -726,8 +719,7 @@ template <class ELFT> void SharedFile<EL
       DynamicSec = &Sec;
       break;
     case SHT_SYMTAB_SHNDX:
-      this->SymtabSHNDX =
-          CHECK(Obj.getSHNDXTable(Sec, Sections), toString(this));
+      this->SymtabSHNDX = CHECK(Obj.getSHNDXTable(Sec, Sections), this);
       break;
     case SHT_GNU_versym:
       this->VersymSec = &Sec;
@@ -745,8 +737,7 @@ template <class ELFT> void SharedFile<EL
   if (!DynamicSec)
     return;
   ArrayRef<Elf_Dyn> Arr =
-      CHECK(Obj.template getSectionContentsAsArray<Elf_Dyn>(DynamicSec),
-            toString(this));
+      CHECK(Obj.template getSectionContentsAsArray<Elf_Dyn>(DynamicSec), this);
   for (const Elf_Dyn &Dyn : Arr) {
     if (Dyn.d_tag == DT_SONAME) {
       uint64_t Val = Dyn.getVal();
@@ -805,8 +796,7 @@ template <class ELFT> void SharedFile<EL
   const Elf_Versym *Versym = nullptr;
   std::vector<const Elf_Verdef *> Verdefs = parseVerdefs(Versym);
 
-  ArrayRef<Elf_Shdr> Sections =
-      CHECK(this->getObj().sections(), toString(this));
+  ArrayRef<Elf_Shdr> Sections = CHECK(this->getObj().sections(), this);
 
   // Add symbols to the symbol table.
   Elf_Sym_Range Syms = this->getGlobalELFSyms();
@@ -819,7 +809,7 @@ template <class ELFT> void SharedFile<EL
     bool Hidden = VersymIndex & VERSYM_HIDDEN;
     VersymIndex = VersymIndex & ~VERSYM_HIDDEN;
 
-    StringRef Name = CHECK(Sym.getName(this->StringTable), toString(this));
+    StringRef Name = CHECK(Sym.getName(this->StringTable), this);
     if (Sym.isUndefined()) {
       Undefs.push_back(Name);
       continue;
@@ -916,7 +906,7 @@ BitcodeFile::BitcodeFile(MemoryBufferRef
   MemoryBufferRef MBRef(MB.getBuffer(),
                         Saver.save(ArchiveName + MB.getBufferIdentifier() +
                                    utostr(OffsetInArchive)));
-  Obj = CHECK(lto::InputFile::create(MBRef), toString(this));
+  Obj = CHECK(lto::InputFile::create(MBRef), this);
 
   Triple T(Obj->getTargetTriple());
   EKind = getBitcodeELFKind(T);
@@ -1081,20 +1071,20 @@ template <class ELFT> std::vector<String
   typedef typename ELFT::SymRange Elf_Sym_Range;
 
   ELFFile<ELFT> Obj = check(ELFFile<ELFT>::create(this->MB.getBuffer()));
-  ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), toString(this));
+  ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), this);
   for (const Elf_Shdr &Sec : Sections) {
     if (Sec.sh_type != SHT_SYMTAB)
       continue;
 
-    Elf_Sym_Range Syms = CHECK(Obj.symbols(&Sec), toString(this));
+    Elf_Sym_Range Syms = CHECK(Obj.symbols(&Sec), this);
     uint32_t FirstNonLocal = Sec.sh_info;
     StringRef StringTable =
-        CHECK(Obj.getStringTableForSymtab(Sec, Sections), toString(this));
+        CHECK(Obj.getStringTableForSymtab(Sec, Sections), this);
     std::vector<StringRef> V;
 
     for (const Elf_Sym &Sym : Syms.slice(FirstNonLocal))
       if (Sym.st_shndx != SHN_UNDEF)
-        V.push_back(CHECK(Sym.getName(StringTable), toString(this)));
+        V.push_back(CHECK(Sym.getName(StringTable), this));
     return V;
   }
   return {};
@@ -1102,7 +1092,7 @@ template <class ELFT> std::vector<String
 
 std::vector<StringRef> LazyObjFile::getBitcodeSymbols() {
   std::unique_ptr<lto::InputFile> Obj =
-      CHECK(lto::InputFile::create(this->MB), toString(this));
+      CHECK(lto::InputFile::create(this->MB), this);
   std::vector<StringRef> V;
   for (const lto::InputFile::Symbol &Sym : Obj->symbols())
     if (!Sym.isUndefined())

Modified: lld/trunk/include/lld/Common/ErrorHandler.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/ErrorHandler.h?rev=320005&r1=320004&r2=320005&view=diff
==============================================================================
--- lld/trunk/include/lld/Common/ErrorHandler.h (original)
+++ lld/trunk/include/lld/Common/ErrorHandler.h Wed Dec  6 19:24:57 2017
@@ -102,12 +102,10 @@ T check2(Expected<T> E, llvm::function_r
   return std::move(*E);
 }
 
-inline std::string checkToString(const Twine &S) { return S.str(); }
-inline std::string checkToString(std::string S) { return S; }
-inline std::string checkToString(const char *S) { return S; }
+inline std::string toString(const Twine &S) { return S.str(); }
 
 // To evaluate the second argument lazily, we use C macro.
-#define CHECK(E, S) check2(E, [&] { return checkToString(S); })
+#define CHECK(E, S) check2(E, [&] { return toString(S); })
 
 } // namespace lld
 




More information about the llvm-commits mailing list