From: Rafael Espindola Date: Tue, 30 Jun 2015 01:53:01 +0000 (+0000) Subject: Don't return error_code from a function that doesn't fail. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7ede9649c143982b17b42db941b15592257a6ffb;p=oota-llvm.git Don't return error_code from a function that doesn't fail. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241033 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index ce12aab6fba..21feebd339e 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -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 &Result) const override; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index b21a1a1c99c..e7b3ce18ae5 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -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 &Result) const override; @@ -725,14 +724,12 @@ uint64_t ELFObjectFile::getROffset(DataRefImpl Rel) const { } template -std::error_code ELFObjectFile::getRelocationType(DataRefImpl Rel, - uint64_t &Result) const { +uint64_t ELFObjectFile::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 diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 43f8b0a11e2..c067a7023c1 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -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 &Result) const override; diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index ba7a5c4f2ef..3fcafc966e5 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -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 &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 diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index b63d4326b16..2940d6d8cf3 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -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(); diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 6311c6ec5e4..1761c42af23 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -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(O); - uint64_t RelType; - Check(RelI->getType(RelType)); + uint64_t RelType = RelI->getType(); ErrorOr AddendOrErr = ELFRelocationRef(*RelI).getAddend(); int64_t Addend = AddendOrErr ? *AddendOrErr : 0; elf_symbol_iterator Symbol = RelI->getSymbol(); diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h index d7f0ab0e8a4..95d5dce4b3e 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h @@ -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]; diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 6263d32db8c..733fd49ad77 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -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 * diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index ef8daacee14..5de72125afe 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -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 &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; } diff --git a/lib/Object/Object.cpp b/lib/Object/Object.cpp index 6c4bd3cdb88..aba9a449803 100644 --- a/lib/Object/Object.cpp +++ b/lib/Object/Object.cpp @@ -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. diff --git a/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp b/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp index 85783844358..d819c693265 100644 --- a/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp +++ b/lib/Target/X86/MCTargetDesc/X86ELFRelocationInfo.cpp @@ -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); diff --git a/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp b/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp index cc78e2c0ef2..34b6424bebe 100644 --- a/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp +++ b/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp @@ -27,7 +27,7 @@ public: const MCExpr *createExprForRelocation(RelocationRef Rel) override { const MachOObjectFile *Obj = cast(Rel.getObject()); - uint64_t RelType; Rel.getType(RelType); + uint64_t RelType = Rel.getType(); symbol_iterator SymI = Rel.getSymbol(); StringRef SymName; SymI->getName(SymName); diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 1b8bdbe2ace..40085274cde 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -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();