aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/ADT
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ADT')
-rw-r--r--unittests/ADT/APIntTest.cpp81
-rw-r--r--unittests/ADT/APSIntTest.cpp44
-rw-r--r--unittests/ADT/ArrayRefTest.cpp33
-rw-r--r--unittests/ADT/BitVectorTest.cpp6
-rw-r--r--unittests/ADT/CMakeLists.txt15
-rw-r--r--unittests/ADT/DenseMapTest.cpp30
-rw-r--r--unittests/ADT/HashingTest.cpp2
-rw-r--r--unittests/ADT/MakeUniqueTest.cpp76
-rw-r--r--unittests/ADT/OptionalTest.cpp2
-rw-r--r--unittests/ADT/OwningPtrTest.cpp273
-rw-r--r--unittests/ADT/PointerIntPairTest.cpp76
-rw-r--r--unittests/ADT/SmallPtrSetTest.cpp87
-rw-r--r--unittests/ADT/StringMapTest.cpp32
-rw-r--r--unittests/ADT/StringRefTest.cpp17
-rw-r--r--unittests/ADT/TinyPtrVectorTest.cpp118
-rw-r--r--unittests/ADT/TripleTest.cpp93
-rw-r--r--unittests/ADT/ilistTest.cpp6
-rw-r--r--unittests/ADT/polymorphic_ptr_test.cpp129
18 files changed, 866 insertions, 254 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index 3c0dfe1..19c47ab 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -597,4 +597,85 @@ TEST(APIntTest, tcDecrement) {
EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0);
}
}
+
+TEST(APIntTest, arrayAccess) {
+ // Single word check.
+ uint64_t E1 = 0x2CA7F46BF6569915ULL;
+ APInt A1(64, E1);
+ for (unsigned i = 0, e = 64; i < e; ++i) {
+ EXPECT_EQ(bool(E1 & (1ULL << i)),
+ A1[i]);
+ }
+
+ // Multiword check.
+ integerPart E2[4] = {
+ 0xEB6EB136591CBA21ULL,
+ 0x7B9358BD6A33F10AULL,
+ 0x7E7FFA5EADD8846ULL,
+ 0x305F341CA00B613DULL
+ };
+ APInt A2(integerPartWidth*4, ArrayRef<integerPart>(E2, 4));
+ for (unsigned i = 0; i < 4; ++i) {
+ for (unsigned j = 0; j < integerPartWidth; ++j) {
+ EXPECT_EQ(bool(E2[i] & (1ULL << j)),
+ A2[i*integerPartWidth + j]);
+ }
+ }
+}
+
+TEST(APIntTest, LargeAPIntConstruction) {
+ // Check that we can properly construct very large APInt. It is very
+ // unlikely that people will ever do this, but it is a legal input,
+ // so we should not crash on it.
+ APInt A9(UINT32_MAX, 0);
+ EXPECT_FALSE(A9.getBoolValue());
+}
+
+TEST(APIntTest, nearestLogBase2) {
+ // Single word check.
+
+ // Test round up.
+ uint64_t I1 = 0x1800001;
+ APInt A1(64, I1);
+ EXPECT_EQ(A1.nearestLogBase2(), A1.ceilLogBase2());
+
+ // Test round down.
+ uint64_t I2 = 0x1000011;
+ APInt A2(64, I2);
+ EXPECT_EQ(A2.nearestLogBase2(), A2.logBase2());
+
+ // Test ties round up.
+ uint64_t I3 = 0x1800000;
+ APInt A3(64, I3);
+ EXPECT_EQ(A3.nearestLogBase2(), A3.ceilLogBase2());
+
+ // Multiple word check.
+
+ // Test round up.
+ integerPart I4[4] = {0x0, 0xF, 0x18, 0x0};
+ APInt A4(integerPartWidth*4, ArrayRef<integerPart>(I4, 4));
+ EXPECT_EQ(A4.nearestLogBase2(), A4.ceilLogBase2());
+
+ // Test round down.
+ integerPart I5[4] = {0x0, 0xF, 0x10, 0x0};
+ APInt A5(integerPartWidth*4, ArrayRef<integerPart>(I5, 4));
+ 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));
+ EXPECT_EQ(A6.nearestLogBase2(), A6.ceilLogBase2());
+
+ // Test BitWidth == 1 special cases.
+ APInt A7(1, 1);
+ EXPECT_EQ(A7.nearestLogBase2(), 0ULL);
+ APInt A8(1, 0);
+ EXPECT_EQ(A8.nearestLogBase2(), UINT32_MAX);
+
+ // Test the zero case when we have a bit width large enough such
+ // that the bit width is larger than UINT32_MAX-1.
+ APInt A9(UINT32_MAX, 0);
+ EXPECT_EQ(A9.nearestLogBase2(), UINT32_MAX);
+}
+
}
diff --git a/unittests/ADT/APSIntTest.cpp b/unittests/ADT/APSIntTest.cpp
new file mode 100644
index 0000000..eef9c8a
--- /dev/null
+++ b/unittests/ADT/APSIntTest.cpp
@@ -0,0 +1,44 @@
+//===- llvm/unittest/ADT/APSIntTest.cpp - APSInt 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/APSInt.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(APSIntTest, MoveTest) {
+ APSInt A(32, true);
+ EXPECT_TRUE(A.isUnsigned());
+
+ APSInt B(128, false);
+ A = B;
+ EXPECT_FALSE(A.isUnsigned());
+
+ APSInt C(B);
+ EXPECT_FALSE(C.isUnsigned());
+
+ APInt Wide(256, 0);
+ const uint64_t *Bits = Wide.getRawData();
+ APSInt D(std::move(Wide));
+ EXPECT_TRUE(D.isUnsigned());
+ EXPECT_EQ(Bits, D.getRawData()); // Verify that "Wide" was really moved.
+
+ A = APSInt(64, true);
+ EXPECT_TRUE(A.isUnsigned());
+
+ Wide = APInt(128, 1);
+ Bits = Wide.getRawData();
+ A = std::move(Wide);
+ EXPECT_TRUE(A.isUnsigned());
+ EXPECT_EQ(Bits, A.getRawData()); // Verify that "Wide" was really moved.
+}
+
+}
diff --git a/unittests/ADT/ArrayRefTest.cpp b/unittests/ADT/ArrayRefTest.cpp
new file mode 100644
index 0000000..7133ca7
--- /dev/null
+++ b/unittests/ADT/ArrayRefTest.cpp
@@ -0,0 +1,33 @@
+//===- llvm/unittest/ADT/ArrayRefTest.cpp - ArrayRef 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/ArrayRef.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+using namespace llvm;
+
+namespace llvm {
+
+TEST(ArrayRefTest, AllocatorCopy) {
+ BumpPtrAllocator Alloc;
+ static const uint16_t Words1[] = { 1, 4, 200, 37 };
+ ArrayRef<uint16_t> Array1 = makeArrayRef(Words1, 4);
+ static const uint16_t Words2[] = { 11, 4003, 67, 64000, 13 };
+ ArrayRef<uint16_t> Array2 = makeArrayRef(Words2, 5);
+ ArrayRef<uint16_t> Array1c = Array1.copy(Alloc);
+ ArrayRef<uint16_t> Array2c = Array2.copy(Alloc);;
+ EXPECT_TRUE(Array1.equals(Array1c));
+ EXPECT_NE(Array1.data(), Array1c.data());
+ EXPECT_TRUE(Array2.equals(Array2c));
+ EXPECT_NE(Array2.data(), Array2c.data());
+}
+
+
+} // end anonymous namespace
diff --git a/unittests/ADT/BitVectorTest.cpp b/unittests/ADT/BitVectorTest.cpp
index d7cde89..3deaff0 100644
--- a/unittests/ADT/BitVectorTest.cpp
+++ b/unittests/ADT/BitVectorTest.cpp
@@ -356,6 +356,12 @@ TYPED_TEST(BitVectorTest, RangeOps) {
EXPECT_TRUE( E.test(1));
EXPECT_TRUE( E.test(32));
EXPECT_FALSE(E.test(33));
+
+ TypeParam BufferOverrun;
+ unsigned size = sizeof(unsigned long) * 8;
+ BufferOverrun.resize(size);
+ BufferOverrun.reset(0, size);
+ BufferOverrun.set(0, size);
}
TYPED_TEST(BitVectorTest, CompoundTestReset) {
diff --git a/unittests/ADT/CMakeLists.txt b/unittests/ADT/CMakeLists.txt
index 8ad303a..5119723 100644
--- a/unittests/ADT/CMakeLists.txt
+++ b/unittests/ADT/CMakeLists.txt
@@ -5,6 +5,8 @@ set(LLVM_LINK_COMPONENTS
set(ADTSources
APFloatTest.cpp
APIntTest.cpp
+ APSIntTest.cpp
+ ArrayRefTest.cpp
BitVectorTest.cpp
DAGDeltaAlgorithmTest.cpp
DeltaAlgorithmTest.cpp
@@ -18,9 +20,12 @@ set(ADTSources
IntEqClassesTest.cpp
IntervalMapTest.cpp
IntrusiveRefCntPtrTest.cpp
+ MakeUniqueTest.cpp
MapVectorTest.cpp
OptionalTest.cpp
+ OwningPtrTest.cpp
PackedVectorTest.cpp
+ PointerIntPairTest.cpp
PointerUnionTest.cpp
SCCIteratorTest.cpp
SmallPtrSetTest.cpp
@@ -35,18 +40,8 @@ set(ADTSources
TripleTest.cpp
TwineTest.cpp
VariadicFunctionTest.cpp
- polymorphic_ptr_test.cpp
)
-# They cannot be compiled on MSVC9 due to its bug.
-if(MSVC AND MSVC_VERSION LESS 1600)
- set(LLVM_OPTIONAL_SOURCES
- DenseMapTest.cpp
- SmallVectorTest.cpp
- )
- list(REMOVE_ITEM ADTSources ${LLVM_OPTIONAL_SOURCES})
-endif()
-
add_llvm_unittest(ADTTests
${ADTSources}
)
diff --git a/unittests/ADT/DenseMapTest.cpp b/unittests/ADT/DenseMapTest.cpp
index 15eb698..dd49071 100644
--- a/unittests/ADT/DenseMapTest.cpp
+++ b/unittests/ADT/DenseMapTest.cpp
@@ -119,7 +119,7 @@ TYPED_TEST(DenseMapTest, EmptyIntMapTest) {
// Lookup tests
EXPECT_FALSE(this->Map.count(this->getKey()));
EXPECT_TRUE(this->Map.find(this->getKey()) == this->Map.end());
-#ifndef _MSC_VER
+#if !defined(_MSC_VER) || defined(__clang__)
EXPECT_EQ(typename TypeParam::mapped_type(),
this->Map.lookup(this->getKey()));
#else
@@ -209,6 +209,34 @@ TYPED_TEST(DenseMapTest, CopyConstructorTest) {
EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
}
+// Test copy constructor method where SmallDenseMap isn't small.
+TYPED_TEST(DenseMapTest, CopyConstructorNotSmallTest) {
+ for (int Key = 0; Key < 5; ++Key)
+ this->Map[this->getKey(Key)] = this->getValue(Key);
+ TypeParam copyMap(this->Map);
+
+ EXPECT_EQ(5u, copyMap.size());
+ for (int Key = 0; Key < 5; ++Key)
+ EXPECT_EQ(this->getValue(Key), copyMap[this->getKey(Key)]);
+}
+
+// Test copying from a default-constructed map.
+TYPED_TEST(DenseMapTest, CopyConstructorFromDefaultTest) {
+ TypeParam copyMap(this->Map);
+
+ EXPECT_TRUE(copyMap.empty());
+}
+
+// Test copying from an empty map where SmallDenseMap isn't small.
+TYPED_TEST(DenseMapTest, CopyConstructorFromEmptyTest) {
+ for (int Key = 0; Key < 5; ++Key)
+ this->Map[this->getKey(Key)] = this->getValue(Key);
+ this->Map.clear();
+ TypeParam copyMap(this->Map);
+
+ EXPECT_TRUE(copyMap.empty());
+}
+
// Test assignment operator method
TYPED_TEST(DenseMapTest, AssignmentTest) {
this->Map[this->getKey()] = this->getValue();
diff --git a/unittests/ADT/HashingTest.cpp b/unittests/ADT/HashingTest.cpp
index 1b3d061..60917ae 100644
--- a/unittests/ADT/HashingTest.cpp
+++ b/unittests/ADT/HashingTest.cpp
@@ -41,7 +41,7 @@ struct NonPOD {
namespace hashing {
namespace detail {
-template <> struct is_hashable_data<LargeTestInteger> : true_type {};
+template <> struct is_hashable_data<LargeTestInteger> : std::true_type {};
} // namespace detail
} // namespace hashing
diff --git a/unittests/ADT/MakeUniqueTest.cpp b/unittests/ADT/MakeUniqueTest.cpp
new file mode 100644
index 0000000..3b4938a
--- /dev/null
+++ b/unittests/ADT/MakeUniqueTest.cpp
@@ -0,0 +1,76 @@
+//===- 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"
+#include <tuple>
+using namespace llvm;
+
+namespace {
+
+TEST(MakeUniqueTest, SingleObject) {
+ auto p0 = make_unique<int>();
+ EXPECT_TRUE((bool)p0);
+ EXPECT_EQ(0, *p0);
+
+ auto p1 = make_unique<int>(5);
+ EXPECT_TRUE((bool)p1);
+ EXPECT_EQ(5, *p1);
+
+ auto p2 = make_unique<std::tuple<int, int>>(0, 1);
+ EXPECT_TRUE((bool)p2);
+ EXPECT_EQ(std::make_tuple(0, 1), *p2);
+
+ auto p3 = make_unique<std::tuple<int, int, int>>(0, 1, 2);
+ EXPECT_TRUE((bool)p3);
+ EXPECT_EQ(std::make_tuple(0, 1, 2), *p3);
+
+ auto p4 = make_unique<std::tuple<int, int, int, int>>(0, 1, 2, 3);
+ EXPECT_TRUE((bool)p4);
+ EXPECT_EQ(std::make_tuple(0, 1, 2, 3), *p4);
+
+ auto p5 = make_unique<std::tuple<int, int, int, int, int>>(0, 1, 2, 3, 4);
+ EXPECT_TRUE((bool)p5);
+ EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4), *p5);
+
+ auto p6 =
+ make_unique<std::tuple<int, int, int, int, int, int>>(0, 1, 2, 3, 4, 5);
+ EXPECT_TRUE((bool)p6);
+ EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5), *p6);
+
+ auto p7 = make_unique<std::tuple<int, int, int, int, int, int, int>>(
+ 0, 1, 2, 3, 4, 5, 6);
+ EXPECT_TRUE((bool)p7);
+ EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6), *p7);
+
+ auto p8 = make_unique<std::tuple<int, int, int, int, int, int, int, int>>(
+ 0, 1, 2, 3, 4, 5, 6, 7);
+ EXPECT_TRUE((bool)p8);
+ EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7), *p8);
+
+ auto p9 =
+ make_unique<std::tuple<int, int, int, int, int, int, int, int, int>>(
+ 0, 1, 2, 3, 4, 5, 6, 7, 8);
+ EXPECT_TRUE((bool)p9);
+ EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8), *p9);
+
+ auto p10 =
+ make_unique<std::tuple<int, int, int, int, int, int, int, int, int, int>>(
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+ EXPECT_TRUE((bool)p10);
+ EXPECT_EQ(std::make_tuple(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), *p10);
+}
+
+TEST(MakeUniqueTest, Array) {
+ auto p1 = make_unique<int[]>(2);
+ EXPECT_TRUE((bool)p1);
+ EXPECT_EQ(0, p1[0]);
+ EXPECT_EQ(0, p1[1]);
+}
+}
diff --git a/unittests/ADT/OptionalTest.cpp b/unittests/ADT/OptionalTest.cpp
index 21e3847..2da408c 100644
--- a/unittests/ADT/OptionalTest.cpp
+++ b/unittests/ADT/OptionalTest.cpp
@@ -169,7 +169,6 @@ TEST_F(OptionalTest, NullCopyConstructionTest) {
EXPECT_EQ(0u, NonDefaultConstructible::Destructions);
}
-#if LLVM_HAS_RVALUE_REFERENCES
struct MoveOnly {
static unsigned MoveConstructions;
static unsigned Destructions;
@@ -278,7 +277,6 @@ TEST_F(OptionalTest, MoveOnlyAssigningAssignment) {
EXPECT_EQ(1u, MoveOnly::MoveAssignments);
EXPECT_EQ(1u, MoveOnly::Destructions);
}
-#endif
} // end anonymous namespace
diff --git a/unittests/ADT/OwningPtrTest.cpp b/unittests/ADT/OwningPtrTest.cpp
new file mode 100644
index 0000000..aee955b
--- /dev/null
+++ b/unittests/ADT/OwningPtrTest.cpp
@@ -0,0 +1,273 @@
+//===- llvm/unittest/ADT/OwningPtrTest.cpp - OwningPtr 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/OwningPtr.h"
+#include "gtest/gtest.h"
+using namespace llvm;
+
+namespace {
+
+struct TrackDestructor {
+ static unsigned Destructions;
+ int val;
+ explicit TrackDestructor(int val) : val(val) {}
+ ~TrackDestructor() { ++Destructions; }
+ static void ResetCounts() { Destructions = 0; }
+
+private:
+ TrackDestructor(const TrackDestructor &other) LLVM_DELETED_FUNCTION;
+ TrackDestructor &
+ operator=(const TrackDestructor &other) LLVM_DELETED_FUNCTION;
+ TrackDestructor(TrackDestructor &&other) LLVM_DELETED_FUNCTION;
+ TrackDestructor &operator=(TrackDestructor &&other) LLVM_DELETED_FUNCTION;
+};
+
+unsigned TrackDestructor::Destructions = 0;
+
+// Test fixture
+class OwningPtrTest : public testing::Test {};
+
+TEST_F(OwningPtrTest, DefaultConstruction) {
+ TrackDestructor::ResetCounts();
+ {
+ OwningPtr<TrackDestructor> O;
+ EXPECT_FALSE(O);
+ EXPECT_TRUE(!O);
+ EXPECT_FALSE(O.get());
+ EXPECT_FALSE(O.isValid());
+ }
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, PtrConstruction) {
+ TrackDestructor::ResetCounts();
+ {
+ OwningPtr<TrackDestructor> O(new TrackDestructor(3));
+ EXPECT_TRUE((bool)O);
+ EXPECT_FALSE(!O);
+ EXPECT_TRUE(O.get());
+ EXPECT_TRUE(O.isValid());
+ EXPECT_EQ(3, (*O).val);
+ EXPECT_EQ(3, O->val);
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ }
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, Reset) {
+ TrackDestructor::ResetCounts();
+ OwningPtr<TrackDestructor> O(new TrackDestructor(3));
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ O.reset();
+ EXPECT_FALSE((bool)O);
+ EXPECT_TRUE(!O);
+ EXPECT_FALSE(O.get());
+ EXPECT_FALSE(O.isValid());
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, Take) {
+ TrackDestructor::ResetCounts();
+ TrackDestructor *T = 0;
+ {
+ OwningPtr<TrackDestructor> O(new TrackDestructor(3));
+ T = O.take();
+ EXPECT_FALSE((bool)O);
+ EXPECT_TRUE(!O);
+ EXPECT_FALSE(O.get());
+ EXPECT_FALSE(O.isValid());
+ EXPECT_TRUE(T);
+ EXPECT_EQ(3, T->val);
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ }
+ delete T;
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, Release) {
+ TrackDestructor::ResetCounts();
+ TrackDestructor *T = 0;
+ {
+ OwningPtr<TrackDestructor> O(new TrackDestructor(3));
+ T = O.release();
+ EXPECT_FALSE((bool)O);
+ EXPECT_TRUE(!O);
+ EXPECT_FALSE(O.get());
+ EXPECT_FALSE(O.isValid());
+ EXPECT_TRUE(T);
+ EXPECT_EQ(3, T->val);
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ }
+ delete T;
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, MoveConstruction) {
+ TrackDestructor::ResetCounts();
+ {
+ OwningPtr<TrackDestructor> A(new TrackDestructor(3));
+ OwningPtr<TrackDestructor> B = std::move(A);
+ EXPECT_FALSE((bool)A);
+ EXPECT_TRUE(!A);
+ EXPECT_FALSE(A.get());
+ EXPECT_FALSE(A.isValid());
+ EXPECT_TRUE((bool)B);
+ EXPECT_FALSE(!B);
+ EXPECT_TRUE(B.get());
+ EXPECT_TRUE(B.isValid());
+ EXPECT_EQ(3, (*B).val);
+ EXPECT_EQ(3, B->val);
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ }
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, MoveAssignment) {
+ TrackDestructor::ResetCounts();
+ {
+ OwningPtr<TrackDestructor> A(new TrackDestructor(3));
+ OwningPtr<TrackDestructor> B(new TrackDestructor(4));
+ B = std::move(A);
+ EXPECT_FALSE(A);
+ EXPECT_TRUE(!A);
+ EXPECT_FALSE(A.get());
+ EXPECT_FALSE(A.isValid());
+ EXPECT_TRUE((bool)B);
+ EXPECT_FALSE(!B);
+ EXPECT_TRUE(B.get());
+ EXPECT_TRUE(B.isValid());
+ EXPECT_EQ(3, (*B).val);
+ EXPECT_EQ(3, B->val);
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+ }
+ EXPECT_EQ(2u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, Swap) {
+ TrackDestructor::ResetCounts();
+ {
+ OwningPtr<TrackDestructor> A(new TrackDestructor(3));
+ OwningPtr<TrackDestructor> B(new TrackDestructor(4));
+ B.swap(A);
+ EXPECT_TRUE((bool)A);
+ EXPECT_FALSE(!A);
+ EXPECT_TRUE(A.get());
+ EXPECT_TRUE(A.isValid());
+ EXPECT_EQ(4, (*A).val);
+ EXPECT_EQ(4, A->val);
+ EXPECT_TRUE((bool)B);
+ EXPECT_FALSE(!B);
+ EXPECT_TRUE(B.get());
+ EXPECT_TRUE(B.isValid());
+ EXPECT_EQ(3, (*B).val);
+ EXPECT_EQ(3, B->val);
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ }
+ EXPECT_EQ(2u, TrackDestructor::Destructions);
+ TrackDestructor::ResetCounts();
+ {
+ OwningPtr<TrackDestructor> A(new TrackDestructor(3));
+ OwningPtr<TrackDestructor> B(new TrackDestructor(4));
+ swap(A, B);
+ EXPECT_TRUE((bool)A);
+ EXPECT_FALSE(!A);
+ EXPECT_TRUE(A.get());
+ EXPECT_TRUE(A.isValid());
+ EXPECT_EQ(4, (*A).val);
+ EXPECT_EQ(4, A->val);
+ EXPECT_TRUE((bool)B);
+ EXPECT_FALSE(!B);
+ EXPECT_TRUE(B.get());
+ EXPECT_TRUE(B.isValid());
+ EXPECT_EQ(3, (*B).val);
+ EXPECT_EQ(3, B->val);
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ }
+ EXPECT_EQ(2u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, UniqueToOwningConstruction) {
+ TrackDestructor::ResetCounts();
+ {
+ std::unique_ptr<TrackDestructor> A(new TrackDestructor(3));
+ OwningPtr<TrackDestructor> B = std::move(A);
+ EXPECT_FALSE(A);
+ EXPECT_TRUE(!A);
+ EXPECT_FALSE(A.get());
+ EXPECT_TRUE((bool)B);
+ EXPECT_FALSE(!B);
+ EXPECT_TRUE(B.get());
+ EXPECT_TRUE(B.isValid());
+ EXPECT_EQ(3, (*B).val);
+ EXPECT_EQ(3, B->val);
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ }
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, UniqueToOwningAssignment) {
+ TrackDestructor::ResetCounts();
+ {
+ std::unique_ptr<TrackDestructor> A(new TrackDestructor(3));
+ OwningPtr<TrackDestructor> B(new TrackDestructor(4));
+ B = std::move(A);
+ EXPECT_FALSE(A);
+ EXPECT_TRUE(!A);
+ EXPECT_FALSE(A.get());
+ EXPECT_TRUE((bool)B);
+ EXPECT_FALSE(!B);
+ EXPECT_TRUE(B.get());
+ EXPECT_TRUE(B.isValid());
+ EXPECT_EQ(3, (*B).val);
+ EXPECT_EQ(3, B->val);
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+ }
+ EXPECT_EQ(2u, TrackDestructor::Destructions);
+}
+
+TEST_F(OwningPtrTest, TakeUniqueConstruction) {
+ TrackDestructor::ResetCounts();
+ {
+ OwningPtr<TrackDestructor> A(new TrackDestructor(3));
+ std::unique_ptr<TrackDestructor> B = A.take_unique();
+ EXPECT_FALSE(A);
+ EXPECT_TRUE(!A);
+ EXPECT_FALSE(A.get());
+ EXPECT_FALSE(A.isValid());
+ EXPECT_TRUE((bool)B);
+ EXPECT_FALSE(!B);
+ EXPECT_TRUE(B.get());
+ EXPECT_EQ(3, (*B).val);
+ EXPECT_EQ(3, B->val);
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ }
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+}
+
+#if LLVM_HAS_RVALUE_REFERENCE_THIS
+TEST_F(OwningPtrTest, OwningToUniqueConstruction) {
+ TrackDestructor::ResetCounts();
+ {
+ OwningPtr<TrackDestructor> A(new TrackDestructor(3));
+ std::unique_ptr<TrackDestructor> B = std::move(A);
+ EXPECT_FALSE(A);
+ EXPECT_TRUE(!A);
+ EXPECT_FALSE(A.get());
+ EXPECT_FALSE(A.isValid());
+ EXPECT_TRUE((bool)B);
+ EXPECT_FALSE(!B);
+ EXPECT_TRUE(B.get());
+ EXPECT_EQ(3, (*B).val);
+ EXPECT_EQ(3, B->val);
+ EXPECT_EQ(0u, TrackDestructor::Destructions);
+ }
+ EXPECT_EQ(1u, TrackDestructor::Destructions);
+}
+#endif
+}
diff --git a/unittests/ADT/PointerIntPairTest.cpp b/unittests/ADT/PointerIntPairTest.cpp
new file mode 100644
index 0000000..296d475
--- /dev/null
+++ b/unittests/ADT/PointerIntPairTest.cpp
@@ -0,0 +1,76 @@
+//===- llvm/unittest/ADT/PointerIntPairTest.cpp - 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/PointerIntPair.h"
+#include <limits>
+using namespace llvm;
+
+namespace {
+
+// Test fixture
+class PointerIntPairTest : public testing::Test {
+};
+
+TEST_F(PointerIntPairTest, GetSet) {
+ PointerIntPair<PointerIntPairTest *, 2> Pair(this, 1U);
+ EXPECT_EQ(this, Pair.getPointer());
+ EXPECT_EQ(1U, Pair.getInt());
+
+ Pair.setInt(2);
+ EXPECT_EQ(this, Pair.getPointer());
+ EXPECT_EQ(2U, Pair.getInt());
+
+ Pair.setPointer(nullptr);
+ EXPECT_EQ(nullptr, Pair.getPointer());
+ EXPECT_EQ(2U, Pair.getInt());
+
+ Pair.setPointerAndInt(this, 3U);
+ EXPECT_EQ(this, Pair.getPointer());
+ EXPECT_EQ(3U, Pair.getInt());
+}
+
+TEST_F(PointerIntPairTest, DefaultInitialize) {
+ PointerIntPair<PointerIntPairTest *, 2> Pair;
+ EXPECT_EQ(nullptr, Pair.getPointer());
+ EXPECT_EQ(0U, Pair.getInt());
+}
+
+#if !(defined(_MSC_VER) && _MSC_VER==1700)
+TEST_F(PointerIntPairTest, ManyUnusedBits) {
+ // In real code this would be a word-sized integer limited to 31 bits.
+ struct Fixnum31 {
+ uintptr_t Value;
+ };
+ class FixnumPointerTraits {
+ public:
+ static inline void *getAsVoidPointer(Fixnum31 Num) {
+ return reinterpret_cast<void *>(Num.Value << NumLowBitsAvailable);
+ }
+ static inline Fixnum31 getFromVoidPointer(void *P) {
+ // In real code this would assert that the value is in range.
+ return { reinterpret_cast<uintptr_t>(P) >> NumLowBitsAvailable };
+ }
+ enum { NumLowBitsAvailable = std::numeric_limits<uintptr_t>::digits - 31 };
+ };
+
+ PointerIntPair<Fixnum31, 1, bool, FixnumPointerTraits> pair;
+ EXPECT_EQ((uintptr_t)0, pair.getPointer().Value);
+ EXPECT_FALSE(pair.getInt());
+
+ pair.setPointerAndInt({ 0x7FFFFFFF }, true );
+ EXPECT_EQ((uintptr_t)0x7FFFFFFF, pair.getPointer().Value);
+ EXPECT_TRUE(pair.getInt());
+
+ EXPECT_EQ(FixnumPointerTraits::NumLowBitsAvailable - 1,
+ PointerLikeTypeTraits<decltype(pair)>::NumLowBitsAvailable);
+}
+#endif
+
+} // end anonymous namespace
diff --git a/unittests/ADT/SmallPtrSetTest.cpp b/unittests/ADT/SmallPtrSetTest.cpp
index f85d7c9..fdd1cbb 100644
--- a/unittests/ADT/SmallPtrSetTest.cpp
+++ b/unittests/ADT/SmallPtrSetTest.cpp
@@ -16,7 +16,30 @@
using namespace llvm;
-// SmallPtrSet swapping test.
+TEST(SmallPtrSetTest, Assignment) {
+ int buf[8];
+ for (int i = 0; i < 8; ++i)
+ buf[i] = 0;
+
+ SmallPtrSet<int *, 4> s1;
+ s1.insert(&buf[0]);
+ s1.insert(&buf[1]);
+
+ SmallPtrSet<int *, 4> s2;
+ (s2 = s1).insert(&buf[2]);
+
+ // Self assign as well.
+ (s2 = s2).insert(&buf[3]);
+
+ s1 = s2;
+ EXPECT_EQ(4U, s1.size());
+ for (int i = 0; i < 8; ++i)
+ if (i < 4)
+ EXPECT_TRUE(s1.count(&buf[i]));
+ else
+ EXPECT_FALSE(s1.count(&buf[i]));
+}
+
TEST(SmallPtrSetTest, GrowthTest) {
int i;
int buf[8];
@@ -71,6 +94,68 @@ TEST(SmallPtrSetTest, GrowthTest) {
EXPECT_EQ(1,buf[i]);
}
+TEST(SmallPtrSetTest, CopyAndMoveTest) {
+ int buf[8];
+ for (int i = 0; i < 8; ++i)
+ buf[i] = 0;
+
+ SmallPtrSet<int *, 4> s1;
+ s1.insert(&buf[0]);
+ s1.insert(&buf[1]);
+ s1.insert(&buf[2]);
+ s1.insert(&buf[3]);
+ EXPECT_EQ(4U, s1.size());
+ for (int i = 0; i < 8; ++i)
+ if (i < 4)
+ EXPECT_TRUE(s1.count(&buf[i]));
+ else
+ EXPECT_FALSE(s1.count(&buf[i]));
+
+ SmallPtrSet<int *, 4> s2(s1);
+ EXPECT_EQ(4U, s2.size());
+ for (int i = 0; i < 8; ++i)
+ if (i < 4)
+ EXPECT_TRUE(s2.count(&buf[i]));
+ else
+ EXPECT_FALSE(s2.count(&buf[i]));
+
+ s1 = s2;
+ EXPECT_EQ(4U, s1.size());
+ EXPECT_EQ(4U, s2.size());
+ for (int i = 0; i < 8; ++i)
+ if (i < 4)
+ EXPECT_TRUE(s1.count(&buf[i]));
+ else
+ EXPECT_FALSE(s1.count(&buf[i]));
+
+ SmallPtrSet<int *, 4> s3(std::move(s1));
+ EXPECT_EQ(4U, s3.size());
+ EXPECT_TRUE(s1.empty());
+ for (int i = 0; i < 8; ++i)
+ if (i < 4)
+ EXPECT_TRUE(s3.count(&buf[i]));
+ else
+ EXPECT_FALSE(s3.count(&buf[i]));
+
+ // Move assign into the moved-from object. Also test move of a non-small
+ // container.
+ s3.insert(&buf[4]);
+ s3.insert(&buf[5]);
+ s3.insert(&buf[6]);
+ s3.insert(&buf[7]);
+ s1 = std::move(s3);
+ EXPECT_EQ(8U, s1.size());
+ EXPECT_TRUE(s3.empty());
+ for (int i = 0; i < 8; ++i)
+ EXPECT_TRUE(s1.count(&buf[i]));
+
+ // Copy assign into a moved-from object.
+ s3 = s1;
+ EXPECT_EQ(8U, s3.size());
+ EXPECT_EQ(8U, s1.size());
+ for (int i = 0; i < 8; ++i)
+ EXPECT_TRUE(s3.count(&buf[i]));
+}
TEST(SmallPtrSetTest, SwapTest) {
int buf[10];
diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp
index 5bb65cb..b6d41bc 100644
--- a/unittests/ADT/StringMapTest.cpp
+++ b/unittests/ADT/StringMapTest.cpp
@@ -183,23 +183,6 @@ TEST_F(StringMapTest, IterationTest) {
}
}
-} // end anonymous namespace
-
-namespace llvm {
-
-template <>
-class StringMapEntryInitializer<uint32_t> {
-public:
- template <typename InitTy>
- static void Initialize(StringMapEntry<uint32_t> &T, InitTy InitVal) {
- T.second = InitVal;
- }
-};
-
-} // end llvm namespace
-
-namespace {
-
// Test StringMapEntry::Create() method.
TEST_F(StringMapTest, StringMapEntryTest) {
StringMap<uint32_t>::value_type* entry =
@@ -220,4 +203,19 @@ TEST_F(StringMapTest, InsertTest) {
assertSingleItemMap();
}
+// Create a non-default constructable value
+struct StringMapTestStruct {
+ StringMapTestStruct(int i) : i(i) {}
+ StringMapTestStruct() LLVM_DELETED_FUNCTION;
+ int i;
+};
+
+TEST_F(StringMapTest, NonDefaultConstructable) {
+ StringMap<StringMapTestStruct> t;
+ t.GetOrCreateValue("Test", StringMapTestStruct(123));
+ StringMap<StringMapTestStruct>::iterator iter = t.find("Test");
+ ASSERT_NE(iter, t.end());
+ ASSERT_EQ(iter->second.i, 123);
+}
+
} // end anonymous namespace
diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp
index 88691ae..c7fd9d0 100644
--- a/unittests/ADT/StringRefTest.cpp
+++ b/unittests/ADT/StringRefTest.cpp
@@ -8,9 +8,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Allocator.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -531,4 +532,18 @@ TEST(StringRefTest, joinStrings) {
EXPECT_TRUE(v2_join3);
}
+
+TEST(StringRefTest, AllocatorCopy) {
+ BumpPtrAllocator Alloc;
+ StringRef Str1 = "hello";
+ StringRef Str2 = "bye";
+ StringRef Str1c = Str1.copy(Alloc);
+ StringRef Str2c = Str2.copy(Alloc);
+ EXPECT_TRUE(Str1.equals(Str1c));
+ EXPECT_NE(Str1.data(), Str1c.data());
+ EXPECT_TRUE(Str2.equals(Str2c));
+ EXPECT_NE(Str2.data(), Str2c.data());
+}
+
+
} // end anonymous namespace
diff --git a/unittests/ADT/TinyPtrVectorTest.cpp b/unittests/ADT/TinyPtrVectorTest.cpp
index a4f92ff..ec868d4 100644
--- a/unittests/ADT/TinyPtrVectorTest.cpp
+++ b/unittests/ADT/TinyPtrVectorTest.cpp
@@ -36,7 +36,7 @@ template <typename VectorT>
class TinyPtrVectorTest : public testing::Test {
protected:
typedef typename VectorT::value_type PtrT;
- typedef typename remove_pointer<PtrT>::type ValueT;
+ typedef typename std::remove_pointer<PtrT>::type ValueT;
VectorT V;
VectorT V2;
@@ -72,9 +72,9 @@ protected:
EXPECT_EQ(Values.size(), V.size());
for (size_t i = 0, e = Values.size(); i != e; ++i) {
EXPECT_EQ(Values[i], V[i]);
- EXPECT_EQ(Values[i], *llvm::next(V.begin(), i));
+ EXPECT_EQ(Values[i], *std::next(V.begin(), i));
}
- EXPECT_EQ(V.end(), llvm::next(V.begin(), Values.size()));
+ EXPECT_EQ(V.end(), std::next(V.begin(), Values.size()));
}
};
@@ -157,170 +157,136 @@ TYPED_TEST(TinyPtrVectorTest, CopyAndMoveCtorTest) {
this->expectValues(Copy2, this->testArray(42));
this->expectValues(this->V2, this->testArray(0));
-#if LLVM_HAS_RVALUE_REFERENCES
TypeParam Move(std::move(Copy2));
this->expectValues(Move, this->testArray(42));
this->expectValues(Copy2, this->testArray(0));
-#endif
}
TYPED_TEST(TinyPtrVectorTest, CopyAndMoveTest) {
this->V = this->V2;
this->expectValues(this->V, this->testArray(0));
this->expectValues(this->V2, this->testArray(0));
-#if LLVM_HAS_RVALUE_REFERENCES
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(0));
-#endif
this->setVectors(this->testArray(1), this->testArray(0));
this->V = this->V2;
this->expectValues(this->V, this->testArray(0));
this->expectValues(this->V2, this->testArray(0));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(1), this->testArray(0));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(0));
-#endif
this->setVectors(this->testArray(2), this->testArray(0));
this->V = this->V2;
this->expectValues(this->V, this->testArray(0));
this->expectValues(this->V2, this->testArray(0));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(2), this->testArray(0));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(0));
-#endif
this->setVectors(this->testArray(42), this->testArray(0));
this->V = this->V2;
this->expectValues(this->V, this->testArray(0));
this->expectValues(this->V2, this->testArray(0));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(42), this->testArray(0));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(0));
-#endif
this->setVectors(this->testArray(0), this->testArray(1));
this->V = this->V2;
this->expectValues(this->V, this->testArray(1));
this->expectValues(this->V2, this->testArray(1));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(0), this->testArray(1));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(1));
-#endif
this->setVectors(this->testArray(0), this->testArray(2));
this->V = this->V2;
this->expectValues(this->V, this->testArray(2));
this->expectValues(this->V2, this->testArray(2));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(0), this->testArray(2));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(2));
-#endif
this->setVectors(this->testArray(0), this->testArray(42));
this->V = this->V2;
this->expectValues(this->V, this->testArray(42));
this->expectValues(this->V2, this->testArray(42));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(0), this->testArray(42));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(42));
-#endif
this->setVectors(this->testArray(1), this->testArray(1));
this->V = this->V2;
this->expectValues(this->V, this->testArray(1));
this->expectValues(this->V2, this->testArray(1));
-#if LLVM_HAS_RVALUE_REFERENCES
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(1));
-#endif
this->setVectors(this->testArray(1), this->testArray(2));
this->V = this->V2;
this->expectValues(this->V, this->testArray(2));
this->expectValues(this->V2, this->testArray(2));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(1), this->testArray(2));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(2));
-#endif
this->setVectors(this->testArray(1), this->testArray(42));
this->V = this->V2;
this->expectValues(this->V, this->testArray(42));
this->expectValues(this->V2, this->testArray(42));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(1), this->testArray(42));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(42));
-#endif
this->setVectors(this->testArray(2), this->testArray(1));
this->V = this->V2;
this->expectValues(this->V, this->testArray(1));
this->expectValues(this->V2, this->testArray(1));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(2), this->testArray(1));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(1));
-#endif
this->setVectors(this->testArray(2), this->testArray(2));
this->V = this->V2;
this->expectValues(this->V, this->testArray(2));
this->expectValues(this->V2, this->testArray(2));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(2), this->testArray(2));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(2));
-#endif
this->setVectors(this->testArray(2), this->testArray(42));
this->V = this->V2;
this->expectValues(this->V, this->testArray(42));
this->expectValues(this->V2, this->testArray(42));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(2), this->testArray(42));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(42));
-#endif
this->setVectors(this->testArray(42), this->testArray(1));
this->V = this->V2;
this->expectValues(this->V, this->testArray(1));
this->expectValues(this->V2, this->testArray(1));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(42), this->testArray(1));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(1));
-#endif
this->setVectors(this->testArray(42), this->testArray(2));
this->V = this->V2;
this->expectValues(this->V, this->testArray(2));
this->expectValues(this->V2, this->testArray(2));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(42), this->testArray(2));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(2));
-#endif
this->setVectors(this->testArray(42), this->testArray(42));
this->V = this->V2;
this->expectValues(this->V, this->testArray(42));
this->expectValues(this->V2, this->testArray(42));
-#if LLVM_HAS_RVALUE_REFERENCES
this->setVectors(this->testArray(42), this->testArray(42));
this->V = std::move(this->V2);
this->expectValues(this->V, this->testArray(42));
-#endif
}
TYPED_TEST(TinyPtrVectorTest, EraseTest) {
@@ -334,17 +300,17 @@ TYPED_TEST(TinyPtrVectorTest, EraseTest) {
this->V.erase(this->V.begin());
this->TestPtrs.erase(this->TestPtrs.begin());
this->expectValues(this->V, this->testArray(41));
- this->V.erase(llvm::next(this->V.begin(), 1));
- this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 1));
+ this->V.erase(std::next(this->V.begin(), 1));
+ this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 1));
this->expectValues(this->V, this->testArray(40));
- this->V.erase(llvm::next(this->V.begin(), 2));
- this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 2));
+ this->V.erase(std::next(this->V.begin(), 2));
+ this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 2));
this->expectValues(this->V, this->testArray(39));
- this->V.erase(llvm::next(this->V.begin(), 5));
- this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 5));
+ this->V.erase(std::next(this->V.begin(), 5));
+ this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 5));
this->expectValues(this->V, this->testArray(38));
- this->V.erase(llvm::next(this->V.begin(), 13));
- this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 13));
+ this->V.erase(std::next(this->V.begin(), 13));
+ this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 13));
this->expectValues(this->V, this->testArray(37));
typename TypeParam::iterator I = this->V.begin();
@@ -366,27 +332,27 @@ TYPED_TEST(TinyPtrVectorTest, EraseRangeTest) {
this->appendValues(this->V, this->testArray(42));
this->expectValues(this->V, this->testArray(42));
- this->V.erase(this->V.begin(), llvm::next(this->V.begin(), 1));
+ this->V.erase(this->V.begin(), std::next(this->V.begin(), 1));
this->TestPtrs.erase(this->TestPtrs.begin(),
- llvm::next(this->TestPtrs.begin(), 1));
+ std::next(this->TestPtrs.begin(), 1));
this->expectValues(this->V, this->testArray(41));
- this->V.erase(llvm::next(this->V.begin(), 1), llvm::next(this->V.begin(), 2));
- this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 1),
- llvm::next(this->TestPtrs.begin(), 2));
+ this->V.erase(std::next(this->V.begin(), 1), std::next(this->V.begin(), 2));
+ this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 1),
+ std::next(this->TestPtrs.begin(), 2));
this->expectValues(this->V, this->testArray(40));
- this->V.erase(llvm::next(this->V.begin(), 2), llvm::next(this->V.begin(), 4));
- this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 2),
- llvm::next(this->TestPtrs.begin(), 4));
+ this->V.erase(std::next(this->V.begin(), 2), std::next(this->V.begin(), 4));
+ this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 2),
+ std::next(this->TestPtrs.begin(), 4));
this->expectValues(this->V, this->testArray(38));
- this->V.erase(llvm::next(this->V.begin(), 5), llvm::next(this->V.begin(), 10));
- this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 5),
- llvm::next(this->TestPtrs.begin(), 10));
+ this->V.erase(std::next(this->V.begin(), 5), std::next(this->V.begin(), 10));
+ this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 5),
+ std::next(this->TestPtrs.begin(), 10));
this->expectValues(this->V, this->testArray(33));
- this->V.erase(llvm::next(this->V.begin(), 13), llvm::next(this->V.begin(), 26));
- this->TestPtrs.erase(llvm::next(this->TestPtrs.begin(), 13),
- llvm::next(this->TestPtrs.begin(), 26));
+ this->V.erase(std::next(this->V.begin(), 13), std::next(this->V.begin(), 26));
+ this->TestPtrs.erase(std::next(this->TestPtrs.begin(), 13),
+ std::next(this->TestPtrs.begin(), 26));
this->expectValues(this->V, this->testArray(20));
- this->V.erase(llvm::next(this->V.begin(), 7), this->V.end());
+ this->V.erase(std::next(this->V.begin(), 7), this->V.end());
this->expectValues(this->V, this->testArray(7));
this->V.erase(this->V.begin(), this->V.end());
this->expectValues(this->V, this->testArray(0));
@@ -403,8 +369,8 @@ TYPED_TEST(TinyPtrVectorTest, Insert) {
this->V.insert(this->V.begin(), this->TestPtrs[42]);
this->TestPtrs.insert(this->TestPtrs.begin(), this->TestPtrs[42]);
this->expectValues(this->V, this->testArray(6));
- this->V.insert(llvm::next(this->V.begin(), 3), this->TestPtrs[43]);
- this->TestPtrs.insert(llvm::next(this->TestPtrs.begin(), 3),
+ this->V.insert(std::next(this->V.begin(), 3), this->TestPtrs[43]);
+ this->TestPtrs.insert(std::next(this->TestPtrs.begin(), 3),
this->TestPtrs[43]);
this->expectValues(this->V, this->testArray(7));
}
@@ -418,30 +384,30 @@ TYPED_TEST(TinyPtrVectorTest, InsertRange) {
this->V.insert(this->V.end(), this->TestPtrs.end(), this->TestPtrs.end());
this->expectValues(this->V, this->testArray(0));
this->V.insert(this->V.end(), this->TestPtrs.begin(),
- llvm::next(this->TestPtrs.begin()));
+ std::next(this->TestPtrs.begin()));
this->expectValues(this->V, this->testArray(1));
this->V.clear();
this->V.insert(this->V.end(), this->TestPtrs.begin(),
- llvm::next(this->TestPtrs.begin(), 2));
+ std::next(this->TestPtrs.begin(), 2));
this->expectValues(this->V, this->testArray(2));
this->V.clear();
this->V.insert(this->V.end(), this->TestPtrs.begin(),
- llvm::next(this->TestPtrs.begin(), 42));
+ std::next(this->TestPtrs.begin(), 42));
this->expectValues(this->V, this->testArray(42));
this->V.clear();
this->V.insert(this->V.end(),
- llvm::next(this->TestPtrs.begin(), 5),
- llvm::next(this->TestPtrs.begin(), 13));
+ std::next(this->TestPtrs.begin(), 5),
+ std::next(this->TestPtrs.begin(), 13));
this->V.insert(this->V.begin(),
- llvm::next(this->TestPtrs.begin(), 0),
- llvm::next(this->TestPtrs.begin(), 3));
- this->V.insert(llvm::next(this->V.begin(), 2),
- llvm::next(this->TestPtrs.begin(), 2),
- llvm::next(this->TestPtrs.begin(), 4));
- this->V.erase(llvm::next(this->V.begin(), 4));
- this->V.insert(llvm::next(this->V.begin(), 4),
- llvm::next(this->TestPtrs.begin(), 4),
- llvm::next(this->TestPtrs.begin(), 5));
+ std::next(this->TestPtrs.begin(), 0),
+ std::next(this->TestPtrs.begin(), 3));
+ this->V.insert(std::next(this->V.begin(), 2),
+ std::next(this->TestPtrs.begin(), 2),
+ std::next(this->TestPtrs.begin(), 4));
+ this->V.erase(std::next(this->V.begin(), 4));
+ this->V.insert(std::next(this->V.begin(), 4),
+ std::next(this->TestPtrs.begin(), 4),
+ std::next(this->TestPtrs.begin(), 5));
this->expectValues(this->V, this->testArray(13));
}
diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp
index b402896..2e9d585 100644
--- a/unittests/ADT/TripleTest.cpp
+++ b/unittests/ADT/TripleTest.cpp
@@ -190,6 +190,9 @@ 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)
+ continue;
+
C[2] = Triple::getOSTypeName(Triple::OSType(OS));
std::string E = Join(C[0], C[1], C[2]);
@@ -201,7 +204,7 @@ TEST(TripleTest, Normalization) {
EXPECT_EQ(E, Triple::normalize(Join(C[2], C[0], C[1])));
EXPECT_EQ(E, Triple::normalize(Join(C[2], C[1], C[0])));
- for (int Env = 1+Triple::UnknownEnvironment; Env <= Triple::MachO;
+ for (int Env = 1 + Triple::UnknownEnvironment; Env <= Triple::Android;
++Env) {
C[3] = Triple::getEnvironmentTypeName(Triple::EnvironmentType(Env));
@@ -238,7 +241,7 @@ TEST(TripleTest, Normalization) {
// Various real-world funky triples. The value returned by GCC's config.sub
// is given in the comment.
- EXPECT_EQ("i386--mingw32", Triple::normalize("i386-mingw32")); // i386-pc-mingw32
+ EXPECT_EQ("i386--windows-gnu", Triple::normalize("i386-mingw32")); // i386-pc-mingw32
EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-linux-gnu")); // x86_64-pc-linux-gnu
EXPECT_EQ("i486--linux-gnu", Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
EXPECT_EQ("i386-redhat-linux", Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
@@ -349,10 +352,6 @@ TEST(TripleTest, BitWidthArchVariants) {
EXPECT_EQ(Triple::UnknownArch, T.get32BitArchVariant().getArch());
EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
- T.setArch(Triple::arm);
- EXPECT_EQ(Triple::arm, T.get32BitArchVariant().getArch());
- EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch());
-
T.setArch(Triple::mips);
EXPECT_EQ(Triple::mips, T.get32BitArchVariant().getArch());
EXPECT_EQ(Triple::mips64, T.get64BitArchVariant().getArch());
@@ -417,7 +416,7 @@ TEST(TripleTest, getOSVersion) {
EXPECT_EQ((unsigned)5, Minor);
EXPECT_EQ((unsigned)0, Micro);
T.getiOSVersion(Major, Minor, Micro);
- EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)5, Major);
EXPECT_EQ((unsigned)0, Minor);
EXPECT_EQ((unsigned)0, Micro);
@@ -432,7 +431,7 @@ TEST(TripleTest, getOSVersion) {
EXPECT_EQ((unsigned)5, Minor);
EXPECT_EQ((unsigned)0, Micro);
T.getiOSVersion(Major, Minor, Micro);
- EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)5, Major);
EXPECT_EQ((unsigned)0, Minor);
EXPECT_EQ((unsigned)0, Micro);
@@ -447,7 +446,7 @@ TEST(TripleTest, getOSVersion) {
EXPECT_EQ((unsigned)4, Minor);
EXPECT_EQ((unsigned)0, Micro);
T.getiOSVersion(Major, Minor, Micro);
- EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)5, Major);
EXPECT_EQ((unsigned)0, Minor);
EXPECT_EQ((unsigned)0, Micro);
@@ -462,7 +461,7 @@ TEST(TripleTest, getOSVersion) {
EXPECT_EQ((unsigned)7, Minor);
EXPECT_EQ((unsigned)0, Micro);
T.getiOSVersion(Major, Minor, Micro);
- EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)5, Major);
EXPECT_EQ((unsigned)0, Minor);
EXPECT_EQ((unsigned)0, Micro);
@@ -477,11 +476,11 @@ TEST(TripleTest, getOSVersion) {
EXPECT_EQ((unsigned)4, Minor);
EXPECT_EQ((unsigned)0, Micro);
T.getiOSVersion(Major, Minor, Micro);
- EXPECT_EQ((unsigned)3, Major);
+ EXPECT_EQ((unsigned)5, Major);
EXPECT_EQ((unsigned)0, Minor);
EXPECT_EQ((unsigned)0, Micro);
- T = Triple("armv7-apple-ios5.0");
+ T = Triple("armv7-apple-ios7.0");
EXPECT_FALSE(T.isMacOSX());
EXPECT_TRUE(T.isiOS());
EXPECT_FALSE(T.isArch16Bit());
@@ -492,9 +491,77 @@ TEST(TripleTest, getOSVersion) {
EXPECT_EQ((unsigned)4, Minor);
EXPECT_EQ((unsigned)0, Micro);
T.getiOSVersion(Major, Minor, Micro);
- EXPECT_EQ((unsigned)5, Major);
+ EXPECT_EQ((unsigned)7, Major);
EXPECT_EQ((unsigned)0, Minor);
EXPECT_EQ((unsigned)0, Micro);
}
+TEST(TripleTest, FileFormat) {
+ EXPECT_EQ(Triple::ELF, Triple("i686-unknown-linux-gnu").getObjectFormat());
+ EXPECT_EQ(Triple::ELF, Triple("i686-unknown-freebsd").getObjectFormat());
+ EXPECT_EQ(Triple::ELF, Triple("i686-unknown-netbsd").getObjectFormat());
+ EXPECT_EQ(Triple::ELF, Triple("i686--win32-elf").getObjectFormat());
+ EXPECT_EQ(Triple::ELF, Triple("i686---elf").getObjectFormat());
+
+ EXPECT_EQ(Triple::MachO, Triple("i686-apple-macosx").getObjectFormat());
+ EXPECT_EQ(Triple::MachO, Triple("i686-apple-ios").getObjectFormat());
+ EXPECT_EQ(Triple::MachO, Triple("i686---macho").getObjectFormat());
+
+ EXPECT_EQ(Triple::COFF, Triple("i686--win32").getObjectFormat());
+
+ EXPECT_EQ(Triple::ELF, Triple("i686-pc-windows-msvc-elf").getObjectFormat());
+ EXPECT_EQ(Triple::ELF, Triple("i686-pc-cygwin-elf").getObjectFormat());
+
+ Triple MSVCNormalized(Triple::normalize("i686-pc-windows-msvc-elf"));
+ EXPECT_EQ(Triple::ELF, MSVCNormalized.getObjectFormat());
+
+ Triple GNUWindowsNormalized(Triple::normalize("i686-pc-windows-gnu-elf"));
+ EXPECT_EQ(Triple::ELF, GNUWindowsNormalized.getObjectFormat());
+
+ Triple CygnusNormalised(Triple::normalize("i686-pc-windows-cygnus-elf"));
+ EXPECT_EQ(Triple::ELF, CygnusNormalised.getObjectFormat());
+
+ Triple CygwinNormalized(Triple::normalize("i686-pc-cygwin-elf"));
+ EXPECT_EQ(Triple::ELF, CygwinNormalized.getObjectFormat());
+
+ Triple T = Triple("");
+ T.setObjectFormat(Triple::ELF);
+ EXPECT_EQ(Triple::ELF, T.getObjectFormat());
+}
+
+TEST(TripleTest, NormalizeWindows) {
+ EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-win32"));
+ EXPECT_EQ("i686--windows-msvc", Triple::normalize("i686-win32"));
+ EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32"));
+ EXPECT_EQ("i686--windows-gnu", Triple::normalize("i686-mingw32"));
+ EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-mingw32-w64"));
+ EXPECT_EQ("i686--windows-gnu", Triple::normalize("i686-mingw32-w64"));
+ EXPECT_EQ("i686-pc-windows-cygnus", Triple::normalize("i686-pc-cygwin"));
+ EXPECT_EQ("i686--windows-cygnus", Triple::normalize("i686-cygwin"));
+
+ EXPECT_EQ("x86_64-pc-windows-msvc", Triple::normalize("x86_64-pc-win32"));
+ EXPECT_EQ("x86_64--windows-msvc", Triple::normalize("x86_64-win32"));
+ EXPECT_EQ("x86_64-pc-windows-gnu", Triple::normalize("x86_64-pc-mingw32"));
+ EXPECT_EQ("x86_64--windows-gnu", Triple::normalize("x86_64-mingw32"));
+ EXPECT_EQ("x86_64-pc-windows-gnu", Triple::normalize("x86_64-pc-mingw32-w64"));
+ EXPECT_EQ("x86_64--windows-gnu", Triple::normalize("x86_64-mingw32-w64"));
+
+ EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-win32-elf"));
+ EXPECT_EQ("i686--windows-elf", Triple::normalize("i686-win32-elf"));
+ EXPECT_EQ("i686-pc-windows-macho", Triple::normalize("i686-pc-win32-macho"));
+ EXPECT_EQ("i686--windows-macho", Triple::normalize("i686-win32-macho"));
+
+ EXPECT_EQ("x86_64-pc-windows-elf", Triple::normalize("x86_64-pc-win32-elf"));
+ EXPECT_EQ("x86_64--windows-elf", Triple::normalize("x86_64-win32-elf"));
+ EXPECT_EQ("x86_64-pc-windows-macho", Triple::normalize("x86_64-pc-win32-macho"));
+ EXPECT_EQ("x86_64--windows-macho", Triple::normalize("x86_64-win32-macho"));
+
+ EXPECT_EQ("i686-pc-windows-cygnus",
+ Triple::normalize("i686-pc-windows-cygnus"));
+ EXPECT_EQ("i686-pc-windows-gnu", Triple::normalize("i686-pc-windows-gnu"));
+ EXPECT_EQ("i686-pc-windows-itanium", Triple::normalize("i686-pc-windows-itanium"));
+ EXPECT_EQ("i686-pc-windows-msvc", Triple::normalize("i686-pc-windows-msvc"));
+
+ EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-windows-elf-elf"));
+}
}
diff --git a/unittests/ADT/ilistTest.cpp b/unittests/ADT/ilistTest.cpp
index 0c0cd0f..134607c 100644
--- a/unittests/ADT/ilistTest.cpp
+++ b/unittests/ADT/ilistTest.cpp
@@ -51,15 +51,15 @@ TEST(ilistTest, SpliceOne) {
List.splice(List.begin(), List, List.begin());
EXPECT_EQ(1u, List.size());
EXPECT_EQ(1, List.front().Value);
- EXPECT_TRUE(llvm::next(List.begin()) == List.end());
+ EXPECT_TRUE(std::next(List.begin()) == List.end());
// Altenative noop. Move the first element behind itself.
List.push_back(2);
List.push_back(3);
- List.splice(llvm::next(List.begin()), List, List.begin());
+ List.splice(std::next(List.begin()), List, List.begin());
EXPECT_EQ(3u, List.size());
EXPECT_EQ(1, List.front().Value);
- EXPECT_EQ(2, llvm::next(List.begin())->Value);
+ EXPECT_EQ(2, std::next(List.begin())->Value);
EXPECT_EQ(3, List.back().Value);
}
diff --git a/unittests/ADT/polymorphic_ptr_test.cpp b/unittests/ADT/polymorphic_ptr_test.cpp
deleted file mode 100644
index bd5d838..0000000
--- a/unittests/ADT/polymorphic_ptr_test.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-//===- llvm/unittest/ADT/polymorphic_ptr.h - polymorphic_ptr<T> 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/polymorphic_ptr.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace llvm;
-
-namespace {
-
-struct S {
- S(int x) : x(x) {}
- S *clone() { return new S(*this); }
- int x;
-};
-
-// A function that forces the return of a copy.
-template <typename T>
-T dummy_copy(const T &arg) { return arg; }
-
-TEST(polymorphic_ptr_test, Basic) {
- polymorphic_ptr<S> null;
- EXPECT_FALSE((bool)null);
- EXPECT_TRUE(!null);
- EXPECT_EQ((S*)0, null.get());
-
- S *s = new S(42);
- polymorphic_ptr<S> p(s);
- EXPECT_TRUE((bool)p);
- EXPECT_FALSE(!p);
- EXPECT_TRUE(p != null);
- EXPECT_FALSE(p == null);
- EXPECT_TRUE(p == s);
- EXPECT_TRUE(s == p);
- EXPECT_FALSE(p != s);
- EXPECT_FALSE(s != p);
- EXPECT_EQ(s, &*p);
- EXPECT_EQ(s, p.operator->());
- EXPECT_EQ(s, p.get());
- EXPECT_EQ(42, p->x);
-
- EXPECT_EQ(s, p.take());
- EXPECT_FALSE((bool)p);
- EXPECT_TRUE(!p);
- p = s;
- EXPECT_TRUE((bool)p);
- EXPECT_FALSE(!p);
- EXPECT_EQ(s, &*p);
- EXPECT_EQ(s, p.operator->());
- EXPECT_EQ(s, p.get());
- EXPECT_EQ(42, p->x);
-
- polymorphic_ptr<S> p2((llvm_move(p)));
-#if !LLVM_HAS_RVALUE_REFERENCES
- // 'p' may not have been moved from in C++98, fake it for the test.
- p2 = p.take();
-#endif
- EXPECT_FALSE((bool)p);
- EXPECT_TRUE(!p);
- EXPECT_TRUE((bool)p2);
- EXPECT_FALSE(!p2);
- EXPECT_EQ(s, &*p2);
-
- using std::swap;
- swap(p, p2);
- EXPECT_TRUE((bool)p);
- EXPECT_FALSE(!p);
- EXPECT_EQ(s, &*p);
- EXPECT_FALSE((bool)p2);
- EXPECT_TRUE(!p2);
-
- // Force copies and that everything survives.
- polymorphic_ptr<S> p3 = dummy_copy(polymorphic_ptr<S>(p));
- EXPECT_TRUE((bool)p3);
- EXPECT_FALSE(!p3);
- EXPECT_NE(s, &*p3);
- EXPECT_EQ(42, p3->x);
-
- // Force copies of null without trying to dereference anything.
- polymorphic_ptr<S> null_copy = dummy_copy(polymorphic_ptr<S>(null));
- EXPECT_FALSE((bool)null_copy);
- EXPECT_TRUE(!null_copy);
- EXPECT_EQ(null, null_copy);
-}
-
-struct Base {
- virtual ~Base() {}
- virtual Base *clone() = 0;
- virtual StringRef name() { return "Base"; }
-};
-
-struct DerivedA : Base {
- virtual DerivedA *clone() { return new DerivedA(); }
- virtual StringRef name() { return "DerivedA"; }
-};
-struct DerivedB : Base {
- virtual DerivedB *clone() { return new DerivedB(); }
- virtual StringRef name() { return "DerivedB"; }
-};
-
-TEST(polymorphic_ptr_test, Polymorphism) {
- polymorphic_ptr<Base> a(new DerivedA());
- polymorphic_ptr<Base> b(new DerivedB());
-
- EXPECT_EQ("DerivedA", a->name());
- EXPECT_EQ("DerivedB", b->name());
-
- polymorphic_ptr<Base> copy = dummy_copy(a);
- EXPECT_NE(a, copy);
- EXPECT_EQ("DerivedA", copy->name());
-
- copy = dummy_copy(b);
- EXPECT_NE(b, copy);
- EXPECT_EQ("DerivedB", copy->name());
-
- // Test creating a copy out of a temporary directly.
- copy = dummy_copy<polymorphic_ptr<Base> >(new DerivedA());
- EXPECT_NE(a, copy);
- EXPECT_EQ("DerivedA", copy->name());
-}
-
-}