[llvm-commits] [llvm] r122081 - in /llvm/trunk: include/llvm/ADT/IntervalMap.h unittests/ADT/IntervalMapTest.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Fri Dec 17 11:18:38 PST 2010
Author: stoklund
Date: Fri Dec 17 13:18:38 2010
New Revision: 122081
URL: http://llvm.org/viewvc/llvm-project?rev=122081&view=rev
Log:
Fix crash when IntervalMapOverlaps::advanceTo moves past the last overlap.
Modified:
llvm/trunk/include/llvm/ADT/IntervalMap.h
llvm/trunk/unittests/ADT/IntervalMapTest.cpp
Modified: llvm/trunk/include/llvm/ADT/IntervalMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/IntervalMap.h?rev=122081&r1=122080&r2=122081&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/IntervalMap.h (original)
+++ llvm/trunk/include/llvm/ADT/IntervalMap.h Fri Dec 17 13:18:38 2010
@@ -2036,6 +2036,8 @@
/// either meets end.
/// Don't move the iterators if they are already overlapping.
void advance() {
+ if (!valid())
+ return;
for (;;) {
// Make a.end > b.start.
posA.advanceTo(posB.start());
@@ -2052,10 +2054,7 @@
/// IntervalMapOverlaps - Create an iterator for the overlaps of a and b.
IntervalMapOverlaps(const MapA &a, const MapB &b)
: posA(b.empty() ? a.end() : a.find(b.start())),
- posB(posA.valid() ? b.find(posA.start()) : b.end()) {
- if (valid())
- advance();
- }
+ posB(posA.valid() ? b.find(posA.start()) : b.end()) { advance(); }
/// valid - Return true if iterator is at an overlap.
bool valid() const {
@@ -2090,7 +2089,7 @@
// Second half-loop of advance().
posB.advanceTo(posA.start());
if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
- return ;
+ return;
advance();
}
@@ -2098,7 +2097,7 @@
void skipB() {
++posB;
if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
- return;
+ return;
advance();
}
Modified: llvm/trunk/unittests/ADT/IntervalMapTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/IntervalMapTest.cpp?rev=122081&r1=122080&r2=122081&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/IntervalMapTest.cpp (original)
+++ llvm/trunk/unittests/ADT/IntervalMapTest.cpp Fri Dec 17 13:18:38 2010
@@ -586,7 +586,11 @@
ASSERT_TRUE(BA.valid());
EXPECT_EQ(3u, BA.a().start());
EXPECT_EQ(4u, BA.b().start());
- ++BA;
+ // advance past end.
+ BA.advanceTo(6);
+ EXPECT_FALSE(BA.valid());
+ // advance an invalid iterator.
+ BA.advanceTo(7);
EXPECT_FALSE(BA.valid());
}
More information about the llvm-commits
mailing list