diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h index 2c2bd4823ce..6091e610469 100644 --- a/include/llvm/Object/COFF.h +++ b/include/llvm/Object/COFF.h @@ -271,8 +271,7 @@ private: error_code initExportTablePtr(); protected: - error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const - LLVM_OVERRIDE; + void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE; error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const LLVM_OVERRIDE; error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const @@ -288,8 +287,7 @@ protected: LLVM_OVERRIDE; error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const LLVM_OVERRIDE; - error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const - LLVM_OVERRIDE; + void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE; error_code getSectionName(DataRefImpl Sec, StringRef &Res) const LLVM_OVERRIDE; error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const @@ -313,8 +311,7 @@ protected: relocation_iterator section_rel_begin(DataRefImpl Sec) const LLVM_OVERRIDE; relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE; - error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const - LLVM_OVERRIDE; + void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE; error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const LLVM_OVERRIDE; error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const @@ -397,7 +394,7 @@ public: : ImportTable(Table), Index(I), OwningObject(Owner) {} bool operator==(const ImportDirectoryEntryRef &Other) const; - error_code getNext(ImportDirectoryEntryRef &Result) const; + void moveNext(); error_code getName(StringRef &Result) const; error_code @@ -421,7 +418,7 @@ public: : ExportTable(Table), Index(I), OwningObject(Owner) {} bool operator==(const ExportDirectoryEntryRef &Other) const; - error_code getNext(ExportDirectoryEntryRef &Result) const; + void moveNext(); error_code getDllName(StringRef &Result) const; error_code getOrdinalBase(uint32_t &Result) const; diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index 0a16b07e426..45bcde6155b 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -55,8 +55,7 @@ public: protected: ELFFile EF; - error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const - LLVM_OVERRIDE; + void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE; error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const LLVM_OVERRIDE; error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const @@ -78,8 +77,7 @@ protected: error_code getLibraryPath(DataRefImpl Data, StringRef &Res) const LLVM_OVERRIDE; - error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const - LLVM_OVERRIDE; + void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE; error_code getSectionName(DataRefImpl Sec, StringRef &Res) const LLVM_OVERRIDE; error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const @@ -102,8 +100,7 @@ protected: relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE; section_iterator getRelocatedSection(DataRefImpl Sec) const LLVM_OVERRIDE; - error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const - LLVM_OVERRIDE; + void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE; error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const LLVM_OVERRIDE; error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const @@ -222,10 +219,8 @@ typedef ELFObjectFile > ELF32BEObjectFile; typedef ELFObjectFile > ELF64BEObjectFile; template -error_code ELFObjectFile::getSymbolNext(DataRefImpl Symb, - SymbolRef &Result) const { - Result = SymbolRef(toDRI(++toELFSymIter(Symb)), this); - return object_error::success; +void ELFObjectFile::moveSymbolNext(DataRefImpl &Symb) const { + Symb = toDRI(++toELFSymIter(Symb)); } template @@ -439,10 +434,8 @@ error_code ELFObjectFile::getSymbolValue(DataRefImpl Symb, } template -error_code ELFObjectFile::getSectionNext(DataRefImpl Sec, - SectionRef &Result) const { - Result = SectionRef(toDRI(++toELFShdrIter(Sec)), this); - return object_error::success; +void ELFObjectFile::moveSectionNext(DataRefImpl &Sec) const { + Sec = toDRI(++toELFShdrIter(Sec)); } template @@ -594,11 +587,8 @@ ELFObjectFile::getRelocatedSection(DataRefImpl Sec) const { // Relocations template -error_code ELFObjectFile::getRelocationNext(DataRefImpl Rel, - RelocationRef &Result) const { +void ELFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { ++Rel.d.b; - Result = RelocationRef(Rel, this); - return object_error::success; } template diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 731a07be607..fb548e32622 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -38,7 +38,7 @@ public: bool operator==(const DiceRef &Other) const; bool operator<(const DiceRef &Other) const; - error_code getNext(DiceRef &Result) const; + void moveNext(); error_code getOffset(uint32_t &Result) const; error_code getLength(uint16_t &Result) const; @@ -59,8 +59,7 @@ public: MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, bool Is64Bits, error_code &EC, bool BufferOwned = true); - error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const - LLVM_OVERRIDE; + void moveSymbolNext(DataRefImpl &Symb) const LLVM_OVERRIDE; error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const LLVM_OVERRIDE; error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const @@ -79,8 +78,7 @@ public: error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const LLVM_OVERRIDE; - error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const - LLVM_OVERRIDE; + void moveSectionNext(DataRefImpl &Sec) const LLVM_OVERRIDE; error_code getSectionName(DataRefImpl Sec, StringRef &Res) const LLVM_OVERRIDE; error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const @@ -104,8 +102,7 @@ public: relocation_iterator section_rel_begin(DataRefImpl Sec) const LLVM_OVERRIDE; relocation_iterator section_rel_end(DataRefImpl Sec) const LLVM_OVERRIDE; - error_code getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const - LLVM_OVERRIDE; + void moveRelocationNext(DataRefImpl &Rel) const LLVM_OVERRIDE; error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const LLVM_OVERRIDE; error_code getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const @@ -244,13 +241,10 @@ inline bool DiceRef::operator<(const DiceRef &Other) const { return DicePimpl < Other.DicePimpl; } -inline error_code DiceRef::getNext(DiceRef &Result) const { - DataRefImpl Rel = DicePimpl; +inline void DiceRef::moveNext() { const MachO::data_in_code_entry *P = - reinterpret_cast(Rel.p); - Rel.p = reinterpret_cast(P + 1); - Result = DiceRef(Rel, OwningObject); - return object_error::success; + reinterpret_cast(DicePimpl.p); + DicePimpl.p = reinterpret_cast(P + 1); } // Since a Mach-O data in code reference, a DiceRef, can only be created when diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h index 7533d625b12..1d6c536d4f6 100644 --- a/include/llvm/Object/ObjectFile.h +++ b/include/llvm/Object/ObjectFile.h @@ -63,12 +63,8 @@ public: return !(*this == other); } - content_iterator& increment(error_code &err) { - content_type next; - if (error_code ec = Current.getNext(next)) - err = ec; - else - Current = next; + content_iterator &operator++() { // preincrement + Current.moveNext(); return *this; } }; @@ -101,7 +97,7 @@ public: bool operator==(const RelocationRef &Other) const; - error_code getNext(RelocationRef &Result) const; + void moveNext(); error_code getAddress(uint64_t &Result) const; error_code getOffset(uint64_t &Result) const; @@ -146,7 +142,7 @@ public: bool operator==(const SectionRef &Other) const; bool operator<(const SectionRef &Other) const; - error_code getNext(SectionRef &Result) const; + void moveNext(); error_code getName(StringRef &Result) const; error_code getAddress(uint64_t &Result) const; @@ -210,7 +206,7 @@ public: bool operator==(const SymbolRef &Other) const; bool operator<(const SymbolRef &Other) const; - error_code getNext(SymbolRef &Result) const; + void moveNext(); error_code getName(StringRef &Result) const; /// Returns the symbol virtual address (i.e. address at which it will be @@ -285,7 +281,7 @@ protected: // Implementations assume that the DataRefImpl is valid and has not been // modified externally. It's UB otherwise. friend class SymbolRef; - virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const = 0; + virtual void moveSymbolNext(DataRefImpl &Symb) const = 0; virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0; virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const = 0; virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res)const=0; @@ -301,7 +297,7 @@ protected: // Same as above for SectionRef. friend class SectionRef; - virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const = 0; + virtual void moveSectionNext(DataRefImpl &Sec) const = 0; virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const = 0; virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const =0; virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const = 0; @@ -324,8 +320,7 @@ protected: // Same as above for RelocationRef. friend class RelocationRef; - virtual error_code getRelocationNext(DataRefImpl Rel, - RelocationRef &Res) const = 0; + virtual void moveRelocationNext(DataRefImpl &Rel) const = 0; virtual error_code getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const =0; virtual error_code getRelocationOffset(DataRefImpl Rel, @@ -412,8 +407,8 @@ inline bool SymbolRef::operator<(const SymbolRef &Other) const { return SymbolPimpl < Other.SymbolPimpl; } -inline error_code SymbolRef::getNext(SymbolRef &Result) const { - return OwningObject->getSymbolNext(SymbolPimpl, Result); +inline void SymbolRef::moveNext() { + return OwningObject->moveSymbolNext(SymbolPimpl); } inline error_code SymbolRef::getName(StringRef &Result) const { @@ -471,8 +466,8 @@ inline bool SectionRef::operator<(const SectionRef &Other) const { return SectionPimpl < Other.SectionPimpl; } -inline error_code SectionRef::getNext(SectionRef &Result) const { - return OwningObject->getSectionNext(SectionPimpl, Result); +inline void SectionRef::moveNext() { + return OwningObject->moveSectionNext(SectionPimpl); } inline error_code SectionRef::getName(StringRef &Result) const { @@ -554,8 +549,8 @@ inline bool RelocationRef::operator==(const RelocationRef &Other) const { return RelocationPimpl == Other.RelocationPimpl; } -inline error_code RelocationRef::getNext(RelocationRef &Result) const { - return OwningObject->getRelocationNext(RelocationPimpl, Result); +inline void RelocationRef::moveNext() { + return OwningObject->moveRelocationNext(RelocationPimpl); } inline error_code RelocationRef::getAddress(uint64_t &Result) const { diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARFContext.cpp index 3b73f7ff4df..daf7cdd98c6 100644 --- a/lib/DebugInfo/DWARFContext.cpp +++ b/lib/DebugInfo/DWARFContext.cpp @@ -603,10 +603,9 @@ static bool consumeCompressedDebugSectionHeader(StringRef &data, DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) : IsLittleEndian(Obj->isLittleEndian()), AddressSize(Obj->getBytesInAddress()) { - error_code ec; for (object::section_iterator i = Obj->begin_sections(), - e = Obj->end_sections(); - i != e; i.increment(ec)) { + e = Obj->end_sections(); + i != e; ++i) { StringRef name; i->getName(name); StringRef data; @@ -697,8 +696,8 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) : uint64_t SectionSize; RelocatedSection->getSize(SectionSize); for (object::relocation_iterator reloc_i = i->begin_relocations(), - reloc_e = i->end_relocations(); - reloc_i != reloc_e; reloc_i.increment(ec)) { + reloc_e = i->end_relocations(); + reloc_i != reloc_e; ++reloc_i) { uint64_t Address; reloc_i->getOffset(Address); uint64_t Type; diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index f99d7d0b279..6f9eefb68c9 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -115,12 +115,10 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) { // Maximum required total memory to allocate all common symbols uint64_t CommonSize = 0; - error_code err; // Parse symbols DEBUG(dbgs() << "Parse symbols:\n"); - for (symbol_iterator i = obj->begin_symbols(), e = obj->end_symbols(); - i != e; i.increment(err)) { - Check(err); + for (symbol_iterator i = obj->begin_symbols(), e = obj->end_symbols(); i != e; + ++i) { object::SymbolRef::Type SymType; StringRef Name; Check(i->getType(SymType)); @@ -173,18 +171,16 @@ ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) { // Parse and process relocations DEBUG(dbgs() << "Parse relocations:\n"); - for (section_iterator si = obj->begin_sections(), - se = obj->end_sections(); si != se; si.increment(err)) { - Check(err); + for (section_iterator si = obj->begin_sections(), se = obj->end_sections(); + si != se; ++si) { bool isFirstRelocation = true; unsigned SectionID = 0; StubMap Stubs; section_iterator RelocatedSection = si->getRelocatedSection(); for (relocation_iterator i = si->begin_relocations(), - e = si->end_relocations(); i != e; i.increment(err)) { - Check(err); - + e = si->end_relocations(); + i != e; ++i) { // If it's the first relocation in this section, find its SectionID if (isFirstRelocation) { SectionID = @@ -251,21 +247,21 @@ unsigned RuntimeDyldImpl::emitSection(ObjectImage &Obj, unsigned StubBufSize = 0, StubSize = getMaxStubSize(); - error_code err; const ObjectFile *ObjFile = Obj.getObjectFile(); // FIXME: this is an inefficient way to handle this. We should computed the // necessary section allocation size in loadObject by walking all the sections // once. if (StubSize > 0) { for (section_iterator SI = ObjFile->begin_sections(), - SE = ObjFile->end_sections(); - SI != SE; SI.increment(err), Check(err)) { + SE = ObjFile->end_sections(); + SI != SE; ++SI) { section_iterator RelSecI = SI->getRelocatedSection(); if (!(RelSecI == Section)) continue; for (relocation_iterator I = SI->begin_relocations(), - E = SI->end_relocations(); I != E; I.increment(err), Check(err)) { + E = SI->end_relocations(); + I != E; ++I) { StubBufSize += StubSize; } } diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 7f3a790d4b9..4dbd6794c61 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -621,10 +621,8 @@ void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj, RelocationValueRef &Rel) { // Get the ELF symbol value (st_value) to compare with Relocation offset in // .opd entries - - error_code err; - for (section_iterator si = Obj.begin_sections(), - se = Obj.end_sections(); si != se; si.increment(err)) { + for (section_iterator si = Obj.begin_sections(), se = Obj.end_sections(); + si != se; ++si) { section_iterator RelSecI = si->getRelocatedSection(); if (RelSecI == Obj.end_sections()) continue; @@ -636,14 +634,12 @@ void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj, for (relocation_iterator i = si->begin_relocations(), e = si->end_relocations(); i != e;) { - check(err); - // The R_PPC64_ADDR64 relocation indicates the first field // of a .opd entry uint64_t TypeFunc; check(i->getType(TypeFunc)); if (TypeFunc != ELF::R_PPC64_ADDR64) { - i.increment(err); + ++i; continue; } @@ -653,10 +649,9 @@ void RuntimeDyldELF::findOPDEntrySection(ObjectImage &Obj, int64_t Addend; check(getELFRelocationAddend(*i, Addend)); - i = i.increment(err); + ++i; if (i == e) break; - check(err); // Just check if following relocation is a R_PPC64_TOC uint64_t TypeTOC; diff --git a/lib/MC/MCObjectDisassembler.cpp b/lib/MC/MCObjectDisassembler.cpp index 16a110f09bf..85de4111b7f 100644 --- a/lib/MC/MCObjectDisassembler.cpp +++ b/lib/MC/MCObjectDisassembler.cpp @@ -37,11 +37,8 @@ MCObjectDisassembler::MCObjectDisassembler(const ObjectFile &Obj, : Obj(Obj), Dis(Dis), MIA(MIA), MOS(0) {} uint64_t MCObjectDisassembler::getEntrypoint() { - error_code ec; for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols(); - SI != SE; SI.increment(ec)) { - if (ec) - break; + SI != SE; ++SI) { StringRef Name; SI->getName(Name); if (Name == "main" || Name == "_main") { @@ -90,13 +87,8 @@ MCModule *MCObjectDisassembler::buildModule(bool withCFG) { } void MCObjectDisassembler::buildSectionAtoms(MCModule *Module) { - error_code ec; - for (section_iterator SI = Obj.begin_sections(), - SE = Obj.end_sections(); - SI != SE; - SI.increment(ec)) { - if (ec) break; - + for (section_iterator SI = Obj.begin_sections(), SE = Obj.end_sections(); + SI != SE; ++SI) { bool isText; SI->isText(isText); bool isData; SI->isData(isData); if (!isData && !isText) @@ -184,11 +176,8 @@ void MCObjectDisassembler::buildCFG(MCModule *Module) { AddressSetTy Splits; AddressSetTy Calls; - error_code ec; for (symbol_iterator SI = Obj.begin_symbols(), SE = Obj.end_symbols(); - SI != SE; SI.increment(ec)) { - if (ec) - break; + SI != SE; ++SI) { SymbolRef::Type SymType; SI->getType(SymType); if (SymType == SymbolRef::ST_Function) { @@ -506,11 +495,8 @@ MCMachOObjectDisassembler::MCMachOObjectDisassembler( : MCObjectDisassembler(MOOF, Dis, MIA), MOOF(MOOF), VMAddrSlide(VMAddrSlide), HeaderLoadAddress(HeaderLoadAddress) { - error_code ec; for (section_iterator SI = MOOF.begin_sections(), SE = MOOF.end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) - break; + SI != SE; ++SI) { StringRef Name; SI->getName(Name); // FIXME: We should use the S_ section type instead of the name. diff --git a/lib/MC/MCObjectSymbolizer.cpp b/lib/MC/MCObjectSymbolizer.cpp index cdf743e6bbb..3fb053dd789 100644 --- a/lib/MC/MCObjectSymbolizer.cpp +++ b/lib/MC/MCObjectSymbolizer.cpp @@ -52,10 +52,8 @@ MCMachObjectSymbolizer(MCContext &Ctx, OwningPtr &RelInfo, : MCObjectSymbolizer(Ctx, RelInfo, MOOF), MOOF(MOOF), StubsStart(0), StubsCount(0), StubSize(0), StubsIndSymIndex(0) { - error_code ec; for (section_iterator SI = MOOF->begin_sections(), SE = MOOF->end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) break; + SI != SE; ++SI) { StringRef Name; SI->getName(Name); if (Name == "__stubs") { SectionRef StubsSec = *SI; @@ -91,10 +89,8 @@ StringRef MCMachObjectSymbolizer::findExternalFunctionAt(uint64_t Addr) { StringRef SymName; symbol_iterator SI = MOOF->begin_symbols(); - error_code ec; - for (uint32_t i = 0; i != SymtabIdx; ++i) { - SI.increment(ec); - } + for (uint32_t i = 0; i != SymtabIdx; ++i) + ++SI; SI->getName(SymName); assert(SI != MOOF->end_symbols() && "Stub wasn't found in the symbol table!"); assert(SymName.front() == '_' && "Mach-O symbol doesn't start with '_'!"); @@ -159,10 +155,8 @@ tryAddingSymbolicOperand(MCInst &MI, raw_ostream &cStream, return false; uint64_t UValue = Value; // FIXME: map instead of looping each time? - error_code ec; for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols(); - SI != SE; SI.increment(ec)) { - if (ec) break; + SI != SE; ++SI) { uint64_t SymAddr; SI->getAddress(SymAddr); uint64_t SymSize; SI->getSize(SymSize); StringRef SymName; SI->getName(SymName); @@ -239,11 +233,8 @@ const RelocationRef *MCObjectSymbolizer::findRelocationAt(uint64_t Addr) { } void MCObjectSymbolizer::buildSectionList() { - error_code ec; for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) break; - + SI != SE; ++SI) { bool RequiredForExec; SI->isRequiredForExecution(RequiredForExec); if (RequiredForExec == false) continue; @@ -263,11 +254,8 @@ void MCObjectSymbolizer::buildSectionList() { } void MCObjectSymbolizer::buildRelocationByAddrMap() { - error_code ec; for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) break; - + SI != SE; ++SI) { section_iterator RelSecI = SI->getRelocatedSection(); if (RelSecI == Obj->end_sections()) continue; @@ -279,9 +267,7 @@ void MCObjectSymbolizer::buildRelocationByAddrMap() { continue; for (relocation_iterator RI = SI->begin_relocations(), RE = SI->end_relocations(); - RI != RE; - RI.increment(ec)) { - if (ec) break; + RI != RE; ++RI) { // FIXME: libObject is inconsistent regarding error handling. The // overwhelming majority of methods always return object_error::success, // and assert for simple errors.. Here, ELFObjectFile::getRelocationOffset diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index 1558d9d15fd..6439056dfad 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -87,13 +87,10 @@ const coff_section *COFFObjectFile::toSec(DataRefImpl Ref) const { return Addr; } -error_code COFFObjectFile::getSymbolNext(DataRefImpl Ref, - SymbolRef &Result) const { +void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const { const coff_symbol *Symb = toSymb(Ref); Symb += 1 + Symb->NumberOfAuxSymbols; Ref.p = reinterpret_cast(Symb); - Result = SymbolRef(Ref, this); - return object_error::success; } error_code COFFObjectFile::getSymbolName(DataRefImpl Ref, @@ -221,13 +218,10 @@ error_code COFFObjectFile::getSymbolValue(DataRefImpl Ref, report_fatal_error("getSymbolValue unimplemented in COFFObjectFile"); } -error_code COFFObjectFile::getSectionNext(DataRefImpl Ref, - SectionRef &Result) const { +void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const { const coff_section *Sec = toSec(Ref); Sec += 1; Ref.p = reinterpret_cast(Sec); - Result = SectionRef(Ref, this); - return object_error::success; } error_code COFFObjectFile::getSectionName(DataRefImpl Ref, @@ -386,11 +380,8 @@ error_code COFFObjectFile::initSymbolTablePtr() { // Returns the file offset for the given RVA. error_code COFFObjectFile::getRvaPtr(uint32_t Rva, uintptr_t &Res) const { - error_code EC; for (section_iterator I = begin_sections(), E = end_sections(); I != E; - I.increment(EC)) { - if (EC) - return EC; + ++I) { const coff_section *Section = getCOFFSection(I); uint32_t SectionStart = Section->VirtualAddress; uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize; @@ -801,12 +792,9 @@ const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const { return reinterpret_cast(Rel.p); } -error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel, - RelocationRef &Res) const { +void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { Rel.p = reinterpret_cast( reinterpret_cast(Rel.p) + 1); - Res = RelocationRef(Rel, this); - return object_error::success; } error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel, @@ -932,10 +920,8 @@ operator==(const ImportDirectoryEntryRef &Other) const { return ImportTable == Other.ImportTable && Index == Other.Index; } -error_code -ImportDirectoryEntryRef::getNext(ImportDirectoryEntryRef &Result) const { - Result = ImportDirectoryEntryRef(ImportTable, Index + 1, OwningObject); - return object_error::success; +void ImportDirectoryEntryRef::moveNext() { + ++Index; } error_code ImportDirectoryEntryRef:: @@ -967,10 +953,8 @@ operator==(const ExportDirectoryEntryRef &Other) const { return ExportTable == Other.ExportTable && Index == Other.Index; } -error_code -ExportDirectoryEntryRef::getNext(ExportDirectoryEntryRef &Result) const { - Result = ExportDirectoryEntryRef(ExportTable, Index + 1, OwningObject); - return object_error::success; +void ExportDirectoryEntryRef::moveNext() { + ++Index; } // Returns the name of the current export symbol. If the symbol is exported only diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 2409314e12c..49e3148ac8f 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -275,18 +275,9 @@ static StringRef parseSegmentOrSectionName(const char *P) { // Helper to advance a section or symbol iterator multiple increments at a time. template -static error_code advance(T &it, size_t Val) { - error_code ec; - while (Val--) { - it.increment(ec); - } - return ec; -} - -template -static void advanceTo(T &it, size_t Val) { - if (error_code ec = advance(it, Val)) - report_fatal_error(ec.message()); +static void advance(T &it, size_t Val) { + while (Val--) + ++it; } static unsigned getCPUType(const MachOObjectFile *O) { @@ -305,11 +296,9 @@ static void printRelocationTargetName(const MachOObjectFile *O, if (IsScattered) { uint32_t Val = O->getPlainRelocationSymbolNum(RE); - error_code ec; for (symbol_iterator SI = O->begin_symbols(), SE = O->end_symbols(); - SI != SE; SI.increment(ec)) { - if (ec) report_fatal_error(ec.message()); - + SI != SE; ++SI) { + error_code ec; uint64_t Addr; StringRef Name; @@ -325,9 +314,8 @@ static void printRelocationTargetName(const MachOObjectFile *O, // If we couldn't find a symbol that this relocation refers to, try // to find a section beginning instead. for (section_iterator SI = O->begin_sections(), SE = O->end_sections(); - SI != SE; SI.increment(ec)) { - if (ec) report_fatal_error(ec.message()); - + SI != SE; ++SI) { + error_code ec; uint64_t Addr; StringRef Name; @@ -350,12 +338,12 @@ static void printRelocationTargetName(const MachOObjectFile *O, if (isExtern) { symbol_iterator SI = O->begin_symbols(); - advanceTo(SI, Val); + advance(SI, Val); SI->getName(S); } else { section_iterator SI = O->begin_sections(); // Adjust for the fact that sections are 1-indexed. - advanceTo(SI, Val - 1); + advance(SI, Val - 1); SI->getName(S); } @@ -454,14 +442,11 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, bool IsLittleEndian, } } -error_code MachOObjectFile::getSymbolNext(DataRefImpl Symb, - SymbolRef &Res) const { +void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const { unsigned SymbolTableEntrySize = is64Bit() ? sizeof(MachO::nlist_64) : sizeof(MachO::nlist); Symb.p += SymbolTableEntrySize; - Res = SymbolRef(Symb, this); - return object_error::success; } error_code MachOObjectFile::getSymbolName(DataRefImpl Symb, @@ -545,9 +530,7 @@ error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI, } // Unfortunately symbols are unsorted so we need to touch all // symbols from load command - error_code ec; - for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E; - I.increment(ec)) { + for (symbol_iterator I = begin_symbols(), E = end_symbols(); I != E; ++I) { DataRefImpl DRI = I->getRawDataRefImpl(); Entry = getSymbolTableEntryBase(this, DRI); getSymbolAddress(DRI, Value); @@ -648,11 +631,8 @@ error_code MachOObjectFile::getSymbolValue(DataRefImpl Symb, report_fatal_error("getSymbolValue unimplemented in MachOObjectFile"); } -error_code MachOObjectFile::getSectionNext(DataRefImpl Sec, - SectionRef &Res) const { +void MachOObjectFile::moveSectionNext(DataRefImpl &Sec) const { Sec.d.a++; - Res = SectionRef(Sec, this); - return object_error::success; } error_code @@ -834,13 +814,10 @@ MachOObjectFile::section_rel_end(DataRefImpl Sec) const { return relocation_iterator(RelocationRef(Ret, this)); } -error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel, - RelocationRef &Res) const { +void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const { const MachO::any_relocation_info *P = reinterpret_cast(Rel.p); Rel.p = reinterpret_cast(P + 1); - Res = RelocationRef(Rel, this); - return object_error::success; } error_code diff --git a/lib/Object/Object.cpp b/lib/Object/Object.cpp index e454d8eec79..399d460f8ce 100644 --- a/lib/Object/Object.cpp +++ b/lib/Object/Object.cpp @@ -84,9 +84,7 @@ LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, } void LLVMMoveToNextSection(LLVMSectionIteratorRef SI) { - error_code ec; - unwrap(SI)->increment(ec); - if (ec) report_fatal_error("LLVMMoveToNextSection failed: " + ec.message()); + ++(*unwrap(SI)); } void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, @@ -111,9 +109,7 @@ LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile, } void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI) { - error_code ec; - unwrap(SI)->increment(ec); - if (ec) report_fatal_error("LLVMMoveToNextSymbol failed: " + ec.message()); + ++(*unwrap(SI)); } // SectionRef accessors @@ -169,10 +165,7 @@ LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section, } void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) { - error_code ec; - unwrap(SI)->increment(ec); - if (ec) report_fatal_error("LLVMMoveToNextRelocation failed: " + - ec.message()); + ++(*unwrap(SI)); } diff --git a/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp b/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp index 1114ff96cf4..024bdb75b4e 100644 --- a/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp +++ b/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp @@ -72,9 +72,9 @@ public: break; case X86_64_RELOC_SUBTRACTOR: { - RelocationRef RelNext; - Obj->getRelocationNext(Rel.getRawDataRefImpl(), RelNext); - any_relocation_info RENext = Obj->getRelocation(RelNext.getRawDataRefImpl()); + Rel.moveNext(); + any_relocation_info RENext = + Obj->getRelocation(Rel.getRawDataRefImpl()); // X86_64_SUBTRACTOR must be followed by a relocation of type // X86_64_RELOC_UNSIGNED. @@ -86,7 +86,7 @@ public: const MCExpr *LHS = MCSymbolRefExpr::Create(Sym, Ctx); - symbol_iterator RSymI = RelNext.getSymbol(); + symbol_iterator RSymI = Rel.getSymbol(); uint64_t RSymAddr; RSymI->getAddress(RSymAddr); StringRef RSymName; diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 8917cd3801f..bb5c0da8a3d 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -716,10 +716,9 @@ static void writeSymbolTable( print32BE(Out, 0); } - error_code Err; for (object::symbol_iterator I = Obj->begin_symbols(), E = Obj->end_symbols(); - I != E; I.increment(Err), failIfError(Err)) { + I != E; ++I) { uint32_t Symflags; failIfError(I->getFlags(Symflags)); if (Symflags & object::SymbolRef::SF_FormatSpecific) diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 495a71b0e90..da221d133a2 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -532,16 +532,13 @@ static char getNMTypeChar(ObjectFile *Obj, symbol_iterator I) { } static void dumpSymbolNamesFromObject(ObjectFile *Obj) { - error_code EC; symbol_iterator IBegin = Obj->begin_symbols(); symbol_iterator IEnd = Obj->end_symbols(); if (DynamicSyms) { IBegin = Obj->begin_dynamic_symbols(); IEnd = Obj->end_dynamic_symbols(); } - for (symbol_iterator I = IBegin; I != IEnd; I.increment(EC)) { - if (error(EC)) - break; + for (symbol_iterator I = IBegin; I != IEnd; ++I) { uint32_t SymFlags; if (error(I->getFlags(SymFlags))) break; diff --git a/tools/llvm-objdump/COFFDump.cpp b/tools/llvm-objdump/COFFDump.cpp index 7b60a5d4dcc..dd2db2b037e 100644 --- a/tools/llvm-objdump/COFFDump.cpp +++ b/tools/llvm-objdump/COFFDump.cpp @@ -241,11 +241,7 @@ static void printImportTables(const COFFObjectFile *Obj) { if (I == E) return; outs() << "The Import Tables:\n"; - error_code EC; - for (; I != E; I = I.increment(EC)) { - if (EC) - return; - + for (; I != E; I = ++I) { const import_directory_table_entry *Dir; StringRef Name; if (I->getImportTableEntry(Dir)) return; @@ -294,10 +290,7 @@ static void printExportTable(const COFFObjectFile *Obj) { outs() << " DLL name: " << DllName << "\n"; outs() << " Ordinal base: " << OrdinalBase << "\n"; outs() << " Ordinal RVA Name\n"; - error_code EC; - for (; I != E; I = I.increment(EC)) { - if (EC) - return; + for (; I != E; I = ++I) { uint32_t Ordinal; if (I->getOrdinal(Ordinal)) return; @@ -327,12 +320,8 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) { const coff_section *Pdata = 0; - error_code EC; - for (section_iterator SI = Obj->begin_sections(), - SE = Obj->end_sections(); - SI != SE; SI.increment(EC)) { - if (error(EC)) return; - + for (section_iterator SI = Obj->begin_sections(), SE = Obj->end_sections(); + SI != SE; ++SI) { StringRef Name; if (error(SI->getName(Name))) continue; @@ -342,10 +331,8 @@ void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) { std::vector Rels; for (relocation_iterator RI = SI->begin_relocations(), RE = SI->end_relocations(); - RI != RE; RI.increment(EC)) { - if (error(EC)) break; + RI != RE; ++RI) Rels.push_back(*RI); - } // Sort relocations by address. std::sort(Rels.begin(), Rels.end(), RelocAddressLess); diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 52c786f3055..b8ce9c884a7 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -154,13 +154,14 @@ getSectionsAndSymbols(const MachO::mach_header Header, std::vector &Symbols, SmallVectorImpl &FoundFns, uint64_t &BaseSegmentAddress) { - error_code ec; for (symbol_iterator SI = MachOObj->begin_symbols(), - SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec)) + SE = MachOObj->end_symbols(); + SI != SE; ++SI) Symbols.push_back(*SI); for (section_iterator SI = MachOObj->begin_sections(), - SE = MachOObj->end_sections(); SI != SE; SI.increment(ec)) { + SE = MachOObj->end_sections(); + SI != SE; ++SI) { SectionRef SR = *SI; StringRef SectName; SR.getName(SectName); @@ -270,9 +271,8 @@ static void DisassembleInputMachO2(StringRef Filename, else BaseAddress = BaseSegmentAddress; DiceTable Dices; - error_code ec; for (dice_iterator DI = MachOOF->begin_dices(), DE = MachOOF->end_dices(); - DI != DE; DI.increment(ec)){ + DI != DE; ++DI) { uint32_t Offset; DI->getOffset(Offset); Dices.push_back(std::make_pair(BaseAddress + Offset, *DI)); @@ -329,9 +329,9 @@ static void DisassembleInputMachO2(StringRef Filename, // Parse relocations. std::vector > Relocs; - error_code ec; for (relocation_iterator RI = Sections[SectIdx].begin_relocations(), - RE = Sections[SectIdx].end_relocations(); RI != RE; RI.increment(ec)) { + RE = Sections[SectIdx].end_relocations(); + RI != RE; ++RI) { uint64_t RelocOffset, SectionAddress; RI->getOffset(RelocOffset); Sections[SectIdx].getAddress(SectionAddress); diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 9a56bf9b4c0..325e7006ed8 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -387,18 +387,14 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { error_code EC; std::map > SectionRelocMap; for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections(); - I != E; I.increment(EC)) { - if (error(EC)) - break; + I != E; ++I) { section_iterator Sec2 = I->getRelocatedSection(); if (Sec2 != Obj->end_sections()) SectionRelocMap[*Sec2].push_back(*I); } for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections(); - I != E; I.increment(EC)) { - if (error(EC)) - break; + I != E; ++I) { bool Text; if (error(I->isText(Text))) break; @@ -412,7 +408,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { // Make a list of all the symbols in this section. std::vector > Symbols; for (symbol_iterator SI = Obj->begin_symbols(), SE = Obj->end_symbols(); - SI != SE; SI.increment(EC)) { + SI != SE; ++SI) { bool contains; if (!error(I->containsSymbol(*SI, contains)) && contains) { uint64_t Address; @@ -441,11 +437,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { RelocSec != E; ++RelocSec) { for (relocation_iterator RI = RelocSec->begin_relocations(), RE = RelocSec->end_relocations(); - RI != RE; RI.increment(EC)) { - if (error(EC)) - break; + RI != RE; ++RI) Rels.push_back(*RI); - } } } @@ -559,11 +552,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { } static void PrintRelocations(const ObjectFile *o) { - error_code EC; for (section_iterator si = o->begin_sections(), se = o->end_sections(); - si != se; si.increment(EC)) { - if (error(EC)) - return; + si != se; ++si) { if (si->begin_relocations() == si->end_relocations()) continue; StringRef secname; @@ -571,10 +561,7 @@ static void PrintRelocations(const ObjectFile *o) { outs() << "RELOCATION RECORDS FOR [" << secname << "]:\n"; for (relocation_iterator ri = si->begin_relocations(), re = si->end_relocations(); - ri != re; ri.increment(EC)) { - if (error(EC)) - return; - + ri != re; ++ri) { bool hidden; uint64_t address; SmallString<32> relocname; @@ -593,12 +580,9 @@ static void PrintRelocations(const ObjectFile *o) { static void PrintSectionHeaders(const ObjectFile *o) { outs() << "Sections:\n" "Idx Name Size Address Type\n"; - error_code EC; unsigned i = 0; for (section_iterator si = o->begin_sections(), se = o->end_sections(); - si != se; si.increment(EC)) { - if (error(EC)) - return; + si != se; ++si) { StringRef Name; if (error(si->getName(Name))) return; @@ -621,9 +605,7 @@ static void PrintSectionHeaders(const ObjectFile *o) { static void PrintSectionContents(const ObjectFile *o) { error_code EC; for (section_iterator si = o->begin_sections(), se = o->end_sections(); - si != se; si.increment(EC)) { - if (error(EC)) - return; + si != se; ++si) { StringRef Name; StringRef Contents; uint64_t BaseAddr; @@ -714,11 +696,8 @@ static void PrintSymbolTable(const ObjectFile *o) { if (const COFFObjectFile *coff = dyn_cast(o)) PrintCOFFSymbolTable(coff); else { - error_code EC; for (symbol_iterator si = o->begin_symbols(), se = o->end_symbols(); - si != se; si.increment(EC)) { - if (error(EC)) - return; + si != se; ++si) { StringRef Name; uint64_t Address; SymbolRef::Type Type; diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 803e3f67330..08153ebd047 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -541,23 +541,15 @@ error_code COFFDumper::getSection( } void COFFDumper::cacheRelocations() { - error_code EC; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) - break; - + SecI != SecE; ++SecI) { const coff_section *Section = Obj->getCOFFSection(SecI); for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) - break; - + RelI != RelE; ++RelI) RelocMap[Section].push_back(*RelI); - } // Sort relocations by address. std::sort(RelocMap[Section].begin(), RelocMap[Section].end(), @@ -824,16 +816,11 @@ void COFFDumper::printCodeViewLineTables(section_iterator SecI) { } void COFFDumper::printSections() { - error_code EC; - ListScope SectionsD(W, "Sections"); int SectionNumber = 0; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) - break; - + SecI != SecE; ++SecI) { ++SectionNumber; const coff_section *Section = Obj->getCOFFSection(SecI); @@ -860,20 +847,15 @@ void COFFDumper::printSections() { ListScope D(W, "Relocations"); for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) break; - + RelI != RelE; ++RelI) printRelocation(SecI, RelI); - } } if (opts::SectionSymbols) { ListScope D(W, "Symbols"); for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols(); - SymI != SymE; SymI.increment(EC)) { - if (error(EC)) break; - + SymI != SymE; ++SymI) { bool Contained = false; if (SecI->containsSymbol(*SymI, Contained) || !Contained) continue; @@ -897,15 +879,11 @@ void COFFDumper::printSections() { void COFFDumper::printRelocations() { ListScope D(W, "Relocations"); - error_code EC; int SectionNumber = 0; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { + SecI != SecE; ++SecI) { ++SectionNumber; - if (error(EC)) - break; - StringRef Name; if (error(SecI->getName(Name))) continue; @@ -913,9 +891,7 @@ void COFFDumper::printRelocations() { bool PrintedGroup = false; for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) break; - + RelI != RelE; ++RelI) { if (!PrintedGroup) { W.startLine() << "Section (" << SectionNumber << ") " << Name << " {\n"; W.indent(); @@ -963,14 +939,9 @@ void COFFDumper::printRelocation(section_iterator SecI, void COFFDumper::printSymbols() { ListScope Group(W, "Symbols"); - error_code EC; - for (symbol_iterator SymI = Obj->begin_symbols(), - SymE = Obj->end_symbols(); - SymI != SymE; SymI.increment(EC)) { - if (error(EC)) break; - + for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols(); + SymI != SymE; ++SymI) printSymbol(SymI); - } } void COFFDumper::printDynamicSymbols() { @@ -1116,12 +1087,9 @@ void COFFDumper::printUnwindInfo() { } void COFFDumper::printX64UnwindInfo() { - error_code EC; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) break; - + SecI != SecE; ++SecI) { StringRef Name; if (error(SecI->getName(Name))) continue; diff --git a/tools/llvm-readobj/MachODumper.cpp b/tools/llvm-readobj/MachODumper.cpp index 6626f4082f8..af76901a3f1 100644 --- a/tools/llvm-readobj/MachODumper.cpp +++ b/tools/llvm-readobj/MachODumper.cpp @@ -222,12 +222,9 @@ void MachODumper::printSections(const MachOObjectFile *Obj) { ListScope Group(W, "Sections"); int SectionIndex = -1; - error_code EC; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) break; - + SecI != SecE; ++SecI) { ++SectionIndex; MachOSection Section; @@ -263,20 +260,15 @@ void MachODumper::printSections(const MachOObjectFile *Obj) { ListScope D(W, "Relocations"); for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) break; - + RelI != RelE; ++RelI) printRelocation(SecI, RelI); - } } if (opts::SectionSymbols) { ListScope D(W, "Symbols"); for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols(); - SymI != SymE; SymI.increment(EC)) { - if (error(EC)) break; - + SymI != SymE; ++SymI) { bool Contained = false; if (SecI->containsSymbol(*SymI, Contained) || !Contained) continue; @@ -300,9 +292,7 @@ void MachODumper::printRelocations() { error_code EC; for (section_iterator SecI = Obj->begin_sections(), SecE = Obj->end_sections(); - SecI != SecE; SecI.increment(EC)) { - if (error(EC)) break; - + SecI != SecE; ++SecI) { StringRef Name; if (error(SecI->getName(Name))) continue; @@ -310,9 +300,7 @@ void MachODumper::printRelocations() { bool PrintedGroup = false; for (relocation_iterator RelI = SecI->begin_relocations(), RelE = SecI->end_relocations(); - RelI != RelE; RelI.increment(EC)) { - if (error(EC)) break; - + RelI != RelE; ++RelI) { if (!PrintedGroup) { W.startLine() << "Section " << Name << " {\n"; W.indent(); @@ -382,12 +370,8 @@ void MachODumper::printRelocation(const MachOObjectFile *Obj, void MachODumper::printSymbols() { ListScope Group(W, "Symbols"); - error_code EC; - for (symbol_iterator SymI = Obj->begin_symbols(), - SymE = Obj->end_symbols(); - SymI != SymE; SymI.increment(EC)) { - if (error(EC)) break; - + for (symbol_iterator SymI = Obj->begin_symbols(), SymE = Obj->end_symbols(); + SymI != SymE; ++SymI) { printSymbol(SymI); } } diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index 531595eacdd..65c0ab72553 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -151,11 +151,9 @@ static int printLineInfoForInput() { OwningPtr Context(DIContext::getDWARFContext(LoadedObject->getObjectFile())); // Use symbol info to iterate functions in the object. - error_code ec; for (object::symbol_iterator I = LoadedObject->begin_symbols(), E = LoadedObject->end_symbols(); - I != E && !ec; - I.increment(ec)) { + I != E; ++I) { object::SymbolRef::Type SymType; if (I->getType(SymType)) continue; if (SymType == object::SymbolRef::ST_Function) { diff --git a/tools/llvm-size/llvm-size.cpp b/tools/llvm-size/llvm-size.cpp index ead853e16a7..f46bf6b4a20 100644 --- a/tools/llvm-size/llvm-size.cpp +++ b/tools/llvm-size/llvm-size.cpp @@ -111,12 +111,8 @@ static void PrintObjectSectionSizes(ObjectFile *o) { std::size_t max_name_len = strlen("section"); std::size_t max_size_len = strlen("size"); std::size_t max_addr_len = strlen("addr"); - error_code ec; - for (section_iterator i = o->begin_sections(), - e = o->end_sections(); i != e; - i.increment(ec)) { - if (error(ec)) - return; + for (section_iterator i = o->begin_sections(), e = o->end_sections(); + i != e; ++i) { uint64_t size = 0; if (error(i->getSize(size))) return; @@ -154,12 +150,8 @@ static void PrintObjectSectionSizes(ObjectFile *o) { << "%#" << max_addr_len << radix_fmt << "\n"; // Print each section. - for (section_iterator i = o->begin_sections(), - e = o->end_sections(); i != e; - i.increment(ec)) { - if (error(ec)) - return; - + for (section_iterator i = o->begin_sections(), e = o->end_sections(); + i != e; ++i) { StringRef name; uint64_t size = 0; uint64_t addr = 0; @@ -189,13 +181,8 @@ static void PrintObjectSectionSizes(ObjectFile *o) { uint64_t total_bss = 0; // Make one pass over the section table to calculate sizes. - error_code ec; - for (section_iterator i = o->begin_sections(), - e = o->end_sections(); i != e; - i.increment(ec)) { - if (error(ec)) - return; - + for (section_iterator i = o->begin_sections(), e = o->end_sections(); + i != e; ++i) { uint64_t size = 0; bool isText = false; bool isData = false; diff --git a/tools/llvm-symbolizer/LLVMSymbolize.cpp b/tools/llvm-symbolizer/LLVMSymbolize.cpp index 71588e171fa..40751998579 100644 --- a/tools/llvm-symbolizer/LLVMSymbolize.cpp +++ b/tools/llvm-symbolizer/LLVMSymbolize.cpp @@ -52,11 +52,8 @@ static void patchFunctionNameInDILineInfo(const std::string &NewFunctionName, ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx) : Module(Obj), DebugInfoContext(DICtx) { - error_code ec; for (symbol_iterator si = Module->begin_symbols(), se = Module->end_symbols(); - si != se; si.increment(ec)) { - if (error(ec)) - return; + si != se; ++si) { SymbolRef::Type SymbolType; if (error(si->getType(SymbolType))) continue; @@ -268,9 +265,8 @@ static bool getGNUDebuglinkContents(const Binary *Bin, std::string &DebugName, const ObjectFile *Obj = dyn_cast(Bin); if (!Obj) return false; - error_code EC; for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections(); - I != E; I.increment(EC)) { + I != E; ++I) { StringRef Name; I->getName(Name); Name = Name.substr(Name.find_first_not_of("._")); diff --git a/tools/macho-dump/macho-dump.cpp b/tools/macho-dump/macho-dump.cpp index 4e7a0b875f1..f2f4b8c70f0 100644 --- a/tools/macho-dump/macho-dump.cpp +++ b/tools/macho-dump/macho-dump.cpp @@ -96,9 +96,9 @@ static int DumpSectionData(const MachOObjectFile &Obj, unsigned Index, // Dump the relocation entries. outs() << " ('_relocations', [\n"; unsigned RelNum = 0; - error_code EC; for (relocation_iterator I = Obj.section_rel_begin(Index), - E = Obj.section_rel_end(Index); I != E; I.increment(EC), ++RelNum) { + E = Obj.section_rel_end(Index); + I != E; ++I, ++RelNum) { MachO::any_relocation_info RE = Obj.getRelocation(I->getRawDataRefImpl()); outs() << " # Relocation " << RelNum << "\n"; outs() << " (('word-0', " << format("0x%x", RE.r_word0) << "),\n"; @@ -201,10 +201,9 @@ static int DumpSymtabCommand(const MachOObjectFile &Obj) { // Dump the symbol table. outs() << " ('_symbols', [\n"; - error_code EC; unsigned SymNum = 0; for (symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E; - I.increment(EC), ++SymNum) { + ++I, ++SymNum) { DataRefImpl DRI = I->getRawDataRefImpl(); if (Obj.is64Bit()) { MachO::nlist_64 STE = Obj.getSymbol64TableEntry(DRI); diff --git a/tools/obj2yaml/coff2yaml.cpp b/tools/obj2yaml/coff2yaml.cpp index 02d7ebf7740..47ccfb77000 100644 --- a/tools/obj2yaml/coff2yaml.cpp +++ b/tools/obj2yaml/coff2yaml.cpp @@ -51,10 +51,8 @@ void COFFDumper::dumpHeader(const object::coff_file_header *Header) { void COFFDumper::dumpSections(unsigned NumSections) { std::vector &Sections = YAMLObj.Sections; - error_code ec; for (object::section_iterator iter = Obj.begin_sections(); - iter != Obj.end_sections(); iter.increment(ec)) { - check(ec); + iter != Obj.end_sections(); ++iter) { const object::coff_section *Sect = Obj.getCOFFSection(iter); COFFYAML::Section Sec; Sec.Name = Sect->Name; // FIXME: check the null termination! @@ -68,7 +66,7 @@ void COFFDumper::dumpSections(unsigned NumSections) { std::vector Relocations; for (object::relocation_iterator rIter = iter->begin_relocations(); - rIter != iter->end_relocations(); rIter.increment(ec)) { + rIter != iter->end_relocations(); ++rIter) { const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter); COFFYAML::Relocation Rel; object::symbol_iterator Sym = rIter->getSymbol(); @@ -83,11 +81,9 @@ void COFFDumper::dumpSections(unsigned NumSections) { } void COFFDumper::dumpSymbols(unsigned NumSymbols) { - error_code ec; std::vector &Symbols = YAMLObj.Symbols; for (object::symbol_iterator iter = Obj.begin_symbols(); - iter != Obj.end_symbols(); iter.increment(ec)) { - check(ec); + iter != Obj.end_symbols(); ++iter) { const object::coff_symbol *Symbol = Obj.getCOFFSymbol(iter); COFFYAML::Symbol Sym; Obj.getSymbolName(Symbol, Sym.Name);