diff --git a/llvm/include/llvm/ADT/IntervalMap.h b/llvm/include/llvm/ADT/IntervalMap.h --- a/llvm/include/llvm/ADT/IntervalMap.h +++ b/llvm/include/llvm/ADT/IntervalMap.h @@ -1046,6 +1046,13 @@ new(&rootLeaf()) RootLeaf(); } + IntervalMap(IntervalMap &&other) + : IntervalMap(other.allocator) { + std::swap(data, other.data); + std::swap(height, other.height); + std::swap(rootSize, other.rootSize); + } + ~IntervalMap() { clear(); rootLeaf().~RootLeaf(); diff --git a/llvm/unittests/ADT/IntervalMapTest.cpp b/llvm/unittests/ADT/IntervalMapTest.cpp --- a/llvm/unittests/ADT/IntervalMapTest.cpp +++ b/llvm/unittests/ADT/IntervalMapTest.cpp @@ -664,6 +664,48 @@ EXPECT_FALSE(map.overlaps(66, 67)); } +TEST(IntervalMapTest, MoveEmpty) { + UUMap::Allocator allocator; + UUMap map(allocator); + UUMap map2(std::move(map)); + EXPECT_TRUE(map2.empty()); +} + +TEST(IntervalMapTest, MoveSingleEntry) { + UUMap::Allocator allocator; + UUMap map(allocator); + map.insert(10, 20, 0); + UUMap map2(std::move(map)); + + UUMap::iterator I = map2.begin(); + ASSERT_TRUE(I.valid()); + EXPECT_EQ(10u, I.start()); + EXPECT_EQ(20u, I.stop()); + EXPECT_EQ(0u, I.value()); + ++I; + EXPECT_FALSE(I.valid()); +} + +TEST(IntervalMapTest, MoveLargeMap) { + UUMap::Allocator allocator; + UUMap map(allocator); + for (unsigned i = 0; i < 500; i += 20) { + map.insert(i, i + 10, 0); + } + UUMap map2(std::move(map)); + + UUMap::iterator I = map2.begin(); + for (unsigned i = 0; i < 500; i += 20) { + ASSERT_TRUE(I.valid()); + EXPECT_EQ(i, I.start()); + EXPECT_EQ(i + 10, I.stop()); + EXPECT_EQ(0u, I.value()); + ++I; + } + + EXPECT_FALSE(I.valid()); +} + TEST(IntervalMapOverlapsTest, SmallMaps) { typedef IntervalMapOverlaps UUOverlaps; UUMap::Allocator allocator;