[llvm] r297182 - Add unit tests for changes to SmallPtrSet and PointerLikeTypeTraits
Daniel Berlin via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 7 10:47:52 PST 2017
Author: dannyb
Date: Tue Mar 7 12:47:52 2017
New Revision: 297182
URL: http://llvm.org/viewvc/llvm-project?rev=297182&view=rev
Log:
Add unit tests for changes to SmallPtrSet and PointerLikeTypeTraits
Modified:
llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp
Modified: llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp?rev=297182&r1=297181&r2=297182&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp (original)
+++ llvm/trunk/unittests/ADT/SmallPtrSetTest.cpp Tue Mar 7 12:47:52 2017
@@ -12,7 +12,9 @@
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
+#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Support/PointerLikeTypeTraits.h"
using namespace llvm;
@@ -279,3 +281,34 @@ TEST(SmallPtrSetTest, EraseTest) {
SmallPtrSet<int *, 2> A;
checkEraseAndIterators(A);
}
+
+// Verify that const pointers work for count and find even when the underlying
+// SmallPtrSet is not for a const pointer type.
+TEST(SmallPtrSetTest, ConstTest) {
+ SmallPtrSet<int *, 8> IntSet;
+ int A;
+ int *B = &A;
+ const int *C = &A;
+ IntSet.insert(B);
+ EXPECT_EQ(IntSet.count(B), 1u);
+ EXPECT_EQ(IntSet.count(C), 1u);
+ // FIXME: We can't unit test find right now because ABI_BREAKING_CHECKS breaks
+ // find().
+ // EXPECT_NE(IntSet.find(B), IntSet.end());
+ // EXPECT_NE(IntSet.find(C), IntSet.end());
+}
+
+// Verify that we automatically get the const version of PointerLikeTypeTraits
+// filled in for us, even for a non-pointer type
+using TestPair = PointerIntPair<int *, 1>;
+
+TEST(SmallPtrSetTest, ConstNonPtrTest) {
+ SmallPtrSet<TestPair, 8> IntSet;
+ int A[1];
+ TestPair Pair(&A[0], 1);
+ IntSet.insert(Pair);
+ EXPECT_EQ(IntSet.count(Pair), 1u);
+ // FIXME: We can't unit test find right now because ABI_BREAKING_CHECKS breaks
+ // find().
+ // EXPECT_NE(IntSet.find(Pair), IntSet.end());
+}
More information about the llvm-commits
mailing list