From f8a35ff558cbbfac81b252b3f2de6a6fe42fb12c Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 30 Jun 2015 04:08:37 +0000 Subject: [PATCH] Don't return error_code from a function that doesn't fail. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241042 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/COFF.h | 6 +++--- include/llvm/Object/ELFObjectFile.h | 16 ++++------------ include/llvm/Object/MachO.h | 5 ++--- include/llvm/Object/ObjectFile.h | 11 ++++------- lib/DebugInfo/DWARF/DWARFContext.cpp | 5 +---- lib/Object/COFFObjectFile.cpp | 6 ++---- lib/Object/MachOObjectFile.cpp | 6 ++---- lib/Object/Object.cpp | 4 +--- tools/llvm-objdump/llvm-objdump.cpp | 5 ++--- tools/llvm-readobj/COFFDumper.cpp | 3 +-- tools/llvm-readobj/MachODumper.cpp | 3 +-- 11 files changed, 23 insertions(+), 47 deletions(-) diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 21feebd339e..ba565e26d6f 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -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; - std::error_code - getRelocationTypeName(DataRefImpl Rel, - SmallVectorImpl &Result) const override; + void getRelocationTypeName(DataRefImpl Rel, + SmallVectorImpl &Result) const override; + public: COFFObjectFile(MemoryBufferRef Object, std::error_code &EC); basic_symbol_iterator symbol_begin_impl() const override; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index e7b3ce18ae5..e689dc2a34e 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -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; - std::error_code - getRelocationTypeName(DataRefImpl Rel, - SmallVectorImpl &Result) const override; + void getRelocationTypeName(DataRefImpl Rel, + SmallVectorImpl &Result) const override; uint32_t getSectionType(DataRefImpl Sec) const override; uint64_t getSectionFlags(DataRefImpl Sec) const override; @@ -738,17 +737,10 @@ StringRef ELFObjectFile::getRelocationTypeName(uint32_t Type) const { } template -std::error_code ELFObjectFile::getRelocationTypeName( +void ELFObjectFile::getRelocationTypeName( DataRefImpl Rel, SmallVectorImpl &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); - return std::error_code(); } template diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 50baeb79a0b..6d2d14ed27b 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -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; - std::error_code - getRelocationTypeName(DataRefImpl Rel, - SmallVectorImpl &Result) const override; + void getRelocationTypeName(DataRefImpl Rel, + SmallVectorImpl &Result) const override; uint8_t getRelocationLength(DataRefImpl Rel) const; // MachO specific. diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 7056471d251..2510d341c05 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -58,8 +58,7 @@ public: /// @brief Get a string that represents the type of this relocation. /// /// This is for display purposes only. - std::error_code getTypeName(SmallVectorImpl &Result) const; - + void getTypeName(SmallVectorImpl &Result) 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 std::error_code - getRelocationTypeName(DataRefImpl Rel, - SmallVectorImpl &Result) const = 0; + virtual void getRelocationTypeName(DataRefImpl Rel, + SmallVectorImpl &Result) const = 0; public: uint64_t getCommonSymbolSize(DataRefImpl Symb) const { @@ -457,8 +455,7 @@ inline uint64_t RelocationRef::getType() const { return OwningObject->getRelocationType(RelocationPimpl); } -inline std::error_code -RelocationRef::getTypeName(SmallVectorImpl &Result) const { +inline void RelocationRef::getTypeName(SmallVectorImpl &Result) const { return OwningObject->getRelocationTypeName(RelocationPimpl, Result); } diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index 2940d6d8cf3..c25ddad33b7 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -707,10 +707,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, 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; diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 733fd49ad77..3babc210dd9 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -1031,9 +1031,8 @@ COFFObjectFile::getRelocations(const coff_section *Sec) const { Res = #reloc_type; \ break; -std::error_code -COFFObjectFile::getRelocationTypeName(DataRefImpl Rel, - SmallVectorImpl &Result) const { +void COFFObjectFile::getRelocationTypeName( + DataRefImpl Rel, SmallVectorImpl &Result) const { 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()); - return std::error_code(); } #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 9763fabca82..79220f42c51 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -659,9 +659,8 @@ uint64_t MachOObjectFile::getRelocationType(DataRefImpl Rel) const { return getAnyRelocationType(RE); } -std::error_code -MachOObjectFile::getRelocationTypeName(DataRefImpl Rel, - SmallVectorImpl &Result) const { +void MachOObjectFile::getRelocationTypeName( + DataRefImpl Rel, SmallVectorImpl &Result) const { StringRef res; uint64_t RType = getRelocationType(Rel); @@ -767,7 +766,6 @@ MachOObjectFile::getRelocationTypeName(DataRefImpl Rel, break; } Result.append(res.begin(), res.end()); - return std::error_code(); } uint8_t MachOObjectFile::getRelocationLength(DataRefImpl Rel) const { diff --git a/lib/Object/Object.cpp b/lib/Object/Object.cpp index aba9a449803..173dd62fc32 100644 --- a/lib/Object/Object.cpp +++ b/lib/Object/Object.cpp @@ -214,9 +214,7 @@ uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) { // NOTE: Caller takes ownership of returned string. const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) { SmallVector ret; - if (std::error_code ec = (*unwrap(RI))->getTypeName(ret)) - report_fatal_error(ec.message()); - + (*unwrap(RI))->getTypeName(ret); char *str = static_cast(malloc(ret.size())); std::copy(ret.begin(), ret.end(), str); return str; diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index b17cb0b47ea..dde7e55cfa0 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -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; - 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 @@ -967,8 +967,7 @@ void llvm::PrintRelocations(const ObjectFile *Obj) { 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 << " " diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 40085274cde..5dde7f93edf 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -807,8 +807,7 @@ void COFFDumper::printRelocation(const SectionRef &Section, 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; diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index 7365ad7396a..049c9f5d8c1 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -463,8 +463,7 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj, 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); -- 2.34.1