[PATCH] D17529: ELF: Implement ICF.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 26 06:21:03 PST 2016


grimar added a comment.

Problem is in

  template <class ELFT>
  void ICF<ELFT>::forEachGroup(std::vector<InputSection<ELFT> *> &V,
                               Comparator Eq) {
    for (auto I = V.begin(), E = V.end(); I != E;) {
      InputSection<ELFT> *Head = *I;
      auto Bound = std::find_if(I + 1, E, [&](InputSection<ELFT> *S) {
        return S->GroupId != Head->GroupId;
      });
      segregate(&*I, &*Bound, Eq);
      I = Bound;
    }
  }

Bound == V.end() and that crashes at

  segregate(&*I, &*Bound, Eq);

Have next values for V:
+		[0]	0x0096f698 {RelocSections={Val={Val={Value=0x00000000 } } } OutSecOff=0x0000000000000000 GroupId=0x8000000055626995 }
+		[1]	0x0096f6c8 {RelocSections={Val={Val={Value=0x00000000 } } } OutSecOff=0x0000000000000000 GroupId=0x8000000055626995 }
+		[2]	0x0096f668 {RelocSections={Val={Val={Value=0x00000000 } } } OutSecOff=0x0000000000000000 GroupId=0x80000000af442220 }
Head->GroupId == 	0x8000000055626995

at first iteration it sets I to V[2]. Then on next one finds nothing, because I + 1 is already == E.
If I add next after "auto Bound ="

  if (Bound == V.end())
    return;

all tests pass for me.


http://reviews.llvm.org/D17529





More information about the llvm-commits mailing list