[llvm] r200442 - Simplify the handling of iterators in ObjectFile.

Rafael Espindola rafael.espindola at gmail.com
Wed Jan 29 18:49:51 PST 2014


Author: rafael
Date: Wed Jan 29 20:49:50 2014
New Revision: 200442

URL: http://llvm.org/viewvc/llvm-project?rev=200442&view=rev
Log:
Simplify the handling of iterators in ObjectFile.

None of the object file formats reported error on iterator increment. In
retrospect, that is not too surprising: no object format stores symbols or
sections in a linked list or other structure that requires chasing pointers.
As a consequence, all error checking can be done on begin() and end().

This reduces the text segment of bin/llvm-readobj in my machine from 521233 to
518526 bytes.

Modified:
    llvm/trunk/include/llvm/Object/COFF.h
    llvm/trunk/include/llvm/Object/ELFObjectFile.h
    llvm/trunk/include/llvm/Object/MachO.h
    llvm/trunk/include/llvm/Object/ObjectFile.h
    llvm/trunk/lib/DebugInfo/DWARFContext.cpp
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
    llvm/trunk/lib/MC/MCObjectDisassembler.cpp
    llvm/trunk/lib/MC/MCObjectSymbolizer.cpp
    llvm/trunk/lib/Object/COFFObjectFile.cpp
    llvm/trunk/lib/Object/MachOObjectFile.cpp
    llvm/trunk/lib/Object/Object.cpp
    llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp
    llvm/trunk/tools/llvm-ar/llvm-ar.cpp
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp
    llvm/trunk/tools/llvm-objdump/COFFDump.cpp
    llvm/trunk/tools/llvm-objdump/MachODump.cpp
    llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
    llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
    llvm/trunk/tools/llvm-readobj/MachODumper.cpp
    llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
    llvm/trunk/tools/llvm-size/llvm-size.cpp
    llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp
    llvm/trunk/tools/macho-dump/macho-dump.cpp
    llvm/trunk/tools/obj2yaml/coff2yaml.cpp

Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Wed Jan 29 20:49:50 2014
@@ -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;

Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Wed Jan 29 20:49:50 2014
@@ -55,8 +55,7 @@ public:
 protected:
   ELFFile<ELFT> 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<ELFType<support::b
 typedef ELFObjectFile<ELFType<support::big, 2, true> > ELF64BEObjectFile;
 
 template <class ELFT>
-error_code ELFObjectFile<ELFT>::getSymbolNext(DataRefImpl Symb,
-                                              SymbolRef &Result) const {
-  Result = SymbolRef(toDRI(++toELFSymIter(Symb)), this);
-  return object_error::success;
+void ELFObjectFile<ELFT>::moveSymbolNext(DataRefImpl &Symb) const {
+  Symb = toDRI(++toELFSymIter(Symb));
 }
 
 template <class ELFT>
@@ -439,10 +434,8 @@ error_code ELFObjectFile<ELFT>::getSymbo
 }
 
 template <class ELFT>
-error_code ELFObjectFile<ELFT>::getSectionNext(DataRefImpl Sec,
-                                               SectionRef &Result) const {
-  Result = SectionRef(toDRI(++toELFShdrIter(Sec)), this);
-  return object_error::success;
+void ELFObjectFile<ELFT>::moveSectionNext(DataRefImpl &Sec) const {
+  Sec = toDRI(++toELFShdrIter(Sec));
 }
 
 template <class ELFT>
@@ -594,11 +587,8 @@ ELFObjectFile<ELFT>::getRelocatedSection
 
 // Relocations
 template <class ELFT>
-error_code ELFObjectFile<ELFT>::getRelocationNext(DataRefImpl Rel,
-                                                  RelocationRef &Result) const {
+void ELFObjectFile<ELFT>::moveRelocationNext(DataRefImpl &Rel) const {
   ++Rel.d.b;
-  Result = RelocationRef(Rel, this);
-  return object_error::success;
 }
 
 template <class ELFT>

Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Wed Jan 29 20:49:50 2014
@@ -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 Dic
   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<const MachO::data_in_code_entry *>(Rel.p);
-  Rel.p = reinterpret_cast<uintptr_t>(P + 1);
-  Result = DiceRef(Rel, OwningObject);
-  return object_error::success;
+    reinterpret_cast<const MachO::data_in_code_entry *>(DicePimpl.p);
+  DicePimpl.p = reinterpret_cast<uintptr_t>(P + 1);
 }
 
 // Since a Mach-O data in code reference, a DiceRef, can only be created when

Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Wed Jan 29 20:49:50 2014
@@ -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 S
   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
   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==(co
   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 {

Modified: llvm/trunk/lib/DebugInfo/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFContext.cpp Wed Jan 29 20:49:50 2014
@@ -603,10 +603,9 @@ static bool consumeCompressedDebugSectio
 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::DWARFContextInMemo
       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;

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Wed Jan 29 20:49:50 2014
@@ -115,12 +115,10 @@ ObjectImage *RuntimeDyldImpl::loadObject
   // 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
 
   // 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(Ob
 
   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;
       }
     }

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp Wed Jan 29 20:49:50 2014
@@ -621,10 +621,8 @@ void RuntimeDyldELF::findOPDEntrySection
                                          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
 
     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
       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;

Modified: llvm/trunk/lib/MC/MCObjectDisassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectDisassembler.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectDisassembler.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectDisassembler.cpp Wed Jan 29 20:49:50 2014
@@ -37,11 +37,8 @@ MCObjectDisassembler::MCObjectDisassembl
     : 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::buildMod
 }
 
 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(MCMo
   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::MCMachOObject
     : 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.

Modified: llvm/trunk/lib/MC/MCObjectSymbolizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectSymbolizer.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectSymbolizer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectSymbolizer.cpp Wed Jan 29 20:49:50 2014
@@ -52,10 +52,8 @@ MCMachObjectSymbolizer(MCContext &Ctx, O
     : 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::findEx
 
   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
     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:
 }
 
 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::buildSectionLis
 }
 
 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::buildRelocation
       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

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Wed Jan 29 20:49:50 2014
@@ -87,13 +87,10 @@ const coff_section *COFFObjectFile::toSe
   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<uintptr_t>(Symb);
-  Result = SymbolRef(Ref, this);
-  return object_error::success;
 }
 
 error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
@@ -221,13 +218,10 @@ error_code COFFObjectFile::getSymbolValu
   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<uintptr_t>(Sec);
-  Result = SectionRef(Ref, this);
-  return object_error::success;
 }
 
 error_code COFFObjectFile::getSectionName(DataRefImpl Ref,
@@ -386,11 +380,8 @@ error_code COFFObjectFile::initSymbolTab
 
 // 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::t
   return reinterpret_cast<const coff_relocation*>(Rel.p);
 }
 
-error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel,
-                                             RelocationRef &Res) const {
+void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
   Rel.p = reinterpret_cast<uintptr_t>(
             reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
-  Res = RelocationRef(Rel, this);
-  return object_error::success;
 }
 
 error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
@@ -932,10 +920,8 @@ operator==(const ImportDirectoryEntryRef
   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
   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

Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Wed Jan 29 20:49:50 2014
@@ -275,18 +275,9 @@ static StringRef parseSegmentOrSectionNa
 
 // Helper to advance a section or symbol iterator multiple increments at a time.
 template<class T>
-static error_code advance(T &it, size_t Val) {
-  error_code ec;
-  while (Val--) {
-    it.increment(ec);
-  }
-  return ec;
-}
-
-template<class T>
-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(co
   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(co
     // 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(co
 
   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(MemoryB
   }
 }
 
-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::getSymbolSiz
   }
   // 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::getSymbolVal
   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(DataRef
   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<const MachO::any_relocation_info *>(Rel.p);
   Rel.p = reinterpret_cast<uintptr_t>(P + 1);
-  Res = RelocationRef(Rel, this);
-  return object_error::success;
 }
 
 error_code

Modified: llvm/trunk/lib/Object/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Object.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Object.cpp (original)
+++ llvm/trunk/lib/Object/Object.cpp Wed Jan 29 20:49:50 2014
@@ -84,9 +84,7 @@ LLVMBool LLVMIsSectionIteratorAtEnd(LLVM
 }
 
 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(LLVMO
 }
 
 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(L
 }
 
 void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
-  error_code ec;
-  unwrap(SI)->increment(ec);
-  if (ec) report_fatal_error("LLVMMoveToNextRelocation failed: " +
-                             ec.message());
+  ++(*unwrap(SI));
 }
 
 

Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachORelocationInfo.cpp Wed Jan 29 20:49:50 2014
@@ -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;

Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Wed Jan 29 20:49:50 2014
@@ -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)

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Wed Jan 29 20:49:50 2014
@@ -532,16 +532,13 @@ static char getNMTypeChar(ObjectFile *Ob
 }
 
 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;

Modified: llvm/trunk/tools/llvm-objdump/COFFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/COFFDump.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/COFFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp Wed Jan 29 20:49:50 2014
@@ -241,11 +241,7 @@ static void printImportTables(const COFF
   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 COFFO
   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 COF
 
   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 COF
     std::vector<RelocationRef> 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);

Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Wed Jan 29 20:49:50 2014
@@ -154,13 +154,14 @@ getSectionsAndSymbols(const MachO::mach_
                       std::vector<SymbolRef> &Symbols,
                       SmallVectorImpl<uint64_t> &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(Strin
   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(Strin
 
     // Parse relocations.
     std::vector<std::pair<uint64_t, SymbolRef> > 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);

Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Jan 29 20:49:50 2014
@@ -387,18 +387,14 @@ static void DisassembleObject(const Obje
   error_code EC;
   std::map<SectionRef, SmallVector<SectionRef, 1> > 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 Obje
     // Make a list of all the symbols in this section.
     std::vector<std::pair<uint64_t, StringRef> > 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 Obje
            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 Obje
 }
 
 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 Objec
     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 Objec
 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 Ob
 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 Objec
   if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(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;

Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Wed Jan 29 20:49:50 2014
@@ -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
 }
 
 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
 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;

Modified: llvm/trunk/tools/llvm-readobj/MachODumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/MachODumper.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/MachODumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/MachODumper.cpp Wed Jan 29 20:49:50 2014
@@ -222,12 +222,9 @@ void MachODumper::printSections(const Ma
   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 Ma
       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
 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);
   }
 }

Modified: llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp (original)
+++ llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp Wed Jan 29 20:49:50 2014
@@ -151,11 +151,9 @@ static int printLineInfoForInput() {
     OwningPtr<DIContext> 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) {

Modified: llvm/trunk/tools/llvm-size/llvm-size.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-size/llvm-size.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-size/llvm-size.cpp (original)
+++ llvm/trunk/tools/llvm-size/llvm-size.cpp Wed Jan 29 20:49:50 2014
@@ -111,12 +111,8 @@ static void PrintObjectSectionSizes(Obje
     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(Obje
         << "%#" << 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(Obje
     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;

Modified: llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp (original)
+++ llvm/trunk/tools/llvm-symbolizer/LLVMSymbolize.cpp Wed Jan 29 20:49:50 2014
@@ -52,11 +52,8 @@ static void patchFunctionNameInDILineInf
 
 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(cons
   const ObjectFile *Obj = dyn_cast<ObjectFile>(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("._"));

Modified: llvm/trunk/tools/macho-dump/macho-dump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/macho-dump/macho-dump.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/macho-dump/macho-dump.cpp (original)
+++ llvm/trunk/tools/macho-dump/macho-dump.cpp Wed Jan 29 20:49:50 2014
@@ -96,9 +96,9 @@ static int DumpSectionData(const MachOOb
   // 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 MachO
 
   // 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);

Modified: llvm/trunk/tools/obj2yaml/coff2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/coff2yaml.cpp?rev=200442&r1=200441&r2=200442&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/coff2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/coff2yaml.cpp Wed Jan 29 20:49:50 2014
@@ -51,10 +51,8 @@ void COFFDumper::dumpHeader(const object
 
 void COFFDumper::dumpSections(unsigned NumSections) {
   std::vector<COFFYAML::Section> &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 N
 
     std::vector<COFFYAML::Relocation> 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 N
 }
 
 void COFFDumper::dumpSymbols(unsigned NumSymbols) {
-  error_code ec;
   std::vector<COFFYAML::Symbol> &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);





More information about the llvm-commits mailing list