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.

llvm-svn: 200442
diff --git a/llvm/tools/llvm-objdump/COFFDump.cpp b/llvm/tools/llvm-objdump/COFFDump.cpp
index 7b60a5d..dd2db2b 100644
--- a/llvm/tools/llvm-objdump/COFFDump.cpp
+++ b/llvm/tools/llvm-objdump/COFFDump.cpp
@@ -241,11 +241,7 @@
   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 @@
   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 @@
 
   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 @@
     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);
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index 52c786f..b8ce9c8 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -154,13 +154,14 @@
                       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 @@
   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 @@
 
     // 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);
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 9a56bf9..325e700 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -387,18 +387,14 @@
   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 @@
     // 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 @@
            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 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 @@
     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 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 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 @@
   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;