[Thumb1] AND with a constant operand can be converted into BIC
[llvm-core.git] / unittests / ADT / PointerEmbeddedIntTest.cpp
blob9c27f8ee655fd814e75f0cef17e07d3b341195c1
1 //===- llvm/unittest/ADT/PointerEmbeddedIntTest.cpp -----------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/PointerEmbeddedInt.h"
12 using namespace llvm;
14 namespace {
16 TEST(PointerEmbeddedIntTest, Basic) {
17 PointerEmbeddedInt<int, CHAR_BIT> I = 42, J = 43;
19 EXPECT_EQ(42, I);
20 EXPECT_EQ(43, I + 1);
21 EXPECT_EQ(sizeof(uintptr_t) * CHAR_BIT - CHAR_BIT,
22 PointerLikeTypeTraits<decltype(I)>::NumLowBitsAvailable);
24 EXPECT_FALSE(I == J);
25 EXPECT_TRUE(I != J);
26 EXPECT_TRUE(I < J);
27 EXPECT_FALSE(I > J);
28 EXPECT_TRUE(I <= J);
29 EXPECT_FALSE(I >= J);
31 EXPECT_FALSE(I == 43);
32 EXPECT_TRUE(I != 43);
33 EXPECT_TRUE(I < 43);
34 EXPECT_FALSE(I > 43);
35 EXPECT_TRUE(I <= 43);
36 EXPECT_FALSE(I >= 43);
38 EXPECT_FALSE(42 == J);
39 EXPECT_TRUE(42 != J);
40 EXPECT_TRUE(42 < J);
41 EXPECT_FALSE(42 > J);
42 EXPECT_TRUE(42 <= J);
43 EXPECT_FALSE(42 >= J);
46 TEST(PointerEmbeddedIntTest, intptr_t) {
47 PointerEmbeddedInt<intptr_t, CHAR_BIT> IPos = 42, INeg = -42;
48 EXPECT_EQ(42, IPos);
49 EXPECT_EQ(-42, INeg);
51 PointerEmbeddedInt<uintptr_t, CHAR_BIT> U = 42, USaturated = 255;
52 EXPECT_EQ(42U, U);
53 EXPECT_EQ(255U, USaturated);
55 PointerEmbeddedInt<intptr_t, std::numeric_limits<intptr_t>::digits>
56 IMax = std::numeric_limits<intptr_t>::max() >> 1,
57 IMin = std::numeric_limits<intptr_t>::min() >> 1;
58 EXPECT_EQ(std::numeric_limits<intptr_t>::max() >> 1, IMax);
59 EXPECT_EQ(std::numeric_limits<intptr_t>::min() >> 1, IMin);
61 PointerEmbeddedInt<uintptr_t, std::numeric_limits<uintptr_t>::digits - 1>
62 UMax = std::numeric_limits<uintptr_t>::max() >> 1,
63 UMin = std::numeric_limits<uintptr_t>::min() >> 1;
64 EXPECT_EQ(std::numeric_limits<uintptr_t>::max() >> 1, UMax);
65 EXPECT_EQ(std::numeric_limits<uintptr_t>::min() >> 1, UMin);
68 TEST(PointerEmbeddedIntTest, PointerLikeTypeTraits) {
69 PointerEmbeddedInt<int, CHAR_BIT> I = 42;
70 using ITraits = PointerLikeTypeTraits<decltype(I)>;
71 EXPECT_EQ(42, ITraits::getFromVoidPointer(ITraits::getAsVoidPointer(I)));
73 PointerEmbeddedInt<uintptr_t, std::numeric_limits<uintptr_t>::digits - 1>
74 Max = std::numeric_limits<uintptr_t>::max() >> 1;
75 using MaxTraits = PointerLikeTypeTraits<decltype(Max)>;
76 EXPECT_EQ(std::numeric_limits<uintptr_t>::max() >> 1,
77 MaxTraits::getFromVoidPointer(MaxTraits::getAsVoidPointer(Max)));
80 } // end anonymous namespace