summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/PointerEmbeddedIntTest.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2016-02-18 21:00:08 +0000
committerJordan Rose <jordan_rose@apple.com>2016-02-18 21:00:08 +0000
commit3c81d6240b95decab635819959b36fa5b6d0079e (patch)
tree5e62f5d7f78071e70e8eecdc20a306bcae8fd3ff /llvm/unittests/ADT/PointerEmbeddedIntTest.cpp
parentb6c6dda439566ed8da56ca6684aefddb5474785e (diff)
downloadbcm5719-llvm-3c81d6240b95decab635819959b36fa5b6d0079e.tar.gz
bcm5719-llvm-3c81d6240b95decab635819959b36fa5b6d0079e.zip
[ADT] Fix PointerEmbeddedInt when the underlying type is uintptr_t.
...and when you try to store negative values in it. llvm-svn: 261259
Diffstat (limited to 'llvm/unittests/ADT/PointerEmbeddedIntTest.cpp')
-rw-r--r--llvm/unittests/ADT/PointerEmbeddedIntTest.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/PointerEmbeddedIntTest.cpp b/llvm/unittests/ADT/PointerEmbeddedIntTest.cpp
index b10365a2f61..9c27f8ee655 100644
--- a/llvm/unittests/ADT/PointerEmbeddedIntTest.cpp
+++ b/llvm/unittests/ADT/PointerEmbeddedIntTest.cpp
@@ -43,4 +43,38 @@ TEST(PointerEmbeddedIntTest, Basic) {
EXPECT_FALSE(42 >= J);
}
+TEST(PointerEmbeddedIntTest, intptr_t) {
+ PointerEmbeddedInt<intptr_t, CHAR_BIT> IPos = 42, INeg = -42;
+ EXPECT_EQ(42, IPos);
+ EXPECT_EQ(-42, INeg);
+
+ PointerEmbeddedInt<uintptr_t, CHAR_BIT> U = 42, USaturated = 255;
+ EXPECT_EQ(42U, U);
+ EXPECT_EQ(255U, USaturated);
+
+ PointerEmbeddedInt<intptr_t, std::numeric_limits<intptr_t>::digits>
+ IMax = std::numeric_limits<intptr_t>::max() >> 1,
+ IMin = std::numeric_limits<intptr_t>::min() >> 1;
+ EXPECT_EQ(std::numeric_limits<intptr_t>::max() >> 1, IMax);
+ EXPECT_EQ(std::numeric_limits<intptr_t>::min() >> 1, IMin);
+
+ PointerEmbeddedInt<uintptr_t, std::numeric_limits<uintptr_t>::digits - 1>
+ UMax = std::numeric_limits<uintptr_t>::max() >> 1,
+ UMin = std::numeric_limits<uintptr_t>::min() >> 1;
+ EXPECT_EQ(std::numeric_limits<uintptr_t>::max() >> 1, UMax);
+ EXPECT_EQ(std::numeric_limits<uintptr_t>::min() >> 1, UMin);
+}
+
+TEST(PointerEmbeddedIntTest, PointerLikeTypeTraits) {
+ PointerEmbeddedInt<int, CHAR_BIT> I = 42;
+ using ITraits = PointerLikeTypeTraits<decltype(I)>;
+ EXPECT_EQ(42, ITraits::getFromVoidPointer(ITraits::getAsVoidPointer(I)));
+
+ PointerEmbeddedInt<uintptr_t, std::numeric_limits<uintptr_t>::digits - 1>
+ Max = std::numeric_limits<uintptr_t>::max() >> 1;
+ using MaxTraits = PointerLikeTypeTraits<decltype(Max)>;
+ EXPECT_EQ(std::numeric_limits<uintptr_t>::max() >> 1,
+ MaxTraits::getFromVoidPointer(MaxTraits::getAsVoidPointer(Max)));
+}
+
} // end anonymous namespace
OpenPOWER on IntegriCloud