summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/IListTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/ADT/IListTest.cpp')
-rw-r--r--llvm/unittests/ADT/IListTest.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/IListTest.cpp b/llvm/unittests/ADT/IListTest.cpp
index 3992a235403..18f6c41a648 100644
--- a/llvm/unittests/ADT/IListTest.cpp
+++ b/llvm/unittests/ADT/IListTest.cpp
@@ -207,6 +207,12 @@ struct NodeWithCallback : ilist_node<NodeWithCallback> {
} // end namespace
namespace llvm {
+// These nodes are stack-allocated for testing purposes, so don't let the ilist
+// own or delete them.
+template <> struct ilist_alloc_traits<NodeWithCallback> {
+ static void deleteNode(NodeWithCallback *) {}
+};
+
template <> struct ilist_callback_traits<NodeWithCallback> {
void addNodeToList(NodeWithCallback *N) { N->IsInList = true; }
void removeNodeFromList(NodeWithCallback *N) { N->IsInList = false; }
@@ -247,6 +253,30 @@ TEST(IListTest, addNodeToList) {
ASSERT_TRUE(N.WasTransferred);
}
+TEST(IListTest, sameListSplice) {
+ NodeWithCallback N1(1);
+ NodeWithCallback N2(2);
+ ASSERT_FALSE(N1.WasTransferred);
+ ASSERT_FALSE(N2.WasTransferred);
+
+ ilist<NodeWithCallback> L1;
+ L1.insert(L1.end(), &N1);
+ L1.insert(L1.end(), &N2);
+ ASSERT_EQ(2u, L1.size());
+ ASSERT_EQ(&N1, &L1.front());
+ ASSERT_FALSE(N1.WasTransferred);
+ ASSERT_FALSE(N2.WasTransferred);
+
+ // Swap the nodes with splice inside the same list. Check that we get the
+ // transfer callback.
+ L1.splice(L1.begin(), L1, std::next(L1.begin()), L1.end());
+ ASSERT_EQ(2u, L1.size());
+ ASSERT_EQ(&N1, &L1.back());
+ ASSERT_EQ(&N2, &L1.front());
+ ASSERT_FALSE(N1.WasTransferred);
+ ASSERT_TRUE(N2.WasTransferred);
+}
+
struct PrivateNode : private ilist_node<PrivateNode> {
friend struct llvm::ilist_detail::NodeAccess;
OpenPOWER on IntegriCloud