[lld] r212035 - MachO: stop iterating past the end of an array

Tim Northover tnorthover at apple.com
Mon Jun 30 03:30:00 PDT 2014


Author: tnorthover
Date: Mon Jun 30 05:30:00 2014
New Revision: 212035

URL: http://llvm.org/viewvc/llvm-project?rev=212035&view=rev
Log:
MachO: stop iterating past the end of an array

When trying to map atom types to sections, we were iterating through an array
until we hit a sentinel value. There's no need for such dances when range-based
for loops are available.

Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
    lld/trunk/test/mach-o/write-final-sections.yaml

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=212035&r1=212034&r2=212035&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Mon Jun 30 05:30:00 2014
@@ -227,9 +227,8 @@ const MachOFinalSectionFromAtomType sect
 
 
 SectionInfo *Util::getFinalSection(DefinedAtom::ContentType atomType) {
-  for (const MachOFinalSectionFromAtomType *p = sectsToAtomType ;
-                                 p->atomType != DefinedAtom::typeUnknown; ++p) {
-    if (p->atomType != atomType)
+  for (auto &p : sectsToAtomType) {
+    if (p.atomType != atomType)
       continue;
     SectionAttr sectionAttrs = 0;
     switch (atomType) {
@@ -243,15 +242,15 @@ SectionInfo *Util::getFinalSection(Defin
     // If we already have a SectionInfo with this name, re-use it.
     // This can happen if two ContentType map to the same mach-o section.
     for (auto sect : _sectionMap) {
-      if (sect.second->sectionName.equals(p->sectionName) &&
-          sect.second->segmentName.equals(p->segmentName)) {
+      if (sect.second->sectionName.equals(p.sectionName) &&
+          sect.second->segmentName.equals(p.segmentName)) {
         return sect.second;
       }
     }
     // Otherwise allocate new SectionInfo object.
-    SectionInfo *sect = new (_allocator) SectionInfo(p->segmentName, 
-                                                     p->sectionName, 
-                                                     p->sectionType, 
+    SectionInfo *sect = new (_allocator) SectionInfo(p.segmentName,
+                                                     p.sectionName,
+                                                     p.sectionType,
                                                      sectionAttrs);
     _sectionInfos.push_back(sect);
     _sectionMap[atomType] = sect;

Modified: lld/trunk/test/mach-o/write-final-sections.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/write-final-sections.yaml?rev=212035&r1=212034&r2=212035&view=diff
==============================================================================
--- lld/trunk/test/mach-o/write-final-sections.yaml (original)
+++ lld/trunk/test/mach-o/write-final-sections.yaml Mon Jun 30 05:30:00 2014
@@ -7,15 +7,10 @@ defined-atoms:
   - name:            _foo
     scope:           global
     content:         [ 55 ]
-# More for __TEXT, __text (with typeResolver)
-  - name:            _resolver
-    scope:           global
-    type:            resolver
-    content:         [ C3 ]
 # CHECK: Name: __text
 # CHECK: Segment: __TEXT
 # CHECK: SectionData (
-# CHECK-NEXT: 0000: 55C3
+# CHECK-NEXT: 0000: 55
 # CHECK-NEXT: )
 
 #  For __TEXT, __const (with typeConstant),





More information about the llvm-commits mailing list