llvm.org GIT mirror llvm / 4aec85a
Fix crash when IntervalMapOverlaps::advanceTo moves past the last overlap. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122081 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 9 years ago
2 changed file(s) with 10 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
20352035 /// either meets end.
20362036 /// Don't move the iterators if they are already overlapping.
20372037 void advance() {
2038 if (!valid())
2039 return;
20382040 for (;;) {
20392041 // Make a.end > b.start.
20402042 posA.advanceTo(posB.start());
20512053 /// IntervalMapOverlaps - Create an iterator for the overlaps of a and b.
20522054 IntervalMapOverlaps(const MapA &a, const MapB &b)
20532055 : posA(b.empty() ? a.end() : a.find(b.start())),
2054 posB(posA.valid() ? b.find(posA.start()) : b.end()) {
2055 if (valid())
2056 advance();
2057 }
2056 posB(posA.valid() ? b.find(posA.start()) : b.end()) { advance(); }
20582057
20592058 /// valid - Return true if iterator is at an overlap.
20602059 bool valid() const {
20892088 // Second half-loop of advance().
20902089 posB.advanceTo(posA.start());
20912090 if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
2092 return ;
2091 return;
20932092 advance();
20942093 }
20952094
20972096 void skipB() {
20982097 ++posB;
20992098 if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
2100 return;
2099 return;
21012100 advance();
21022101 }
21032102
585585 ASSERT_TRUE(BA.valid());
586586 EXPECT_EQ(3u, BA.a().start());
587587 EXPECT_EQ(4u, BA.b().start());
588 ++BA;
588 // advance past end.
589 BA.advanceTo(6);
590 EXPECT_FALSE(BA.valid());
591 // advance an invalid iterator.
592 BA.advanceTo(7);
589593 EXPECT_FALSE(BA.valid());
590594 }
591595