[llvm] r285944 - Replace another report_fatal_error with an ErrorOr.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 3 10:37:28 PDT 2016


Author: rafael
Date: Thu Nov  3 12:37:28 2016
New Revision: 285944

URL: http://llvm.org/viewvc/llvm-project?rev=285944&view=rev
Log:
Replace another report_fatal_error with an ErrorOr.

Modified:
    llvm/trunk/include/llvm/Object/ELF.h
    llvm/trunk/include/llvm/Object/ELFObjectFile.h

Modified: llvm/trunk/include/llvm/Object/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELF.h?rev=285944&r1=285943&r2=285944&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELF.h (original)
+++ llvm/trunk/include/llvm/Object/ELF.h Thu Nov  3 12:37:28 2016
@@ -72,8 +72,8 @@ private:
   const Elf_Ehdr *Header;
 
 public:
-  template<typename T>
-  const T        *getEntry(uint32_t Section, uint32_t Entry) const;
+  template <typename T>
+  ErrorOr<const T *> getEntry(uint32_t Section, uint32_t Entry) const;
   template <typename T>
   const T *getEntry(const Elf_Shdr *Section, uint32_t Entry) const;
 
@@ -403,10 +403,11 @@ ErrorOr<typename ELFT::ShdrRange> ELFFil
 
 template <class ELFT>
 template <typename T>
-const T *ELFFile<ELFT>::getEntry(uint32_t Section, uint32_t Entry) const {
+ErrorOr<const T *> ELFFile<ELFT>::getEntry(uint32_t Section,
+                                           uint32_t Entry) const {
   ErrorOr<const Elf_Shdr *> Sec = getSection(Section);
   if (std::error_code EC = Sec.getError())
-    report_fatal_error(EC.message());
+    return EC;
   return getEntry<T>(*Sec, Entry);
 }
 

Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=285944&r1=285943&r2=285944&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Thu Nov  3 12:37:28 2016
@@ -317,7 +317,10 @@ public:
   const Elf_Rela *getRela(DataRefImpl Rela) const;
 
   const Elf_Sym *getSymbol(DataRefImpl Sym) const {
-    return EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b);
+    auto Ret = EF.template getEntry<Elf_Sym>(Sym.d.a, Sym.d.b);
+    if (std::error_code EC = Ret.getError())
+      report_fatal_error(EC.message());
+    return *Ret;
   }
 
   const Elf_Shdr *getSection(DataRefImpl Sec) const {
@@ -749,14 +752,20 @@ template <class ELFT>
 const typename ELFObjectFile<ELFT>::Elf_Rel *
 ELFObjectFile<ELFT>::getRel(DataRefImpl Rel) const {
   assert(getRelSection(Rel)->sh_type == ELF::SHT_REL);
-  return EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
+  auto Ret = EF.template getEntry<Elf_Rel>(Rel.d.a, Rel.d.b);
+  if (std::error_code EC = Ret.getError())
+    report_fatal_error(EC.message());
+  return *Ret;
 }
 
 template <class ELFT>
 const typename ELFObjectFile<ELFT>::Elf_Rela *
 ELFObjectFile<ELFT>::getRela(DataRefImpl Rela) const {
   assert(getRelSection(Rela)->sh_type == ELF::SHT_RELA);
-  return EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
+  auto Ret = EF.template getEntry<Elf_Rela>(Rela.d.a, Rela.d.b);
+  if (std::error_code EC = Ret.getError())
+    report_fatal_error(EC.message());
+  return *Ret;
 }
 
 template <class ELFT>




More information about the llvm-commits mailing list