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

13 files changed:
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/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h
lib/Object/COFFObjectFile.cpp
lib/Object/MachOObjectFile.cpp
lib/Object/Object.cpp
lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp
lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp
tools/llvm-readobj/COFFDumper.cpp

index ce12aab6fba6f49c1832f6628184a27f14a56096..21feebd339eae00f551fc6a795e96ae49fc5faca 100644 (file)
@@ -678,8 +678,7 @@ protected:
                                        uint64_t &Res) const override;
   uint64_t getRelocationOffset(DataRefImpl Rel) const override;
   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
-  std::error_code getRelocationType(DataRefImpl Rel,
-                                    uint64_t &Res) const override;
+  uint64_t getRelocationType(DataRefImpl Rel) const override;
   std::error_code
   getRelocationTypeName(DataRefImpl Rel,
                         SmallVectorImpl<char> &Result) const override;
index b21a1a1c99c73f7baa912c7166198685a41147d6..e7b3ce18ae5182a7b6719028fe2be5b85b81de74 100644 (file)
@@ -233,8 +233,7 @@ protected:
                                        uint64_t &Res) const override;
   uint64_t getRelocationOffset(DataRefImpl Rel) const override;
   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
-  std::error_code getRelocationType(DataRefImpl Rel,
-                                    uint64_t &Res) const override;
+  uint64_t getRelocationType(DataRefImpl Rel) const override;
   std::error_code
   getRelocationTypeName(DataRefImpl Rel,
                         SmallVectorImpl<char> &Result) const override;
@@ -725,14 +724,12 @@ uint64_t ELFObjectFile<ELFT>::getROffset(DataRefImpl Rel) const {
 }
 
 template <class ELFT>
-std::error_code ELFObjectFile<ELFT>::getRelocationType(DataRefImpl Rel,
-                                                       uint64_t &Result) const {
+uint64_t ELFObjectFile<ELFT>::getRelocationType(DataRefImpl Rel) const {
   const Elf_Shdr *sec = getRelSection(Rel);
   if (sec->sh_type == ELF::SHT_REL)
-    Result = getRel(Rel)->getType(EF.isMips64EL());
+    return getRel(Rel)->getType(EF.isMips64EL());
   else
-    Result = getRela(Rel)->getType(EF.isMips64EL());
-  return std::error_code();
+    return getRela(Rel)->getType(EF.isMips64EL());
 }
 
 template <class ELFT>
index 43f8b0a11e2c4980cc4602107b072718527ba924..c067a7023c10c7bda0d5430f0a6b1a094fe6bb87 100644 (file)
@@ -240,8 +240,7 @@ public:
   uint64_t getRelocationOffset(DataRefImpl Rel) const override;
   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
   section_iterator getRelocationSection(DataRefImpl Rel) const;
-  std::error_code getRelocationType(DataRefImpl Rel,
-                                    uint64_t &Res) const override;
+  uint64_t getRelocationType(DataRefImpl Rel) const override;
   std::error_code
   getRelocationTypeName(DataRefImpl Rel,
                         SmallVectorImpl<char> &Result) const override;
index ba7a5c4f2ef2db954527b21e303fb42433100b13..3fcafc966e590eb0e6d64c9b20dc92df84eb9a8c 100644 (file)
@@ -53,7 +53,7 @@ public:
   std::error_code getAddress(uint64_t &Result) const;
   uint64_t getOffset() const;
   symbol_iterator getSymbol() const;
-  std::error_code getType(uint64_t &Result) const;
+  uint64_t getType() const;
 
   /// @brief Indicates whether this relocation should hidden when listing
   /// relocations, usually because it is the trailing part of a multipart
@@ -242,8 +242,7 @@ protected:
                                                uint64_t &Res) const = 0;
   virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
   virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
-  virtual std::error_code getRelocationType(DataRefImpl Rel,
-                                            uint64_t &Res) const = 0;
+  virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
   virtual std::error_code
   getRelocationTypeName(DataRefImpl Rel,
                         SmallVectorImpl<char> &Result) const = 0;
@@ -464,8 +463,8 @@ inline symbol_iterator RelocationRef::getSymbol() const {
   return OwningObject->getRelocationSymbol(RelocationPimpl);
 }
 
-inline std::error_code RelocationRef::getType(uint64_t &Result) const {
-  return OwningObject->getRelocationType(RelocationPimpl, Result);
+inline uint64_t RelocationRef::getType() const {
+  return OwningObject->getRelocationType(RelocationPimpl);
 }
 
 inline std::error_code
index b63d4326b16eb9073724d93175ffd8c437fd1793..2940d6d8cf3268bb1fbeb1fd238636b68e8457a7 100644 (file)
@@ -668,8 +668,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
       uint64_t SectionSize = RelocatedSection->getSize();
       for (const RelocationRef &Reloc : Section.relocations()) {
         uint64_t Address = Reloc.getOffset();
-        uint64_t Type;
-        Reloc.getType(Type);
+        uint64_t Type = Reloc.getType();
         uint64_t SymAddr = 0;
         uint64_t SectionLoadAddress = 0;
         object::symbol_iterator Sym = Reloc.getSymbol();
index 6311c6ec5e433f73e4d25c2296ded2f9561dad54..1761c42af23d8145bf80cc55857d11f2fc3058d3 100644 (file)
@@ -772,8 +772,7 @@ void RuntimeDyldELF::findOPDEntrySection(const ELFObjectFileBase &Obj,
          i != e;) {
       // The R_PPC64_ADDR64 relocation indicates the first field
       // of a .opd entry
-      uint64_t TypeFunc;
-      check(i->getType(TypeFunc));
+      uint64_t TypeFunc = i->getType();
       if (TypeFunc != ELF::R_PPC64_ADDR64) {
         ++i;
         continue;
@@ -790,8 +789,7 @@ void RuntimeDyldELF::findOPDEntrySection(const ELFObjectFileBase &Obj,
         break;
 
       // Just check if following relocation is a R_PPC64_TOC
-      uint64_t TypeTOC;
-      check(i->getType(TypeTOC));
+      uint64_t TypeTOC = i->getType();
       if (TypeTOC != ELF::R_PPC64_TOC)
         continue;
 
@@ -1059,8 +1057,7 @@ relocation_iterator RuntimeDyldELF::processRelocationRef(
     unsigned SectionID, relocation_iterator RelI, const ObjectFile &O,
     ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) {
   const auto &Obj = cast<ELFObjectFileBase>(O);
-  uint64_t RelType;
-  Check(RelI->getType(RelType));
+  uint64_t RelType = RelI->getType();
   ErrorOr<int64_t> AddendOrErr = ELFRelocationRef(*RelI).getAddend();
   int64_t Addend = AddendOrErr ? *AddendOrErr : 0;
   elf_symbol_iterator Symbol = RelI->getSymbol();
index d7f0ab0e8a4c1d8cd0a72effa0236ac160a6063b..95d5dce4b3ef4b1f3d1ac04ba7b23e0b6df116c9 100644 (file)
@@ -125,8 +125,7 @@ public:
     const bool IsExtern = SecI == Obj.section_end();
 
     // Determine the Addend used to adjust the relocation value.
-    uint64_t RelType;
-    Check(RelI->getType(RelType));
+    uint64_t RelType = RelI->getType();
     uint64_t Offset = RelI->getOffset();
     uint64_t Addend = 0;
     SectionEntry &Section = Sections[SectionID];
index 6263d32db8c82bd4dd997e92f23b6343dce1fb20..733fd49ad777b092c4e8f39682db8abebeed9e14 100644 (file)
@@ -990,11 +990,9 @@ symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const {
   return symbol_iterator(SymbolRef(Ref, this));
 }
 
-std::error_code COFFObjectFile::getRelocationType(DataRefImpl Rel,
-                                                  uint64_t &Res) const {
+uint64_t COFFObjectFile::getRelocationType(DataRefImpl Rel) const {
   const coff_relocation* R = toRel(Rel);
-  Res = R->Type;
-  return std::error_code();
+  return R->Type;
 }
 
 const coff_section *
index ef8daacee14f675834c8648d355f2658674d654b..5de72125afe003e7340bc8083d7075daab7b9242 100644 (file)
@@ -654,19 +654,16 @@ MachOObjectFile::getRelocationSection(DataRefImpl Rel) const {
   return section_iterator(getAnyRelocationSection(getRelocation(Rel)));
 }
 
-std::error_code MachOObjectFile::getRelocationType(DataRefImpl Rel,
-                                                   uint64_t &Res) const {
+uint64_t MachOObjectFile::getRelocationType(DataRefImpl Rel) const {
   MachO::any_relocation_info RE = getRelocation(Rel);
-  Res = getAnyRelocationType(RE);
-  return std::error_code();
+  return getAnyRelocationType(RE);
 }
 
 std::error_code
 MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
                                        SmallVectorImpl<char> &Result) const {
   StringRef res;
-  uint64_t RType;
-  getRelocationType(Rel, RType);
+  uint64_t RType = getRelocationType(Rel);
 
   unsigned Arch = this->getArch();
 
@@ -776,8 +773,7 @@ MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
 std::error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel,
                                                      bool &Result) const {
   unsigned Arch = getArch();
-  uint64_t Type;
-  getRelocationType(Rel, Type);
+  uint64_t Type = getRelocationType(Rel);
 
   Result = false;
 
@@ -791,8 +787,7 @@ std::error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel,
     if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
       DataRefImpl RelPrev = Rel;
       RelPrev.d.a--;
-      uint64_t PrevType;
-      getRelocationType(RelPrev, PrevType);
+      uint64_t PrevType = getRelocationType(RelPrev);
       if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR)
         Result = true;
     }
index 6c4bd3cdb883ea6e45ec763231f1331e823e138f..aba9a4498032089be0b2a7f882d7e77e17ad1fa1 100644 (file)
@@ -208,10 +208,7 @@ LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) {
 }
 
 uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) {
-  uint64_t ret;
-  if (std::error_code ec = (*unwrap(RI))->getType(ret))
-    report_fatal_error(ec.message());
-  return ret;
+  return (*unwrap(RI))->getType();
 }
 
 // NOTE: Caller takes ownership of returned string.
index 857838443583e869f42103e1a16cc121a1021043..d819c693265a5717dd151d023045573d1ac5ed17 100644 (file)
@@ -26,7 +26,7 @@ public:
   X86_64ELFRelocationInfo(MCContext &Ctx) : MCRelocationInfo(Ctx) {}
 
   const MCExpr *createExprForRelocation(RelocationRef Rel) override {
-    uint64_t RelType; Rel.getType(RelType);
+    uint64_t RelType = Rel.getType();
     elf_symbol_iterator SymI = Rel.getSymbol();
 
     StringRef SymName; SymI->getName(SymName);
index cc78e2c0ef2cfacace631a5dc759e1c1b556f2f9..34b6424bebe8fca2f0857edd0857f6a8de001d40 100644 (file)
@@ -27,7 +27,7 @@ public:
   const MCExpr *createExprForRelocation(RelocationRef Rel) override {
     const MachOObjectFile *Obj = cast<MachOObjectFile>(Rel.getObject());
 
-    uint64_t RelType; Rel.getType(RelType);
+    uint64_t RelType = Rel.getType();
     symbol_iterator SymI = Rel.getSymbol();
 
     StringRef SymName; SymI->getName(SymName);
index 1b8bdbe2acee74c85021c7aa9a711976f1e13833..40085274cde1e6513ae1738568b72ea1e0d4d14a 100644 (file)
@@ -804,11 +804,9 @@ void COFFDumper::printRelocations() {
 void COFFDumper::printRelocation(const SectionRef &Section,
                                  const RelocationRef &Reloc) {
   uint64_t Offset = Reloc.getOffset();
-  uint64_t RelocType;
+  uint64_t RelocType = Reloc.getType();
   SmallString<32> RelocName;
   StringRef SymbolName;
-  if (error(Reloc.getType(RelocType)))
-    return;
   if (error(Reloc.getTypeName(RelocName)))
     return;
   symbol_iterator Symbol = Reloc.getSymbol();