Don't return error_code from a function that doesn't fail.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 30 Jun 2015 04:08:37 +0000 (04:08 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 30 Jun 2015 04:08:37 +0000 (04:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241042 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/COFF.h
include/llvm/Object/ELFObjectFile.h
include/llvm/Object/MachO.h
include/llvm/Object/ObjectFile.h
lib/DebugInfo/DWARF/DWARFContext.cpp
lib/Object/COFFObjectFile.cpp
lib/Object/MachOObjectFile.cpp
lib/Object/Object.cpp
tools/llvm-objdump/llvm-objdump.cpp
tools/llvm-readobj/COFFDumper.cpp
tools/llvm-readobj/MachODumper.cpp

index 21feebd339eae00f551fc6a795e96ae49fc5faca..ba565e26d6fd33100eaef5b4e68860296d329510 100644 (file)
@@ -679,9 +679,9 @@ protected:
   uint64_t getRelocationOffset(DataRefImpl Rel) const override;
   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
   uint64_t getRelocationType(DataRefImpl Rel) const override;
   uint64_t getRelocationOffset(DataRefImpl Rel) const override;
   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
   uint64_t getRelocationType(DataRefImpl Rel) const override;
-  std::error_code
-  getRelocationTypeName(DataRefImpl Rel,
-                        SmallVectorImpl<char> &Result) const override;
+  void getRelocationTypeName(DataRefImpl Rel,
+                             SmallVectorImpl<char> &Result) const override;
+
 public:
   COFFObjectFile(MemoryBufferRef Object, std::error_code &EC);
   basic_symbol_iterator symbol_begin_impl() const override;
 public:
   COFFObjectFile(MemoryBufferRef Object, std::error_code &EC);
   basic_symbol_iterator symbol_begin_impl() const override;
index e7b3ce18ae5182a7b6719028fe2be5b85b81de74..e689dc2a34edcd72379650b5f6e1998801a5f46c 100644 (file)
@@ -234,9 +234,8 @@ protected:
   uint64_t getRelocationOffset(DataRefImpl Rel) const override;
   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
   uint64_t getRelocationType(DataRefImpl Rel) const override;
   uint64_t getRelocationOffset(DataRefImpl Rel) const override;
   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
   uint64_t getRelocationType(DataRefImpl Rel) const override;
-  std::error_code
-  getRelocationTypeName(DataRefImpl Rel,
-                        SmallVectorImpl<char> &Result) const override;
+  void getRelocationTypeName(DataRefImpl Rel,
+                             SmallVectorImpl<char> &Result) const override;
 
   uint32_t getSectionType(DataRefImpl Sec) const override;
   uint64_t getSectionFlags(DataRefImpl Sec) const override;
 
   uint32_t getSectionType(DataRefImpl Sec) const override;
   uint64_t getSectionFlags(DataRefImpl Sec) const override;
@@ -738,17 +737,10 @@ StringRef ELFObjectFile<ELFT>::getRelocationTypeName(uint32_t Type) const {
 }
 
 template <class ELFT>
 }
 
 template <class ELFT>
-std::error_code ELFObjectFile<ELFT>::getRelocationTypeName(
+void ELFObjectFile<ELFT>::getRelocationTypeName(
     DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
     DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
-  const Elf_Shdr *sec = getRelSection(Rel);
-  uint32_t type;
-  if (sec->sh_type == ELF::SHT_REL)
-    type = getRel(Rel)->getType(EF.isMips64EL());
-  else
-    type = getRela(Rel)->getType(EF.isMips64EL());
-
+  uint32_t type = getRelocationType(Rel);
   EF.getRelocationTypeName(type, Result);
   EF.getRelocationTypeName(type, Result);
-  return std::error_code();
 }
 
 template <class ELFT>
 }
 
 template <class ELFT>
index 50baeb79a0b2f6e30e29b48898a213e83a5f0686..6d2d14ed27b1e1bc4dfe1f870881155163e96ea1 100644 (file)
@@ -241,9 +241,8 @@ public:
   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
   section_iterator getRelocationSection(DataRefImpl Rel) const;
   uint64_t getRelocationType(DataRefImpl Rel) const override;
   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
   section_iterator getRelocationSection(DataRefImpl Rel) const;
   uint64_t getRelocationType(DataRefImpl Rel) const override;
-  std::error_code
-  getRelocationTypeName(DataRefImpl Rel,
-                        SmallVectorImpl<char> &Result) const override;
+  void getRelocationTypeName(DataRefImpl Rel,
+                             SmallVectorImpl<char> &Result) const override;
   uint8_t getRelocationLength(DataRefImpl Rel) const;
 
   // MachO specific.
   uint8_t getRelocationLength(DataRefImpl Rel) const;
 
   // MachO specific.
index 7056471d2512ef86d64f6bca304adc6badce7d54..2510d341c05938bfe4134554ea866adb8884c552 100644 (file)
@@ -58,8 +58,7 @@ public:
   /// @brief Get a string that represents the type of this relocation.
   ///
   /// This is for display purposes only.
   /// @brief Get a string that represents the type of this relocation.
   ///
   /// This is for display purposes only.
-  std::error_code getTypeName(SmallVectorImpl<char> &Result) const;
-
+  void getTypeName(SmallVectorImpl<char> &Result) const;
 
   DataRefImpl getRawDataRefImpl() const;
   const ObjectFile *getObject() const;
 
   DataRefImpl getRawDataRefImpl() const;
   const ObjectFile *getObject() const;
@@ -238,9 +237,8 @@ protected:
   virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
   virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
   virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
   virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
   virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
   virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
-  virtual std::error_code
-  getRelocationTypeName(DataRefImpl Rel,
-                        SmallVectorImpl<char> &Result) const = 0;
+  virtual void getRelocationTypeName(DataRefImpl Rel,
+                                     SmallVectorImpl<char> &Result) const = 0;
 
 public:
   uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
 
 public:
   uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
@@ -457,8 +455,7 @@ inline uint64_t RelocationRef::getType() const {
   return OwningObject->getRelocationType(RelocationPimpl);
 }
 
   return OwningObject->getRelocationType(RelocationPimpl);
 }
 
-inline std::error_code
-RelocationRef::getTypeName(SmallVectorImpl<char> &Result) const {
+inline void RelocationRef::getTypeName(SmallVectorImpl<char> &Result) const {
   return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
 }
 
   return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
 }
 
index 2940d6d8cf3268bb1fbeb1fd238636b68e8457a7..c25ddad33b7615346012055bbe8ef8a130043d73 100644 (file)
@@ -707,10 +707,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
         object::RelocToApply R(V.visit(Type, Reloc, SymAddr));
         if (V.error()) {
           SmallString<32> Name;
         object::RelocToApply R(V.visit(Type, Reloc, SymAddr));
         if (V.error()) {
           SmallString<32> Name;
-          std::error_code ec(Reloc.getTypeName(Name));
-          if (ec) {
-            errs() << "Aaaaaa! Nameless relocation! Aaaaaa!\n";
-          }
+          Reloc.getTypeName(Name);
           errs() << "error: failed to compute relocation: "
                  << Name << "\n";
           continue;
           errs() << "error: failed to compute relocation: "
                  << Name << "\n";
           continue;
index 733fd49ad777b092c4e8f39682db8abebeed9e14..3babc210dd95dd2d93e6035f92c03949033056ff 100644 (file)
@@ -1031,9 +1031,8 @@ COFFObjectFile::getRelocations(const coff_section *Sec) const {
     Res = #reloc_type;                                                         \
     break;
 
     Res = #reloc_type;                                                         \
     break;
 
-std::error_code
-COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
-                                      SmallVectorImpl<char> &Result) const {
+void COFFObjectFile::getRelocationTypeName(
+    DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
   const coff_relocation *Reloc = toRel(Rel);
   StringRef Res;
   switch (getMachine()) {
   const coff_relocation *Reloc = toRel(Rel);
   StringRef Res;
   switch (getMachine()) {
@@ -1102,7 +1101,6 @@ COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
     Res = "Unknown";
   }
   Result.append(Res.begin(), Res.end());
     Res = "Unknown";
   }
   Result.append(Res.begin(), Res.end());
-  return std::error_code();
 }
 
 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
 }
 
 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
index 9763fabca82390f053b67cd4130ddaed4feea37d..79220f42c51b8769ca6c53231dcde4f6214d1444 100644 (file)
@@ -659,9 +659,8 @@ uint64_t MachOObjectFile::getRelocationType(DataRefImpl Rel) const {
   return getAnyRelocationType(RE);
 }
 
   return getAnyRelocationType(RE);
 }
 
-std::error_code
-MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
-                                       SmallVectorImpl<char> &Result) const {
+void MachOObjectFile::getRelocationTypeName(
+    DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
   StringRef res;
   uint64_t RType = getRelocationType(Rel);
 
   StringRef res;
   uint64_t RType = getRelocationType(Rel);
 
@@ -767,7 +766,6 @@ MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
       break;
   }
   Result.append(res.begin(), res.end());
       break;
   }
   Result.append(res.begin(), res.end());
-  return std::error_code();
 }
 
 uint8_t MachOObjectFile::getRelocationLength(DataRefImpl Rel) const {
 }
 
 uint8_t MachOObjectFile::getRelocationLength(DataRefImpl Rel) const {
index aba9a4498032089be0b2a7f882d7e77e17ad1fa1..173dd62fc32dc871624c3f633a3e3b70be24fb34 100644 (file)
@@ -214,9 +214,7 @@ uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) {
 // NOTE: Caller takes ownership of returned string.
 const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) {
   SmallVector<char, 0> ret;
 // NOTE: Caller takes ownership of returned string.
 const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) {
   SmallVector<char, 0> ret;
-  if (std::error_code ec = (*unwrap(RI))->getTypeName(ret))
-    report_fatal_error(ec.message());
-
+  (*unwrap(RI))->getTypeName(ret);
   char *str = static_cast<char*>(malloc(ret.size()));
   std::copy(ret.begin(), ret.end(), str);
   return str;
   char *str = static_cast<char*>(malloc(ret.size()));
   std::copy(ret.begin(), ret.end(), str);
   return str;
index b17cb0b47ea2ca824a4384c81b29e6d7196edc6c..dde7e55cfa053acda3799a676bdc7ed1681eaf16 100644 (file)
@@ -931,7 +931,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
 
           // Stop when rel_cur's address is past the current instruction.
           if (addr >= Index + Size) break;
 
           // Stop when rel_cur's address is past the current instruction.
           if (addr >= Index + Size) break;
-          if (error(rel_cur->getTypeName(name))) goto skip_print_rel;
+          rel_cur->getTypeName(name);
           if (error(getRelocationValueString(*rel_cur, val)))
             goto skip_print_rel;
           outs() << format(Fmt.data(), SectionAddr + addr) << name
           if (error(getRelocationValueString(*rel_cur, val)))
             goto skip_print_rel;
           outs() << format(Fmt.data(), SectionAddr + addr) << name
@@ -967,8 +967,7 @@ void llvm::PrintRelocations(const ObjectFile *Obj) {
       SmallString<32> valuestr;
       if (hidden)
         continue;
       SmallString<32> valuestr;
       if (hidden)
         continue;
-      if (error(Reloc.getTypeName(relocname)))
-        continue;
+      Reloc.getTypeName(relocname);
       if (error(getRelocationValueString(Reloc, valuestr)))
         continue;
       outs() << format(Fmt.data(), address) << " " << relocname << " "
       if (error(getRelocationValueString(Reloc, valuestr)))
         continue;
       outs() << format(Fmt.data(), address) << " " << relocname << " "
index 40085274cde1e6513ae1738568b72ea1e0d4d14a..5dde7f93edf8d69cafd53dab7bce2837546afabf 100644 (file)
@@ -807,8 +807,7 @@ void COFFDumper::printRelocation(const SectionRef &Section,
   uint64_t RelocType = Reloc.getType();
   SmallString<32> RelocName;
   StringRef SymbolName;
   uint64_t RelocType = Reloc.getType();
   SmallString<32> RelocName;
   StringRef SymbolName;
-  if (error(Reloc.getTypeName(RelocName)))
-    return;
+  Reloc.getTypeName(RelocName);
   symbol_iterator Symbol = Reloc.getSymbol();
   if (Symbol != Obj->symbol_end() && error(Symbol->getName(SymbolName)))
     return;
   symbol_iterator Symbol = Reloc.getSymbol();
   if (Symbol != Obj->symbol_end() && error(Symbol->getName(SymbolName)))
     return;
index 7365ad7396a041d819b83691f9a6ea90657fdf7b..049c9f5d8c1b386dbce5bba332f2443f617ae595 100644 (file)
@@ -463,8 +463,7 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj,
                                   const RelocationRef &Reloc) {
   uint64_t Offset = Reloc.getOffset();
   SmallString<32> RelocName;
                                   const RelocationRef &Reloc) {
   uint64_t Offset = Reloc.getOffset();
   SmallString<32> RelocName;
-  if (error(Reloc.getTypeName(RelocName)))
-    return;
+  Reloc.getTypeName(RelocName);
 
   DataRefImpl DR = Reloc.getRawDataRefImpl();
   MachO::any_relocation_info RE = Obj->getRelocation(DR);
 
   DataRefImpl DR = Reloc.getRawDataRefImpl();
   MachO::any_relocation_info RE = Obj->getRelocation(DR);