aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/ADT
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ADT')
-rw-r--r--unittests/ADT/APFloatTest.cpp164
-rw-r--r--unittests/ADT/APIntTest.cpp25
-rw-r--r--unittests/ADT/ArrayRefTest.cpp53
-rw-r--r--unittests/ADT/CMakeLists.txt2
-rw-r--r--unittests/ADT/DenseMapTest.cpp5
-rw-r--r--unittests/ADT/DenseSetTest.cpp38
-rw-r--r--unittests/ADT/FunctionRefTest.cpp28
-rw-r--r--unittests/ADT/MapVectorTest.cpp69
-rw-r--r--unittests/ADT/OptionalTest.cpp99
-rw-r--r--unittests/ADT/PostOrderIteratorTest.cpp37
-rw-r--r--unittests/ADT/StringMapTest.cpp22
-rw-r--r--unittests/ADT/TripleTest.cpp102
12 files changed, 634 insertions, 10 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp
index 8f298cd..c7ec16b 100644
--- a/unittests/ADT/APFloatTest.cpp
+++ b/unittests/ADT/APFloatTest.cpp
@@ -474,6 +474,40 @@ TEST(APFloatTest, FMA) {
f1.fusedMultiplyAdd(f2, f3, APFloat::rmNearestTiesToEven);
EXPECT_EQ(12.0f, f1.convertToFloat());
}
+
+ {
+ APFloat M1(APFloat::x87DoubleExtended, 1.0);
+ APFloat M2(APFloat::x87DoubleExtended, 1.0);
+ APFloat A(APFloat::x87DoubleExtended, 3.0);
+
+ bool losesInfo = false;
+ M1.fusedMultiplyAdd(M1, A, APFloat::rmNearestTiesToEven);
+ M1.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &losesInfo);
+ EXPECT_FALSE(losesInfo);
+ EXPECT_EQ(4.0f, M1.convertToFloat());
+ }
+}
+
+TEST(APFloatTest, MinNum) {
+ APFloat f1(1.0);
+ APFloat f2(2.0);
+ APFloat nan = APFloat::getNaN(APFloat::IEEEdouble);
+
+ EXPECT_EQ(1.0, minnum(f1, f2).convertToDouble());
+ EXPECT_EQ(1.0, minnum(f2, f1).convertToDouble());
+ EXPECT_EQ(1.0, minnum(f1, nan).convertToDouble());
+ EXPECT_EQ(1.0, minnum(nan, f1).convertToDouble());
+}
+
+TEST(APFloatTest, MaxNum) {
+ APFloat f1(1.0);
+ APFloat f2(2.0);
+ APFloat nan = APFloat::getNaN(APFloat::IEEEdouble);
+
+ EXPECT_EQ(2.0, maxnum(f1, f2).convertToDouble());
+ EXPECT_EQ(2.0, maxnum(f2, f1).convertToDouble());
+ EXPECT_EQ(1.0, maxnum(f1, nan).convertToDouble());
+ EXPECT_EQ(1.0, minnum(nan, f1).convertToDouble());
}
TEST(APFloatTest, Denormal) {
@@ -1342,6 +1376,17 @@ TEST(APFloatTest, getZero) {
}
}
+TEST(APFloatTest, copySign) {
+ EXPECT_TRUE(APFloat(-42.0).bitwiseIsEqual(
+ APFloat::copySign(APFloat(42.0), APFloat(-1.0))));
+ EXPECT_TRUE(APFloat(42.0).bitwiseIsEqual(
+ APFloat::copySign(APFloat(-42.0), APFloat(1.0))));
+ EXPECT_TRUE(APFloat(-42.0).bitwiseIsEqual(
+ APFloat::copySign(APFloat(-42.0), APFloat(-1.0))));
+ EXPECT_TRUE(APFloat(42.0).bitwiseIsEqual(
+ APFloat::copySign(APFloat(42.0), APFloat(1.0))));
+}
+
TEST(APFloatTest, convert) {
bool losesInfo;
APFloat test(APFloat::IEEEdouble, "1.0");
@@ -2671,4 +2716,123 @@ TEST(APFloatTest, divide) {
}
}
+TEST(APFloatTest, operatorOverloads) {
+ // This is mostly testing that these operator overloads compile.
+ APFloat One = APFloat(APFloat::IEEEsingle, "0x1p+0");
+ APFloat Two = APFloat(APFloat::IEEEsingle, "0x2p+0");
+ EXPECT_TRUE(Two.bitwiseIsEqual(One + One));
+ EXPECT_TRUE(One.bitwiseIsEqual(Two - One));
+ EXPECT_TRUE(Two.bitwiseIsEqual(One * Two));
+ EXPECT_TRUE(One.bitwiseIsEqual(Two / Two));
+}
+
+TEST(APFloatTest, abs) {
+ APFloat PInf = APFloat::getInf(APFloat::IEEEsingle, false);
+ APFloat MInf = APFloat::getInf(APFloat::IEEEsingle, true);
+ APFloat PZero = APFloat::getZero(APFloat::IEEEsingle, false);
+ APFloat MZero = APFloat::getZero(APFloat::IEEEsingle, true);
+ APFloat PQNaN = APFloat::getNaN(APFloat::IEEEsingle, false);
+ APFloat MQNaN = APFloat::getNaN(APFloat::IEEEsingle, true);
+ APFloat PSNaN = APFloat::getSNaN(APFloat::IEEEsingle, false);
+ APFloat MSNaN = APFloat::getSNaN(APFloat::IEEEsingle, true);
+ APFloat PNormalValue = APFloat(APFloat::IEEEsingle, "0x1p+0");
+ APFloat MNormalValue = APFloat(APFloat::IEEEsingle, "-0x1p+0");
+ APFloat PLargestValue = APFloat::getLargest(APFloat::IEEEsingle, false);
+ APFloat MLargestValue = APFloat::getLargest(APFloat::IEEEsingle, true);
+ APFloat PSmallestValue = APFloat::getSmallest(APFloat::IEEEsingle, false);
+ APFloat MSmallestValue = APFloat::getSmallest(APFloat::IEEEsingle, true);
+ APFloat PSmallestNormalized =
+ APFloat::getSmallestNormalized(APFloat::IEEEsingle, false);
+ APFloat MSmallestNormalized =
+ APFloat::getSmallestNormalized(APFloat::IEEEsingle, true);
+
+ EXPECT_TRUE(PInf.bitwiseIsEqual(abs(PInf)));
+ EXPECT_TRUE(PInf.bitwiseIsEqual(abs(MInf)));
+ EXPECT_TRUE(PZero.bitwiseIsEqual(abs(PZero)));
+ EXPECT_TRUE(PZero.bitwiseIsEqual(abs(MZero)));
+ EXPECT_TRUE(PQNaN.bitwiseIsEqual(abs(PQNaN)));
+ EXPECT_TRUE(PQNaN.bitwiseIsEqual(abs(MQNaN)));
+ EXPECT_TRUE(PSNaN.bitwiseIsEqual(abs(PSNaN)));
+ EXPECT_TRUE(PSNaN.bitwiseIsEqual(abs(MSNaN)));
+ EXPECT_TRUE(PNormalValue.bitwiseIsEqual(abs(PNormalValue)));
+ EXPECT_TRUE(PNormalValue.bitwiseIsEqual(abs(MNormalValue)));
+ EXPECT_TRUE(PLargestValue.bitwiseIsEqual(abs(PLargestValue)));
+ EXPECT_TRUE(PLargestValue.bitwiseIsEqual(abs(MLargestValue)));
+ EXPECT_TRUE(PSmallestValue.bitwiseIsEqual(abs(PSmallestValue)));
+ EXPECT_TRUE(PSmallestValue.bitwiseIsEqual(abs(MSmallestValue)));
+ EXPECT_TRUE(PSmallestNormalized.bitwiseIsEqual(abs(PSmallestNormalized)));
+ EXPECT_TRUE(PSmallestNormalized.bitwiseIsEqual(abs(MSmallestNormalized)));
+}
+
+TEST(APFloatTest, ilogb) {
+ EXPECT_EQ(0, ilogb(APFloat(APFloat::IEEEsingle, "0x1p+0")));
+ EXPECT_EQ(0, ilogb(APFloat(APFloat::IEEEsingle, "-0x1p+0")));
+ EXPECT_EQ(42, ilogb(APFloat(APFloat::IEEEsingle, "0x1p+42")));
+ EXPECT_EQ(-42, ilogb(APFloat(APFloat::IEEEsingle, "0x1p-42")));
+
+ EXPECT_EQ(APFloat::IEK_Inf,
+ ilogb(APFloat::getInf(APFloat::IEEEsingle, false)));
+ EXPECT_EQ(APFloat::IEK_Inf,
+ ilogb(APFloat::getInf(APFloat::IEEEsingle, true)));
+ EXPECT_EQ(APFloat::IEK_Zero,
+ ilogb(APFloat::getZero(APFloat::IEEEsingle, false)));
+ EXPECT_EQ(APFloat::IEK_Zero,
+ ilogb(APFloat::getZero(APFloat::IEEEsingle, true)));
+ EXPECT_EQ(APFloat::IEK_NaN,
+ ilogb(APFloat::getNaN(APFloat::IEEEsingle, false)));
+ EXPECT_EQ(APFloat::IEK_NaN,
+ ilogb(APFloat::getSNaN(APFloat::IEEEsingle, false)));
+
+ EXPECT_EQ(127, ilogb(APFloat::getLargest(APFloat::IEEEsingle, false)));
+ EXPECT_EQ(127, ilogb(APFloat::getLargest(APFloat::IEEEsingle, true)));
+ EXPECT_EQ(-126, ilogb(APFloat::getSmallest(APFloat::IEEEsingle, false)));
+ EXPECT_EQ(-126, ilogb(APFloat::getSmallest(APFloat::IEEEsingle, true)));
+ EXPECT_EQ(-126,
+ ilogb(APFloat::getSmallestNormalized(APFloat::IEEEsingle, false)));
+ EXPECT_EQ(-126,
+ ilogb(APFloat::getSmallestNormalized(APFloat::IEEEsingle, true)));
+}
+
+TEST(APFloatTest, scalbn) {
+ EXPECT_TRUE(
+ APFloat(APFloat::IEEEsingle, "0x1p+0")
+ .bitwiseIsEqual(scalbn(APFloat(APFloat::IEEEsingle, "0x1p+0"), 0)));
+ EXPECT_TRUE(
+ APFloat(APFloat::IEEEsingle, "0x1p+42")
+ .bitwiseIsEqual(scalbn(APFloat(APFloat::IEEEsingle, "0x1p+0"), 42)));
+ EXPECT_TRUE(
+ APFloat(APFloat::IEEEsingle, "0x1p-42")
+ .bitwiseIsEqual(scalbn(APFloat(APFloat::IEEEsingle, "0x1p+0"), -42)));
+
+ APFloat PInf = APFloat::getInf(APFloat::IEEEsingle, false);
+ APFloat MInf = APFloat::getInf(APFloat::IEEEsingle, true);
+ APFloat PZero = APFloat::getZero(APFloat::IEEEsingle, false);
+ APFloat MZero = APFloat::getZero(APFloat::IEEEsingle, true);
+ APFloat QPNaN = APFloat::getNaN(APFloat::IEEEsingle, false);
+ APFloat QMNaN = APFloat::getNaN(APFloat::IEEEsingle, true);
+ APFloat SNaN = APFloat::getSNaN(APFloat::IEEEsingle, false);
+
+ EXPECT_TRUE(PInf.bitwiseIsEqual(scalbn(PInf, 0)));
+ EXPECT_TRUE(MInf.bitwiseIsEqual(scalbn(MInf, 0)));
+ EXPECT_TRUE(PZero.bitwiseIsEqual(scalbn(PZero, 0)));
+ EXPECT_TRUE(MZero.bitwiseIsEqual(scalbn(MZero, 0)));
+ EXPECT_TRUE(QPNaN.bitwiseIsEqual(scalbn(QPNaN, 0)));
+ EXPECT_TRUE(QMNaN.bitwiseIsEqual(scalbn(QMNaN, 0)));
+ EXPECT_TRUE(SNaN.bitwiseIsEqual(scalbn(SNaN, 0)));
+
+ EXPECT_TRUE(
+ PInf.bitwiseIsEqual(scalbn(APFloat(APFloat::IEEEsingle, "0x1p+0"), 128)));
+ EXPECT_TRUE(MInf.bitwiseIsEqual(
+ scalbn(APFloat(APFloat::IEEEsingle, "-0x1p+0"), 128)));
+ EXPECT_TRUE(
+ PInf.bitwiseIsEqual(scalbn(APFloat(APFloat::IEEEsingle, "0x1p+127"), 1)));
+ EXPECT_TRUE(PZero.bitwiseIsEqual(
+ scalbn(APFloat(APFloat::IEEEsingle, "0x1p+0"), -127)));
+ EXPECT_TRUE(MZero.bitwiseIsEqual(
+ scalbn(APFloat(APFloat::IEEEsingle, "-0x1p+0"), -127)));
+ EXPECT_TRUE(PZero.bitwiseIsEqual(
+ scalbn(APFloat(APFloat::IEEEsingle, "0x1p-126"), -1)));
+ EXPECT_TRUE(PZero.bitwiseIsEqual(
+ scalbn(APFloat(APFloat::IEEEsingle, "0x1p-126"), -1)));
+}
}
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index 19c47ab..8198c71 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -614,7 +614,7 @@ TEST(APIntTest, arrayAccess) {
0x7E7FFA5EADD8846ULL,
0x305F341CA00B613DULL
};
- APInt A2(integerPartWidth*4, ArrayRef<integerPart>(E2, 4));
+ APInt A2(integerPartWidth*4, E2);
for (unsigned i = 0; i < 4; ++i) {
for (unsigned j = 0; j < integerPartWidth; ++j) {
EXPECT_EQ(bool(E2[i] & (1ULL << j)),
@@ -653,17 +653,17 @@ TEST(APIntTest, nearestLogBase2) {
// Test round up.
integerPart I4[4] = {0x0, 0xF, 0x18, 0x0};
- APInt A4(integerPartWidth*4, ArrayRef<integerPart>(I4, 4));
+ APInt A4(integerPartWidth*4, I4);
EXPECT_EQ(A4.nearestLogBase2(), A4.ceilLogBase2());
// Test round down.
integerPart I5[4] = {0x0, 0xF, 0x10, 0x0};
- APInt A5(integerPartWidth*4, ArrayRef<integerPart>(I5, 4));
+ APInt A5(integerPartWidth*4, I5);
EXPECT_EQ(A5.nearestLogBase2(), A5.logBase2());
// Test ties round up.
uint64_t I6[4] = {0x0, 0x0, 0x0, 0x18};
- APInt A6(integerPartWidth*4, ArrayRef<integerPart>(I6, 4));
+ APInt A6(integerPartWidth*4, I6);
EXPECT_EQ(A6.nearestLogBase2(), A6.ceilLogBase2());
// Test BitWidth == 1 special cases.
@@ -678,4 +678,21 @@ TEST(APIntTest, nearestLogBase2) {
EXPECT_EQ(A9.nearestLogBase2(), UINT32_MAX);
}
+TEST(APIntTest, SelfMoveAssignment) {
+ APInt X(32, 0xdeadbeef);
+ X = std::move(X);
+ EXPECT_EQ(32u, X.getBitWidth());
+ EXPECT_EQ(0xdeadbeefULL, X.getLimitedValue());
+
+ uint64_t Bits[] = {0xdeadbeefdeadbeefULL, 0xdeadbeefdeadbeefULL};
+ APInt Y(128, Bits);
+ Y = std::move(Y);
+ EXPECT_EQ(128u, Y.getBitWidth());
+ EXPECT_EQ(~0ULL, Y.getLimitedValue());
+ const uint64_t *Raw = Y.getRawData();
+ EXPECT_EQ(2u, Y.getNumWords());
+ EXPECT_EQ(0xdeadbeefdeadbeefULL, Raw[0]);
+ EXPECT_EQ(0xdeadbeefdeadbeefULL, Raw[1]);
+}
+
}
diff --git a/unittests/ADT/ArrayRefTest.cpp b/unittests/ADT/ArrayRefTest.cpp
index 293afc6..f9c98a5 100644
--- a/unittests/ADT/ArrayRefTest.cpp
+++ b/unittests/ADT/ArrayRefTest.cpp
@@ -13,6 +13,23 @@
#include "gtest/gtest.h"
using namespace llvm;
+// Check that the ArrayRef-of-pointer converting constructor only allows adding
+// cv qualifiers (not removing them, or otherwise changing the type)
+static_assert(
+ std::is_convertible<ArrayRef<int *>, ArrayRef<const int *>>::value,
+ "Adding const");
+static_assert(
+ std::is_convertible<ArrayRef<int *>, ArrayRef<volatile int *>>::value,
+ "Adding volatile");
+static_assert(!std::is_convertible<ArrayRef<int *>, ArrayRef<float *>>::value,
+ "Changing pointer of one type to a pointer of another");
+static_assert(
+ !std::is_convertible<ArrayRef<const int *>, ArrayRef<int *>>::value,
+ "Removing const");
+static_assert(
+ !std::is_convertible<ArrayRef<volatile int *>, ArrayRef<int *>>::value,
+ "Removing volatile");
+
namespace llvm {
TEST(ArrayRefTest, AllocatorCopy) {
@@ -36,5 +53,41 @@ TEST(ArrayRefTest, DropBack) {
EXPECT_TRUE(AR1.drop_back().equals(AR2));
}
+TEST(ArrayRefTest, Equals) {
+ static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8};
+ ArrayRef<int> AR1(A1);
+ EXPECT_TRUE(AR1.equals(1, 2, 3, 4, 5, 6, 7, 8));
+ EXPECT_FALSE(AR1.equals(8, 1, 2, 4, 5, 6, 6, 7));
+ EXPECT_FALSE(AR1.equals(2, 4, 5, 6, 6, 7, 8, 1));
+ EXPECT_FALSE(AR1.equals(0, 1, 2, 4, 5, 6, 6, 7));
+ EXPECT_FALSE(AR1.equals(1, 2, 42, 4, 5, 6, 7, 8));
+ EXPECT_FALSE(AR1.equals(42, 2, 3, 4, 5, 6, 7, 8));
+ EXPECT_FALSE(AR1.equals(1, 2, 3, 4, 5, 6, 7, 42));
+ EXPECT_FALSE(AR1.equals(1, 2, 3, 4, 5, 6, 7));
+ EXPECT_FALSE(AR1.equals(1, 2, 3, 4, 5, 6, 7, 8, 9));
+
+ ArrayRef<int> AR1a = AR1.drop_back();
+ EXPECT_TRUE(AR1a.equals(1, 2, 3, 4, 5, 6, 7));
+ EXPECT_FALSE(AR1a.equals(1, 2, 3, 4, 5, 6, 7, 8));
+
+ ArrayRef<int> AR1b = AR1a.slice(2, 4);
+ EXPECT_TRUE(AR1b.equals(3, 4, 5, 6));
+ EXPECT_FALSE(AR1b.equals(2, 3, 4, 5, 6));
+ EXPECT_FALSE(AR1b.equals(3, 4, 5, 6, 7));
+}
+
+TEST(ArrayRefTest, EmptyEquals) {
+ EXPECT_TRUE(ArrayRef<unsigned>() == ArrayRef<unsigned>());
+}
+
+TEST(ArrayRefTest, ConstConvert) {
+ int buf[4];
+ for (int i = 0; i < 4; ++i)
+ buf[i] = i;
+
+ static int *A[] = {&buf[0], &buf[1], &buf[2], &buf[3]};
+ ArrayRef<const int *> a((ArrayRef<int *>(A)));
+ a = ArrayRef<int *>(A);
+}
} // end anonymous namespace
diff --git a/unittests/ADT/CMakeLists.txt b/unittests/ADT/CMakeLists.txt
index 0f214f3..d899852 100644
--- a/unittests/ADT/CMakeLists.txt
+++ b/unittests/ADT/CMakeLists.txt
@@ -13,6 +13,7 @@ set(ADTSources
DenseMapTest.cpp
DenseSetTest.cpp
FoldingSet.cpp
+ FunctionRefTest.cpp
HashingTest.cpp
ilistTest.cpp
ImmutableMapTest.cpp
@@ -26,6 +27,7 @@ set(ADTSources
PackedVectorTest.cpp
PointerIntPairTest.cpp
PointerUnionTest.cpp
+ PostOrderIteratorTest.cpp
SCCIteratorTest.cpp
SmallPtrSetTest.cpp
SmallStringTest.cpp
diff --git a/unittests/ADT/DenseMapTest.cpp b/unittests/ADT/DenseMapTest.cpp
index 75a910a..f497983 100644
--- a/unittests/ADT/DenseMapTest.cpp
+++ b/unittests/ADT/DenseMapTest.cpp
@@ -244,6 +244,11 @@ TYPED_TEST(DenseMapTest, AssignmentTest) {
EXPECT_EQ(1u, copyMap.size());
EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
+
+ // test self-assignment.
+ copyMap = copyMap;
+ EXPECT_EQ(1u, copyMap.size());
+ EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
}
// Test swap method
diff --git a/unittests/ADT/DenseSetTest.cpp b/unittests/ADT/DenseSetTest.cpp
index 154c589..5952353 100644
--- a/unittests/ADT/DenseSetTest.cpp
+++ b/unittests/ADT/DenseSetTest.cpp
@@ -27,4 +27,42 @@ TEST_F(DenseSetTest, DoubleEntrySetTest) {
EXPECT_EQ(0u, set.count(2));
}
+struct TestDenseSetInfo {
+ static inline unsigned getEmptyKey() { return ~0; }
+ static inline unsigned getTombstoneKey() { return ~0U - 1; }
+ static unsigned getHashValue(const unsigned& Val) { return Val * 37U; }
+ static unsigned getHashValue(const char* Val) {
+ return (unsigned)(Val[0] - 'a') * 37U;
+ }
+ static bool isEqual(const unsigned& LHS, const unsigned& RHS) {
+ return LHS == RHS;
+ }
+ static bool isEqual(const char* LHS, const unsigned& RHS) {
+ return (unsigned)(LHS[0] - 'a') == RHS;
+ }
+};
+
+TEST(DenseSetCustomTest, FindAsTest) {
+ DenseSet<unsigned, TestDenseSetInfo> set;
+ set.insert(0);
+ set.insert(1);
+ set.insert(2);
+
+ // Size tests
+ EXPECT_EQ(3u, set.size());
+
+ // Normal lookup tests
+ EXPECT_EQ(1u, set.count(1));
+ EXPECT_EQ(0u, *set.find(0));
+ EXPECT_EQ(1u, *set.find(1));
+ EXPECT_EQ(2u, *set.find(2));
+ EXPECT_TRUE(set.find(3) == set.end());
+
+ // find_as() tests
+ EXPECT_EQ(0u, *set.find_as("a"));
+ EXPECT_EQ(1u, *set.find_as("b"));
+ EXPECT_EQ(2u, *set.find_as("c"));
+ EXPECT_TRUE(set.find_as("d") == set.end());
+}
+
}
diff --git a/unittests/ADT/FunctionRefTest.cpp b/unittests/ADT/FunctionRefTest.cpp
new file mode 100644
index 0000000..075d9a0
--- /dev/null
+++ b/unittests/ADT/FunctionRefTest.cpp
@@ -0,0 +1,28 @@
+//===- llvm/unittest/ADT/MakeUniqueTest.cpp - make_unique unit tests ------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+// Ensure that copies of a function_ref copy the underlying state rather than
+// causing one function_ref to chain to the next.
+TEST(FunctionRefTest, Copy) {
+ auto A = [] { return 1; };
+ auto B = [] { return 2; };
+ function_ref<int()> X = A;
+ function_ref<int()> Y = X;
+ X = B;
+ EXPECT_EQ(1, Y());
+}
+
+}
diff --git a/unittests/ADT/MapVectorTest.cpp b/unittests/ADT/MapVectorTest.cpp
index 11178bc..8919799 100644
--- a/unittests/ADT/MapVectorTest.cpp
+++ b/unittests/ADT/MapVectorTest.cpp
@@ -9,6 +9,7 @@
#include "gtest/gtest.h"
#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/iterator_range.h"
#include <utility>
using namespace llvm;
@@ -53,3 +54,71 @@ TEST(MapVectorTest, insert_pop) {
EXPECT_EQ(MV[1], 2);
EXPECT_EQ(MV[4], 7);
}
+
+TEST(MapVectorTest, erase) {
+ MapVector<int, int> MV;
+
+ MV.insert(std::make_pair(1, 2));
+ MV.insert(std::make_pair(3, 4));
+ MV.insert(std::make_pair(5, 6));
+ ASSERT_EQ(MV.size(), 3u);
+
+ MV.erase(MV.find(1));
+ ASSERT_EQ(MV.size(), 2u);
+ ASSERT_EQ(MV.find(1), MV.end());
+ ASSERT_EQ(MV[3], 4);
+ ASSERT_EQ(MV[5], 6);
+
+ ASSERT_EQ(MV.erase(3), 1u);
+ ASSERT_EQ(MV.size(), 1u);
+ ASSERT_EQ(MV.find(3), MV.end());
+ ASSERT_EQ(MV[5], 6);
+
+ ASSERT_EQ(MV.erase(79), 0u);
+ ASSERT_EQ(MV.size(), 1u);
+}
+
+TEST(MapVectorTest, remove_if) {
+ MapVector<int, int> MV;
+
+ MV.insert(std::make_pair(1, 11));
+ MV.insert(std::make_pair(2, 12));
+ MV.insert(std::make_pair(3, 13));
+ MV.insert(std::make_pair(4, 14));
+ MV.insert(std::make_pair(5, 15));
+ MV.insert(std::make_pair(6, 16));
+ ASSERT_EQ(MV.size(), 6u);
+
+ MV.remove_if([](const std::pair<int, int> &Val) { return Val.second % 2; });
+ ASSERT_EQ(MV.size(), 3u);
+ ASSERT_EQ(MV.find(1), MV.end());
+ ASSERT_EQ(MV.find(3), MV.end());
+ ASSERT_EQ(MV.find(5), MV.end());
+ ASSERT_EQ(MV[2], 12);
+ ASSERT_EQ(MV[4], 14);
+ ASSERT_EQ(MV[6], 16);
+}
+
+TEST(MapVectorTest, iteration_test) {
+ MapVector<int, int> MV;
+
+ MV.insert(std::make_pair(1, 11));
+ MV.insert(std::make_pair(2, 12));
+ MV.insert(std::make_pair(3, 13));
+ MV.insert(std::make_pair(4, 14));
+ MV.insert(std::make_pair(5, 15));
+ MV.insert(std::make_pair(6, 16));
+ ASSERT_EQ(MV.size(), 6u);
+
+ int count = 1;
+ for (auto P : make_range(MV.begin(), MV.end())) {
+ ASSERT_EQ(P.first, count);
+ count++;
+ }
+
+ count = 6;
+ for (auto P : make_range(MV.rbegin(), MV.rend())) {
+ ASSERT_EQ(P.first, count);
+ count--;
+ }
+}
diff --git a/unittests/ADT/OptionalTest.cpp b/unittests/ADT/OptionalTest.cpp
index 2da408c..cadadce 100644
--- a/unittests/ADT/OptionalTest.cpp
+++ b/unittests/ADT/OptionalTest.cpp
@@ -169,6 +169,52 @@ TEST_F(OptionalTest, NullCopyConstructionTest) {
EXPECT_EQ(0u, NonDefaultConstructible::Destructions);
}
+TEST_F(OptionalTest, GetValueOr) {
+ Optional<int> A;
+ EXPECT_EQ(42, A.getValueOr(42));
+
+ A = 5;
+ EXPECT_EQ(5, A.getValueOr(42));
+}
+
+struct MultiArgConstructor {
+ int x, y;
+ MultiArgConstructor(int x, int y) : x(x), y(y) {}
+ explicit MultiArgConstructor(int x, bool positive)
+ : x(x), y(positive ? x : -x) {}
+
+ MultiArgConstructor(const MultiArgConstructor &) LLVM_DELETED_FUNCTION;
+ MultiArgConstructor(MultiArgConstructor &&) LLVM_DELETED_FUNCTION;
+ MultiArgConstructor &operator=(const MultiArgConstructor &) LLVM_DELETED_FUNCTION;
+ MultiArgConstructor &operator=(MultiArgConstructor &&) LLVM_DELETED_FUNCTION;
+
+ static unsigned Destructions;
+ ~MultiArgConstructor() {
+ ++Destructions;
+ }
+ static void ResetCounts() {
+ Destructions = 0;
+ }
+};
+unsigned MultiArgConstructor::Destructions = 0;
+
+TEST_F(OptionalTest, Emplace) {
+ MultiArgConstructor::ResetCounts();
+ Optional<MultiArgConstructor> A;
+
+ A.emplace(1, 2);
+ EXPECT_TRUE(A.hasValue());
+ EXPECT_EQ(1, A->x);
+ EXPECT_EQ(2, A->y);
+ EXPECT_EQ(0u, MultiArgConstructor::Destructions);
+
+ A.emplace(5, false);
+ EXPECT_TRUE(A.hasValue());
+ EXPECT_EQ(5, A->x);
+ EXPECT_EQ(-5, A->y);
+ EXPECT_EQ(1u, MultiArgConstructor::Destructions);
+}
+
struct MoveOnly {
static unsigned MoveConstructions;
static unsigned Destructions;
@@ -278,5 +324,58 @@ TEST_F(OptionalTest, MoveOnlyAssigningAssignment) {
EXPECT_EQ(1u, MoveOnly::Destructions);
}
+struct Immovable {
+ static unsigned Constructions;
+ static unsigned Destructions;
+ int val;
+ explicit Immovable(int val) : val(val) {
+ ++Constructions;
+ }
+ ~Immovable() {
+ ++Destructions;
+ }
+ static void ResetCounts() {
+ Constructions = 0;
+ Destructions = 0;
+ }
+private:
+ // This should disable all move/copy operations.
+ Immovable(Immovable&& other) LLVM_DELETED_FUNCTION;
+};
+
+unsigned Immovable::Constructions = 0;
+unsigned Immovable::Destructions = 0;
+
+TEST_F(OptionalTest, ImmovableEmplace) {
+ Optional<Immovable> A;
+ Immovable::ResetCounts();
+ A.emplace(4);
+ EXPECT_TRUE((bool)A);
+ EXPECT_EQ(4, A->val);
+ EXPECT_EQ(1u, Immovable::Constructions);
+ EXPECT_EQ(0u, Immovable::Destructions);
+}
+
+#if LLVM_HAS_RVALUE_REFERENCE_THIS
+
+TEST_F(OptionalTest, MoveGetValueOr) {
+ Optional<MoveOnly> A;
+
+ MoveOnly::ResetCounts();
+ EXPECT_EQ(42, std::move(A).getValueOr(MoveOnly(42)).val);
+ EXPECT_EQ(1u, MoveOnly::MoveConstructions);
+ EXPECT_EQ(0u, MoveOnly::MoveAssignments);
+ EXPECT_EQ(2u, MoveOnly::Destructions);
+
+ A = MoveOnly(5);
+ MoveOnly::ResetCounts();
+ EXPECT_EQ(5, std::move(A).getValueOr(MoveOnly(42)).val);
+ EXPECT_EQ(1u, MoveOnly::MoveConstructions);
+ EXPECT_EQ(0u, MoveOnly::MoveAssignments);
+ EXPECT_EQ(2u, MoveOnly::Destructions);
+}
+
+#endif // LLVM_HAS_RVALUE_REFERENCE_THIS
+
} // end anonymous namespace
diff --git a/unittests/ADT/PostOrderIteratorTest.cpp b/unittests/ADT/PostOrderIteratorTest.cpp
new file mode 100644
index 0000000..1da1078
--- /dev/null
+++ b/unittests/ADT/PostOrderIteratorTest.cpp
@@ -0,0 +1,37 @@
+//===- PostOrderIteratorTest.cpp - PostOrderIterator unit tests -----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "gtest/gtest.h"
+#include "llvm/ADT/PostOrderIterator.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/CFG.h"
+using namespace llvm;
+
+namespace {
+
+// Whether we're able to compile
+TEST(PostOrderIteratorTest, Compiles) {
+ typedef SmallPtrSet<void *, 4> ExtSetTy;
+
+ // Tests that template specializations are kept up to date
+ void *Null = nullptr;
+ po_iterator_storage<std::set<void *>, false> PIS;
+ PIS.insertEdge(Null, Null);
+ ExtSetTy Ext;
+ po_iterator_storage<ExtSetTy, true> PISExt(Ext);
+ PIS.insertEdge(Null, Null);
+
+ // Test above, but going through po_iterator (which inherits from template
+ // base)
+ BasicBlock *NullBB = nullptr;
+ auto PI = po_end(NullBB);
+ PI.insertEdge(NullBB, NullBB);
+ auto PIExt = po_ext_end(NullBB, Ext);
+ PIExt.insertEdge(NullBB, NullBB);
+}
+}
diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp
index 028375d..33d668f 100644
--- a/unittests/ADT/StringMapTest.cpp
+++ b/unittests/ADT/StringMapTest.cpp
@@ -250,15 +250,21 @@ struct StringMapTestStruct {
TEST_F(StringMapTest, NonDefaultConstructable) {
StringMap<StringMapTestStruct> t;
- t.GetOrCreateValue("Test", StringMapTestStruct(123));
+ t.insert(std::make_pair("Test", StringMapTestStruct(123)));
StringMap<StringMapTestStruct>::iterator iter = t.find("Test");
ASSERT_NE(iter, t.end());
ASSERT_EQ(iter->second.i, 123);
}
+struct Immovable {
+ Immovable() {}
+ Immovable(Immovable&&) LLVM_DELETED_FUNCTION; // will disable the other special members
+};
+
struct MoveOnly {
int i;
MoveOnly(int i) : i(i) {}
+ MoveOnly(const Immovable&) : i(0) {}
MoveOnly(MoveOnly &&RHS) : i(RHS.i) {}
MoveOnly &operator=(MoveOnly &&RHS) {
i = RHS.i;
@@ -270,17 +276,23 @@ private:
MoveOnly &operator=(const MoveOnly &) LLVM_DELETED_FUNCTION;
};
-TEST_F(StringMapTest, MoveOnlyKey) {
+TEST_F(StringMapTest, MoveOnly) {
StringMap<MoveOnly> t;
- t.GetOrCreateValue("Test", MoveOnly(42));
+ t.insert(std::make_pair("Test", MoveOnly(42)));
StringRef Key = "Test";
StringMapEntry<MoveOnly>::Create(Key, MoveOnly(42))
->Destroy();
}
+TEST_F(StringMapTest, CtorArg) {
+ StringRef Key = "Test";
+ StringMapEntry<MoveOnly>::Create(Key, Immovable())
+ ->Destroy();
+}
+
TEST_F(StringMapTest, MoveConstruct) {
StringMap<int> A;
- A.GetOrCreateValue("x", 42);
+ A["x"] = 42;
StringMap<int> B = std::move(A);
ASSERT_EQ(A.size(), 0u);
ASSERT_EQ(B.size(), 1u);
@@ -325,7 +337,7 @@ struct Countable {
TEST_F(StringMapTest, MoveDtor) {
int InstanceCount = 0;
StringMap<Countable> A;
- A.GetOrCreateValue("x", Countable(42, InstanceCount));
+ A.insert(std::make_pair("x", Countable(42, InstanceCount)));
ASSERT_EQ(InstanceCount, 1);
auto I = A.find("x");
ASSERT_NE(I, A.end());
diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp
index 2e9d585..cacbde6 100644
--- a/unittests/ADT/TripleTest.cpp
+++ b/unittests/ADT/TripleTest.cpp
@@ -129,6 +129,36 @@ TEST(TripleTest, ParsedIDs) {
EXPECT_EQ(Triple::UnknownOS, T.getOS());
EXPECT_EQ(Triple::EABI, T.getEnvironment());
+ T = Triple("amdil-unknown-unknown");
+ EXPECT_EQ(Triple::amdil, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::UnknownOS, T.getOS());
+
+ T = Triple("amdil64-unknown-unknown");
+ EXPECT_EQ(Triple::amdil64, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::UnknownOS, T.getOS());
+
+ T = Triple("hsail-unknown-unknown");
+ EXPECT_EQ(Triple::hsail, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::UnknownOS, T.getOS());
+
+ T = Triple("hsail64-unknown-unknown");
+ EXPECT_EQ(Triple::hsail64, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::UnknownOS, T.getOS());
+
+ T = Triple("spir-unknown-unknown");
+ EXPECT_EQ(Triple::spir, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::UnknownOS, T.getOS());
+
+ T = Triple("spir64-unknown-unknown");
+ EXPECT_EQ(Triple::spir64, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::UnknownOS, T.getOS());
+
T = Triple("huh");
EXPECT_EQ(Triple::UnknownArch, T.getArch());
}
@@ -190,7 +220,7 @@ TEST(TripleTest, Normalization) {
++Vendor) {
C[1] = Triple::getVendorTypeName(Triple::VendorType(Vendor));
for (int OS = 1+Triple::UnknownOS; OS <= Triple::Minix; ++OS) {
- if (OS == Triple::Cygwin || OS == Triple::MinGW32 || OS == Triple::Win32)
+ if (OS == Triple::Win32)
continue;
C[2] = Triple::getOSTypeName(Triple::OSType(OS));
@@ -341,6 +371,36 @@ TEST(TripleTest, BitWidthPredicates) {
EXPECT_FALSE(T.isArch16Bit());
EXPECT_FALSE(T.isArch32Bit());
EXPECT_TRUE(T.isArch64Bit());
+
+ T.setArch(Triple::amdil);
+ EXPECT_FALSE(T.isArch16Bit());
+ EXPECT_TRUE(T.isArch32Bit());
+ EXPECT_FALSE(T.isArch64Bit());
+
+ T.setArch(Triple::amdil64);
+ EXPECT_FALSE(T.isArch16Bit());
+ EXPECT_FALSE(T.isArch32Bit());
+ EXPECT_TRUE(T.isArch64Bit());
+
+ T.setArch(Triple::hsail);
+ EXPECT_FALSE(T.isArch16Bit());
+ EXPECT_TRUE(T.isArch32Bit());
+ EXPECT_FALSE(T.isArch64Bit());
+
+ T.setArch(Triple::hsail64);
+ EXPECT_FALSE(T.isArch16Bit());
+ EXPECT_FALSE(T.isArch32Bit());
+ EXPECT_TRUE(T.isArch64Bit());
+
+ T.setArch(Triple::spir);
+ EXPECT_FALSE(T.isArch16Bit());
+ EXPECT_TRUE(T.isArch32Bit());
+ EXPECT_FALSE(T.isArch64Bit());
+
+ T.setArch(Triple::spir64);
+ EXPECT_FALSE(T.isArch16Bit());
+ EXPECT_FALSE(T.isArch32Bit());
+ EXPECT_TRUE(T.isArch64Bit());
}
TEST(TripleTest, BitWidthArchVariants) {
@@ -399,6 +459,30 @@ TEST(TripleTest, BitWidthArchVariants) {
T.setArch(Triple::x86_64);
EXPECT_EQ(Triple::x86, T.get32BitArchVariant().getArch());
EXPECT_EQ(Triple::x86_64, T.get64BitArchVariant().getArch());
+
+ T.setArch(Triple::amdil);
+ EXPECT_EQ(Triple::amdil, T.get32BitArchVariant().getArch());
+ EXPECT_EQ(Triple::amdil64, T.get64BitArchVariant().getArch());
+
+ T.setArch(Triple::amdil64);
+ EXPECT_EQ(Triple::amdil, T.get32BitArchVariant().getArch());
+ EXPECT_EQ(Triple::amdil64, T.get64BitArchVariant().getArch());
+
+ T.setArch(Triple::hsail);
+ EXPECT_EQ(Triple::hsail, T.get32BitArchVariant().getArch());
+ EXPECT_EQ(Triple::hsail64, T.get64BitArchVariant().getArch());
+
+ T.setArch(Triple::hsail64);
+ EXPECT_EQ(Triple::hsail, T.get32BitArchVariant().getArch());
+ EXPECT_EQ(Triple::hsail64, T.get64BitArchVariant().getArch());
+
+ T.setArch(Triple::spir);
+ EXPECT_EQ(Triple::spir, T.get32BitArchVariant().getArch());
+ EXPECT_EQ(Triple::spir64, T.get64BitArchVariant().getArch());
+
+ T.setArch(Triple::spir64);
+ EXPECT_EQ(Triple::spir, T.get32BitArchVariant().getArch());
+ EXPECT_EQ(Triple::spir64, T.get64BitArchVariant().getArch());
}
TEST(TripleTest, getOSVersion) {
@@ -564,4 +648,20 @@ TEST(TripleTest, NormalizeWindows) {
EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-windows-elf-elf"));
}
+
+TEST(TripleTest, getARMCPUForArch) {
+ {
+ llvm::Triple Triple("armv6-unknown-freebsd");
+ EXPECT_STREQ("arm1176jzf-s", Triple.getARMCPUForArch());
+ }
+ {
+ llvm::Triple Triple("armv7s-apple-ios7");
+ EXPECT_STREQ("swift", Triple.getARMCPUForArch());
+ }
+ {
+ llvm::Triple Triple("armv7-apple-ios7");
+ EXPECT_STREQ("cortex-a8", Triple.getARMCPUForArch());
+ EXPECT_STREQ("swift", Triple.getARMCPUForArch("armv7s"));
+ }
+}
}