]> granicus.if.org Git - llvm/commitdiff
Replace another report_fatal_error with an ErrorOr.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 3 Nov 2016 17:37:28 +0000 (17:37 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 3 Nov 2016 17:37:28 +0000 (17:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285944 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/ELF.h
include/llvm/Object/ELFObjectFile.h

index fe56c39d768c9c4d9d5207e5dd5bfe4220f8f38b..d8adb30ee32a23a8bc19481a271e8a465947c03f 100644 (file)
@@ -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> ELFFile<ELFT>::sections() const {
 
 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);
 }
 
index ad1c2e12ce1e0cb2dbf22643df9c8f94ddc3d23e..f7e9cb9a89f783e0a275eba76849049604884879 100644 (file)
@@ -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>