diff --git a/include/llvm/ADT/ilist_node.h b/include/llvm/ADT/ilist_node.h index 84208b0841b..7244d0f4058 100644 --- a/include/llvm/ADT/ilist_node.h +++ b/include/llvm/ADT/ilist_node.h @@ -80,6 +80,12 @@ private: public: self_iterator getIterator() { return self_iterator(*this); } const_self_iterator getIterator() const { return const_self_iterator(*this); } + reverse_self_iterator getReverseIterator() { + return reverse_self_iterator(*this); + } + const_reverse_self_iterator getReverseIterator() const { + return const_reverse_self_iterator(*this); + } // Under-approximation, but always available for assertions. using node_base_type::isKnownSentinel; diff --git a/unittests/ADT/SimpleIListTest.cpp b/unittests/ADT/SimpleIListTest.cpp index 5a3834822d6..a354f332006 100644 --- a/unittests/ADT/SimpleIListTest.cpp +++ b/unittests/ADT/SimpleIListTest.cpp @@ -178,6 +178,23 @@ TEST(SimpleIListTest, erase) { EXPECT_EQ(2u, L.size()); } +TEST(SimpleIListTest, reverse_iterator) { + simple_ilist L; + Node A, B, C; + L.push_back(A); + L.push_back(B); + L.push_back(C); + + auto ReverseIter = L.rbegin(); + EXPECT_EQ(C.getReverseIterator(), ReverseIter); + ++ReverseIter; + EXPECT_EQ(B.getReverseIterator(), ReverseIter); + ++ReverseIter; + EXPECT_EQ(A.getReverseIterator(), ReverseIter); + ++ReverseIter; + EXPECT_EQ(L.rend(), ReverseIter); +} + TEST(SimpleIListTest, eraseAndDispose) { simple_ilist L; Node A, C;