diff options
author | Stephen Hines <srhines@google.com> | 2014-07-21 00:45:20 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-07-21 00:45:20 -0700 |
commit | c6a4f5e819217e1e12c458aed8e7b122e23a3a58 (patch) | |
tree | 81b7dd2bb4370a392f31d332a566c903b5744764 /unittests/ADT | |
parent | 19c6fbb3e8aaf74093afa08013134b61fa08f245 (diff) | |
download | external_llvm-c6a4f5e819217e1e12c458aed8e7b122e23a3a58.zip external_llvm-c6a4f5e819217e1e12c458aed8e7b122e23a3a58.tar.gz external_llvm-c6a4f5e819217e1e12c458aed8e7b122e23a3a58.tar.bz2 |
Update LLVM for rebase to r212749.
Includes a cherry-pick of:
r212948 - fixes a small issue with atomic calls
Change-Id: Ib97bd980b59f18142a69506400911a6009d9df18
Diffstat (limited to 'unittests/ADT')
-rw-r--r-- | unittests/ADT/APFloatTest.cpp | 54 | ||||
-rw-r--r-- | unittests/ADT/ArrayRefTest.cpp | 7 | ||||
-rw-r--r-- | unittests/ADT/CMakeLists.txt | 1 | ||||
-rw-r--r-- | unittests/ADT/DenseMapTest.cpp | 6 | ||||
-rw-r--r-- | unittests/ADT/DenseSetTest.cpp | 2 | ||||
-rw-r--r-- | unittests/ADT/HashingTest.cpp | 2 | ||||
-rw-r--r-- | unittests/ADT/ImmutableMapTest.cpp | 4 | ||||
-rw-r--r-- | unittests/ADT/OwningPtrTest.cpp | 273 | ||||
-rw-r--r-- | unittests/ADT/PointerUnionTest.cpp | 2 | ||||
-rw-r--r-- | unittests/ADT/SCCIteratorTest.cpp | 2 | ||||
-rw-r--r-- | unittests/ADT/SmallVectorTest.cpp | 210 | ||||
-rw-r--r-- | unittests/ADT/StringMapTest.cpp | 48 | ||||
-rw-r--r-- | unittests/ADT/ilistTest.cpp | 4 |
13 files changed, 277 insertions, 338 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp index e57c8d4..8f298cd 100644 --- a/unittests/ADT/APFloatTest.cpp +++ b/unittests/ADT/APFloatTest.cpp @@ -1173,11 +1173,11 @@ TEST(APFloatTest, exactInverse) { EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(8.5070592e+37f))); // Large float, inverse is a denormal. - EXPECT_FALSE(APFloat(1.7014118e38f).getExactInverse(0)); + EXPECT_FALSE(APFloat(1.7014118e38f).getExactInverse(nullptr)); // Zero - EXPECT_FALSE(APFloat(0.0).getExactInverse(0)); + EXPECT_FALSE(APFloat(0.0).getExactInverse(nullptr)); // Denormalized float - EXPECT_FALSE(APFloat(1.40129846e-45f).getExactInverse(0)); + EXPECT_FALSE(APFloat(1.40129846e-45f).getExactInverse(nullptr)); } TEST(APFloatTest, roundToIntegral) { @@ -1844,10 +1844,10 @@ TEST(APFloatTest, subtract) { { PInf, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { PInf, PZero, "inf", APFloat::opOK, APFloat::fcInfinity }, { PInf, MZero, "inf", APFloat::opOK, APFloat::fcInfinity }, - { PInf, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { PInf, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { PInf, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { PInf, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { PInf, PNormalValue, "inf", APFloat::opOK, APFloat::fcInfinity }, { PInf, MNormalValue, "inf", APFloat::opOK, APFloat::fcInfinity }, @@ -1861,10 +1861,10 @@ TEST(APFloatTest, subtract) { { MInf, MInf, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, { MInf, PZero, "-inf", APFloat::opOK, APFloat::fcInfinity }, { MInf, MZero, "-inf", APFloat::opOK, APFloat::fcInfinity }, - { MInf, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { MInf, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { MInf, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { MInf, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { MInf, PNormalValue, "-inf", APFloat::opOK, APFloat::fcInfinity }, { MInf, MNormalValue, "-inf", APFloat::opOK, APFloat::fcInfinity }, @@ -1878,10 +1878,10 @@ TEST(APFloatTest, subtract) { { PZero, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { PZero, PZero, "0x0p+0", APFloat::opOK, APFloat::fcZero }, { PZero, MZero, "0x0p+0", APFloat::opOK, APFloat::fcZero }, - { PZero, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { PZero, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { PZero, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { PZero, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { PZero, PNormalValue, "-0x1p+0", APFloat::opOK, APFloat::fcNormal }, { PZero, MNormalValue, "0x1p+0", APFloat::opOK, APFloat::fcNormal }, @@ -1895,10 +1895,10 @@ TEST(APFloatTest, subtract) { { MZero, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { MZero, PZero, "-0x0p+0", APFloat::opOK, APFloat::fcZero }, { MZero, MZero, "0x0p+0", APFloat::opOK, APFloat::fcZero }, - { MZero, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { MZero, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { MZero, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { MZero, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { MZero, PNormalValue, "-0x1p+0", APFloat::opOK, APFloat::fcNormal }, { MZero, MNormalValue, "0x1p+0", APFloat::opOK, APFloat::fcNormal }, @@ -1946,10 +1946,10 @@ TEST(APFloatTest, subtract) { { PNormalValue, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { PNormalValue, PZero, "0x1p+0", APFloat::opOK, APFloat::fcNormal }, { PNormalValue, MZero, "0x1p+0", APFloat::opOK, APFloat::fcNormal }, - { PNormalValue, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { PNormalValue, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { PNormalValue, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { PNormalValue, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { PNormalValue, PNormalValue, "0x0p+0", APFloat::opOK, APFloat::fcZero }, { PNormalValue, MNormalValue, "0x1p+1", APFloat::opOK, APFloat::fcNormal }, @@ -1963,10 +1963,10 @@ TEST(APFloatTest, subtract) { { MNormalValue, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { MNormalValue, PZero, "-0x1p+0", APFloat::opOK, APFloat::fcNormal }, { MNormalValue, MZero, "-0x1p+0", APFloat::opOK, APFloat::fcNormal }, - { MNormalValue, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { MNormalValue, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { MNormalValue, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { MNormalValue, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { MNormalValue, PNormalValue, "-0x1p+1", APFloat::opOK, APFloat::fcNormal }, { MNormalValue, MNormalValue, "0x0p+0", APFloat::opOK, APFloat::fcZero }, @@ -1980,10 +1980,10 @@ TEST(APFloatTest, subtract) { { PLargestValue, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { PLargestValue, PZero, "0x1.fffffep+127", APFloat::opOK, APFloat::fcNormal }, { PLargestValue, MZero, "0x1.fffffep+127", APFloat::opOK, APFloat::fcNormal }, - { PLargestValue, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { PLargestValue, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { PLargestValue, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { PLargestValue, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { PLargestValue, PNormalValue, "0x1.fffffep+127", APFloat::opInexact, APFloat::fcNormal }, { PLargestValue, MNormalValue, "0x1.fffffep+127", APFloat::opInexact, APFloat::fcNormal }, @@ -1997,10 +1997,10 @@ TEST(APFloatTest, subtract) { { MLargestValue, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { MLargestValue, PZero, "-0x1.fffffep+127", APFloat::opOK, APFloat::fcNormal }, { MLargestValue, MZero, "-0x1.fffffep+127", APFloat::opOK, APFloat::fcNormal }, - { MLargestValue, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { MLargestValue, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { MLargestValue, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { MLargestValue, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { MLargestValue, PNormalValue, "-0x1.fffffep+127", APFloat::opInexact, APFloat::fcNormal }, { MLargestValue, MNormalValue, "-0x1.fffffep+127", APFloat::opInexact, APFloat::fcNormal }, @@ -2014,10 +2014,10 @@ TEST(APFloatTest, subtract) { { PSmallestValue, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { PSmallestValue, PZero, "0x1p-149", APFloat::opOK, APFloat::fcNormal }, { PSmallestValue, MZero, "0x1p-149", APFloat::opOK, APFloat::fcNormal }, - { PSmallestValue, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { PSmallestValue, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { PSmallestValue, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { PSmallestValue, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { PSmallestValue, PNormalValue, "-0x1p+0", APFloat::opInexact, APFloat::fcNormal }, { PSmallestValue, MNormalValue, "0x1p+0", APFloat::opInexact, APFloat::fcNormal }, @@ -2031,10 +2031,10 @@ TEST(APFloatTest, subtract) { { MSmallestValue, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { MSmallestValue, PZero, "-0x1p-149", APFloat::opOK, APFloat::fcNormal }, { MSmallestValue, MZero, "-0x1p-149", APFloat::opOK, APFloat::fcNormal }, - { MSmallestValue, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { MSmallestValue, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { MSmallestValue, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { MSmallestValue, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { MSmallestValue, PNormalValue, "-0x1p+0", APFloat::opInexact, APFloat::fcNormal }, { MSmallestValue, MNormalValue, "0x1p+0", APFloat::opInexact, APFloat::fcNormal }, @@ -2048,10 +2048,10 @@ TEST(APFloatTest, subtract) { { PSmallestNormalized, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { PSmallestNormalized, PZero, "0x1p-126", APFloat::opOK, APFloat::fcNormal }, { PSmallestNormalized, MZero, "0x1p-126", APFloat::opOK, APFloat::fcNormal }, - { PSmallestNormalized, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { PSmallestNormalized, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { PSmallestNormalized, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { PSmallestNormalized, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { PSmallestNormalized, PNormalValue, "-0x1p+0", APFloat::opInexact, APFloat::fcNormal }, { PSmallestNormalized, MNormalValue, "0x1p+0", APFloat::opInexact, APFloat::fcNormal }, @@ -2065,10 +2065,10 @@ TEST(APFloatTest, subtract) { { MSmallestNormalized, MInf, "inf", APFloat::opOK, APFloat::fcInfinity }, { MSmallestNormalized, PZero, "-0x1p-126", APFloat::opOK, APFloat::fcNormal }, { MSmallestNormalized, MZero, "-0x1p-126", APFloat::opOK, APFloat::fcNormal }, - { MSmallestNormalized, QNaN, "nan", APFloat::opOK, APFloat::fcNaN }, + { MSmallestNormalized, QNaN, "-nan", APFloat::opOK, APFloat::fcNaN }, #if 0 // See Note 1. - { MSmallestNormalized, SNaN, "nan", APFloat::opInvalidOp, APFloat::fcNaN }, + { MSmallestNormalized, SNaN, "-nan", APFloat::opInvalidOp, APFloat::fcNaN }, #endif { MSmallestNormalized, PNormalValue, "-0x1p+0", APFloat::opInexact, APFloat::fcNormal }, { MSmallestNormalized, MNormalValue, "0x1p+0", APFloat::opInexact, APFloat::fcNormal }, diff --git a/unittests/ADT/ArrayRefTest.cpp b/unittests/ADT/ArrayRefTest.cpp index 7133ca7..293afc6 100644 --- a/unittests/ADT/ArrayRefTest.cpp +++ b/unittests/ADT/ArrayRefTest.cpp @@ -29,5 +29,12 @@ TEST(ArrayRefTest, AllocatorCopy) { EXPECT_NE(Array2.data(), Array2c.data()); } +TEST(ArrayRefTest, DropBack) { + static const int TheNumbers[] = {4, 8, 15, 16, 23, 42}; + ArrayRef<int> AR1(TheNumbers); + ArrayRef<int> AR2(TheNumbers, AR1.size() - 1); + EXPECT_TRUE(AR1.drop_back().equals(AR2)); +} + } // end anonymous namespace diff --git a/unittests/ADT/CMakeLists.txt b/unittests/ADT/CMakeLists.txt index 5119723..0f214f3 100644 --- a/unittests/ADT/CMakeLists.txt +++ b/unittests/ADT/CMakeLists.txt @@ -23,7 +23,6 @@ set(ADTSources MakeUniqueTest.cpp MapVectorTest.cpp OptionalTest.cpp - OwningPtrTest.cpp PackedVectorTest.cpp PointerIntPairTest.cpp PointerUnionTest.cpp diff --git a/unittests/ADT/DenseMapTest.cpp b/unittests/ADT/DenseMapTest.cpp index dd49071..75a910a 100644 --- a/unittests/ADT/DenseMapTest.cpp +++ b/unittests/ADT/DenseMapTest.cpp @@ -92,9 +92,9 @@ protected: }; template <typename T> -typename T::key_type *const DenseMapTest<T>::dummy_key_ptr = 0; +typename T::key_type *const DenseMapTest<T>::dummy_key_ptr = nullptr; template <typename T> -typename T::mapped_type *const DenseMapTest<T>::dummy_value_ptr = 0; +typename T::mapped_type *const DenseMapTest<T>::dummy_value_ptr = nullptr; // Register these types for testing. typedef ::testing::Types<DenseMap<uint32_t, uint32_t>, @@ -345,7 +345,7 @@ TEST(DenseMapCustomTest, FindAsTest) { EXPECT_EQ(3u, map.size()); // Normal lookup tests - EXPECT_EQ(1, map.count(1)); + EXPECT_EQ(1u, map.count(1)); EXPECT_EQ(1u, map.find(0)->second); EXPECT_EQ(2u, map.find(1)->second); EXPECT_EQ(3u, map.find(2)->second); diff --git a/unittests/ADT/DenseSetTest.cpp b/unittests/ADT/DenseSetTest.cpp index ada5f6d..154c589 100644 --- a/unittests/ADT/DenseSetTest.cpp +++ b/unittests/ADT/DenseSetTest.cpp @@ -24,7 +24,7 @@ TEST_F(DenseSetTest, DoubleEntrySetTest) { set.insert(0); set.insert(1); // Original failure was an infinite loop in this call: - EXPECT_EQ(0, set.count(2)); + EXPECT_EQ(0u, set.count(2)); } } diff --git a/unittests/ADT/HashingTest.cpp b/unittests/ADT/HashingTest.cpp index 60917ae..acaa83c 100644 --- a/unittests/ADT/HashingTest.cpp +++ b/unittests/ADT/HashingTest.cpp @@ -58,7 +58,7 @@ enum TestEnumeration { TEST(HashingTest, HashValueBasicTest) { int x = 42, y = 43, c = 'x'; - void *p = 0; + void *p = nullptr; uint64_t i = 71; const unsigned ci = 71; volatile int vi = 71; diff --git a/unittests/ADT/ImmutableMapTest.cpp b/unittests/ADT/ImmutableMapTest.cpp index 774581c..6a99884 100644 --- a/unittests/ADT/ImmutableMapTest.cpp +++ b/unittests/ADT/ImmutableMapTest.cpp @@ -36,8 +36,8 @@ TEST(ImmutableMapTest, MultiElemIntMapTest) { EXPECT_TRUE(S.isEmpty()); EXPECT_FALSE(S2.isEmpty()); - EXPECT_EQ(0, S.lookup(3)); - EXPECT_EQ(0, S.lookup(9)); + EXPECT_EQ(nullptr, S.lookup(3)); + EXPECT_EQ(nullptr, S.lookup(9)); EXPECT_EQ(10, *S2.lookup(3)); EXPECT_EQ(11, *S2.lookup(4)); diff --git a/unittests/ADT/OwningPtrTest.cpp b/unittests/ADT/OwningPtrTest.cpp deleted file mode 100644 index aee955b..0000000 --- a/unittests/ADT/OwningPtrTest.cpp +++ /dev/null @@ -1,273 +0,0 @@ -//===- 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/PointerUnionTest.cpp b/unittests/ADT/PointerUnionTest.cpp index 3bfb79c..a592784 100644 --- a/unittests/ADT/PointerUnionTest.cpp +++ b/unittests/ADT/PointerUnionTest.cpp @@ -66,7 +66,7 @@ TEST_F(PointerUnionTest, Is) { TEST_F(PointerUnionTest, Get) { EXPECT_EQ(a.get<float *>(), &f); EXPECT_EQ(b.get<int *>(), &i); - EXPECT_EQ(n.get<int *>(), (int *)0); + EXPECT_EQ(n.get<int *>(), (int *)nullptr); } } // end anonymous namespace diff --git a/unittests/ADT/SCCIteratorTest.cpp b/unittests/ADT/SCCIteratorTest.cpp index 8609732..3f1ba1c 100644 --- a/unittests/ADT/SCCIteratorTest.cpp +++ b/unittests/ADT/SCCIteratorTest.cpp @@ -213,7 +213,7 @@ public: // Return a pointer to it. return FirstNode + i; assert(false && "Dereferencing end iterator!"); - return 0; // Avoid compiler warning. + return nullptr; // Avoid compiler warning. } }; diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp index 58f5591..95bf33e 100644 --- a/unittests/ADT/SmallVectorTest.cpp +++ b/unittests/ADT/SmallVectorTest.cpp @@ -26,8 +26,12 @@ namespace { class Constructable { private: static int numConstructorCalls; + static int numMoveConstructorCalls; + static int numCopyConstructorCalls; static int numDestructorCalls; static int numAssignmentCalls; + static int numMoveAssignmentCalls; + static int numCopyAssignmentCalls; bool constructed; int value; @@ -44,11 +48,13 @@ public: Constructable(const Constructable & src) : constructed(true) { value = src.value; ++numConstructorCalls; + ++numCopyConstructorCalls; } Constructable(Constructable && src) : constructed(true) { value = src.value; ++numConstructorCalls; + ++numMoveConstructorCalls; } ~Constructable() { @@ -61,6 +67,7 @@ public: EXPECT_TRUE(constructed); value = src.value; ++numAssignmentCalls; + ++numCopyAssignmentCalls; return *this; } @@ -68,6 +75,7 @@ public: EXPECT_TRUE(constructed); value = src.value; ++numAssignmentCalls; + ++numMoveAssignmentCalls; return *this; } @@ -77,18 +85,42 @@ public: static void reset() { numConstructorCalls = 0; + numMoveConstructorCalls = 0; + numCopyConstructorCalls = 0; numDestructorCalls = 0; numAssignmentCalls = 0; + numMoveAssignmentCalls = 0; + numCopyAssignmentCalls = 0; } static int getNumConstructorCalls() { return numConstructorCalls; } + static int getNumMoveConstructorCalls() { + return numMoveConstructorCalls; + } + + static int getNumCopyConstructorCalls() { + return numCopyConstructorCalls; + } + static int getNumDestructorCalls() { return numDestructorCalls; } + static int getNumAssignmentCalls() { + return numAssignmentCalls; + } + + static int getNumMoveAssignmentCalls() { + return numMoveAssignmentCalls; + } + + static int getNumCopyAssignmentCalls() { + return numCopyAssignmentCalls; + } + friend bool operator==(const Constructable & c0, const Constructable & c1) { return c0.getValue() == c1.getValue(); } @@ -100,8 +132,26 @@ public: }; int Constructable::numConstructorCalls; +int Constructable::numCopyConstructorCalls; +int Constructable::numMoveConstructorCalls; int Constructable::numDestructorCalls; int Constructable::numAssignmentCalls; +int Constructable::numCopyAssignmentCalls; +int Constructable::numMoveAssignmentCalls; + +struct NonCopyable { + NonCopyable() {} + NonCopyable(NonCopyable &&) {} + NonCopyable &operator=(NonCopyable &&) { return *this; } +private: + NonCopyable(const NonCopyable &) LLVM_DELETED_FUNCTION; + NonCopyable &operator=(const NonCopyable &) LLVM_DELETED_FUNCTION; +}; + +LLVM_ATTRIBUTE_USED void CompileTest() { + SmallVector<NonCopyable, 0> V; + V.resize(42); +} // Test fixture class template <typename VectorT> @@ -148,7 +198,8 @@ protected: typedef ::testing::Types<SmallVector<Constructable, 0>, SmallVector<Constructable, 1>, SmallVector<Constructable, 2>, - SmallVector<Constructable, 4> + SmallVector<Constructable, 4>, + SmallVector<Constructable, 5> > SmallVectorTestTypes; TYPED_TEST_CASE(SmallVectorTest, SmallVectorTestTypes); @@ -240,13 +291,26 @@ TYPED_TEST(SmallVectorTest, ResizeGrowTest) { this->theVector.resize(2); - // The extra constructor/destructor calls come from the temporary object used - // to initialize the contents of the resized array (via copy construction). - EXPECT_EQ(3, Constructable::getNumConstructorCalls()); - EXPECT_EQ(1, Constructable::getNumDestructorCalls()); + EXPECT_EQ(2, Constructable::getNumConstructorCalls()); + EXPECT_EQ(0, Constructable::getNumDestructorCalls()); EXPECT_EQ(2u, this->theVector.size()); } +TYPED_TEST(SmallVectorTest, ResizeWithElementsTest) { + this->theVector.resize(2); + + Constructable::reset(); + + this->theVector.resize(4); + + size_t Ctors = Constructable::getNumConstructorCalls(); + EXPECT_TRUE(Ctors == 2 || Ctors == 4); + size_t MoveCtors = Constructable::getNumMoveConstructorCalls(); + EXPECT_TRUE(MoveCtors == 0 || MoveCtors == 2); + size_t Dtors = Constructable::getNumDestructorCalls(); + EXPECT_TRUE(Dtors == 0 || Dtors == 2); +} + // Resize with fill value. TYPED_TEST(SmallVectorTest, ResizeFillTest) { SCOPED_TRACE("ResizeFillTest"); @@ -413,22 +477,67 @@ TYPED_TEST(SmallVectorTest, InsertTest) { this->assertValuesInOrder(this->theVector, 4u, 1, 77, 2, 3); } +// Insert a copy of a single element. +TYPED_TEST(SmallVectorTest, InsertCopy) { + SCOPED_TRACE("InsertTest"); + + this->makeSequence(this->theVector, 1, 3); + Constructable C(77); + typename TypeParam::iterator I = + this->theVector.insert(this->theVector.begin() + 1, C); + EXPECT_EQ(this->theVector.begin() + 1, I); + this->assertValuesInOrder(this->theVector, 4u, 1, 77, 2, 3); +} + // Insert repeated elements. TYPED_TEST(SmallVectorTest, InsertRepeatedTest) { SCOPED_TRACE("InsertRepeatedTest"); - this->makeSequence(this->theVector, 10, 15); - typename TypeParam::iterator I = - this->theVector.insert(this->theVector.begin() + 1, 2, Constructable(16)); + this->makeSequence(this->theVector, 1, 4); + Constructable::reset(); + auto I = + this->theVector.insert(this->theVector.begin() + 1, 2, Constructable(16)); + // Move construct the top element into newly allocated space, and optionally + // reallocate the whole buffer, move constructing into it. + // FIXME: This is inefficient, we shouldn't move things into newly allocated + // space, then move them up/around, there should only be 2 or 4 move + // constructions here. + EXPECT_TRUE(Constructable::getNumMoveConstructorCalls() == 2 || + Constructable::getNumMoveConstructorCalls() == 6); + // Move assign the next two to shift them up and make a gap. + EXPECT_EQ(1, Constructable::getNumMoveAssignmentCalls()); + // Copy construct the two new elements from the parameter. + EXPECT_EQ(2, Constructable::getNumCopyAssignmentCalls()); + // All without any copy construction. + EXPECT_EQ(0, Constructable::getNumCopyConstructorCalls()); EXPECT_EQ(this->theVector.begin() + 1, I); - this->assertValuesInOrder(this->theVector, 8u, - 10, 16, 16, 11, 12, 13, 14, 15); + this->assertValuesInOrder(this->theVector, 6u, 1, 16, 16, 2, 3, 4); +} - // Insert at end. - I = this->theVector.insert(this->theVector.end(), 2, Constructable(16)); - EXPECT_EQ(this->theVector.begin() + 8, I); - this->assertValuesInOrder(this->theVector, 10u, - 10, 16, 16, 11, 12, 13, 14, 15, 16, 16); + +TYPED_TEST(SmallVectorTest, InsertRepeatedAtEndTest) { + SCOPED_TRACE("InsertRepeatedTest"); + + this->makeSequence(this->theVector, 1, 4); + Constructable::reset(); + auto I = this->theVector.insert(this->theVector.end(), 2, Constructable(16)); + // Just copy construct them into newly allocated space + EXPECT_EQ(2, Constructable::getNumCopyConstructorCalls()); + // Move everything across if reallocation is needed. + EXPECT_TRUE(Constructable::getNumMoveConstructorCalls() == 0 || + Constructable::getNumMoveConstructorCalls() == 4); + // Without ever moving or copying anything else. + EXPECT_EQ(0, Constructable::getNumCopyAssignmentCalls()); + EXPECT_EQ(0, Constructable::getNumMoveAssignmentCalls()); + + EXPECT_EQ(this->theVector.begin() + 4, I); + this->assertValuesInOrder(this->theVector, 6u, 1, 2, 3, 4, 16, 16); +} + +TYPED_TEST(SmallVectorTest, InsertRepeatedEmptyTest) { + SCOPED_TRACE("InsertRepeatedTest"); + + this->makeSequence(this->theVector, 10, 15); // Empty insert. EXPECT_EQ(this->theVector.end(), @@ -447,16 +556,53 @@ TYPED_TEST(SmallVectorTest, InsertRangeTest) { { Constructable(77), Constructable(77), Constructable(77) }; this->makeSequence(this->theVector, 1, 3); - typename TypeParam::iterator I = - this->theVector.insert(this->theVector.begin() + 1, Arr, Arr+3); + Constructable::reset(); + auto I = this->theVector.insert(this->theVector.begin() + 1, Arr, Arr + 3); + // Move construct the top 3 elements into newly allocated space. + // Possibly move the whole sequence into new space first. + // FIXME: This is inefficient, we shouldn't move things into newly allocated + // space, then move them up/around, there should only be 2 or 3 move + // constructions here. + EXPECT_TRUE(Constructable::getNumMoveConstructorCalls() == 2 || + Constructable::getNumMoveConstructorCalls() == 5); + // Copy assign the lower 2 new elements into existing space. + EXPECT_EQ(2, Constructable::getNumCopyAssignmentCalls()); + // Copy construct the third element into newly allocated space. + EXPECT_EQ(1, Constructable::getNumCopyConstructorCalls()); EXPECT_EQ(this->theVector.begin() + 1, I); this->assertValuesInOrder(this->theVector, 6u, 1, 77, 77, 77, 2, 3); +} + + +TYPED_TEST(SmallVectorTest, InsertRangeAtEndTest) { + SCOPED_TRACE("InsertRangeTest"); + + Constructable Arr[3] = + { Constructable(77), Constructable(77), Constructable(77) }; + + this->makeSequence(this->theVector, 1, 3); // Insert at end. - I = this->theVector.insert(this->theVector.end(), Arr, Arr+3); - EXPECT_EQ(this->theVector.begin() + 6, I); - this->assertValuesInOrder(this->theVector, 9u, - 1, 77, 77, 77, 2, 3, 77, 77, 77); + Constructable::reset(); + auto I = this->theVector.insert(this->theVector.end(), Arr, Arr+3); + // Copy construct the 3 elements into new space at the top. + EXPECT_EQ(3, Constructable::getNumCopyConstructorCalls()); + // Don't copy/move anything else. + EXPECT_EQ(0, Constructable::getNumCopyAssignmentCalls()); + // Reallocation might occur, causing all elements to be moved into the new + // buffer. + EXPECT_TRUE(Constructable::getNumMoveConstructorCalls() == 0 || + Constructable::getNumMoveConstructorCalls() == 3); + EXPECT_EQ(0, Constructable::getNumMoveAssignmentCalls()); + EXPECT_EQ(this->theVector.begin() + 3, I); + this->assertValuesInOrder(this->theVector, 6u, + 1, 2, 3, 77, 77, 77); +} + +TYPED_TEST(SmallVectorTest, InsertEmptyRangeTest) { + SCOPED_TRACE("InsertRangeTest"); + + this->makeSequence(this->theVector, 1, 3); // Empty insert. EXPECT_EQ(this->theVector.end(), @@ -531,4 +677,26 @@ TEST(SmallVectorCustomTest, NoAssignTest) { EXPECT_EQ(42, vec.pop_back_val().x); } +struct MovedFrom { + bool hasValue; + MovedFrom() : hasValue(true) { + } + MovedFrom(MovedFrom&& m) : hasValue(m.hasValue) { + m.hasValue = false; + } + MovedFrom &operator=(MovedFrom&& m) { + hasValue = m.hasValue; + m.hasValue = false; + return *this; + } +}; + +TEST(SmallVectorTest, MidInsert) { + SmallVector<MovedFrom, 3> v; + v.push_back(MovedFrom()); + v.insert(v.begin(), MovedFrom()); + for (MovedFrom &m : v) + EXPECT_TRUE(m.hasValue); +} + } diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp index de18e07..028375d 100644 --- a/unittests/ADT/StringMapTest.cpp +++ b/unittests/ADT/StringMapTest.cpp @@ -10,6 +10,7 @@ #include "gtest/gtest.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/DataTypes.h" +#include <tuple> using namespace llvm; namespace { @@ -187,7 +188,7 @@ TEST_F(StringMapTest, IterationTest) { TEST_F(StringMapTest, StringMapEntryTest) { StringMap<uint32_t>::value_type* entry = StringMap<uint32_t>::value_type::Create( - testKeyFirst, testKeyFirst + testKeyLength, 1u); + StringRef(testKeyFirst, testKeyLength), 1u); EXPECT_STREQ(testKey, entry->first().data()); EXPECT_EQ(1u, entry->second); free(entry); @@ -198,11 +199,48 @@ TEST_F(StringMapTest, InsertTest) { SCOPED_TRACE("InsertTest"); testMap.insert( StringMap<uint32_t>::value_type::Create( - testKeyFirst, testKeyFirst + testKeyLength, + StringRef(testKeyFirst, testKeyLength), testMap.getAllocator(), 1u)); assertSingleItemMap(); } +// Test insert(pair<K, V>) method +TEST_F(StringMapTest, InsertPairTest) { + bool Inserted; + StringMap<uint32_t>::iterator NewIt; + std::tie(NewIt, Inserted) = + testMap.insert(std::make_pair(testKeyFirst, testValue)); + EXPECT_EQ(1u, testMap.size()); + EXPECT_EQ(testValue, testMap[testKeyFirst]); + EXPECT_EQ(testKeyFirst, NewIt->first()); + EXPECT_EQ(testValue, NewIt->second); + EXPECT_TRUE(Inserted); + + StringMap<uint32_t>::iterator ExistingIt; + std::tie(ExistingIt, Inserted) = + testMap.insert(std::make_pair(testKeyFirst, testValue + 1)); + EXPECT_EQ(1u, testMap.size()); + EXPECT_EQ(testValue, testMap[testKeyFirst]); + EXPECT_FALSE(Inserted); + EXPECT_EQ(NewIt, ExistingIt); +} + +// Test insert(pair<K, V>) method when rehashing occurs +TEST_F(StringMapTest, InsertRehashingPairTest) { + // Check that the correct iterator is returned when the inserted element is + // moved to a different bucket during internal rehashing. This depends on + // the particular key, and the implementation of StringMap and HashString. + // Changes to those might result in this test not actually checking that. + StringMap<uint32_t> t(1); + EXPECT_EQ(1u, t.getNumBuckets()); + + StringMap<uint32_t>::iterator It = + t.insert(std::make_pair("abcdef", 42)).first; + EXPECT_EQ(2u, t.getNumBuckets()); + EXPECT_EQ("abcdef", It->first()); + EXPECT_EQ(42u, It->second); +} + // Create a non-default constructable value struct StringMapTestStruct { StringMapTestStruct(int i) : i(i) {} @@ -228,15 +266,15 @@ struct MoveOnly { } private: - MoveOnly(const MoveOnly &); - MoveOnly &operator=(const MoveOnly &); + MoveOnly(const MoveOnly &) LLVM_DELETED_FUNCTION; + MoveOnly &operator=(const MoveOnly &) LLVM_DELETED_FUNCTION; }; TEST_F(StringMapTest, MoveOnlyKey) { StringMap<MoveOnly> t; t.GetOrCreateValue("Test", MoveOnly(42)); StringRef Key = "Test"; - StringMapEntry<MoveOnly>::Create(Key.begin(), Key.end(), MoveOnly(42)) + StringMapEntry<MoveOnly>::Create(Key, MoveOnly(42)) ->Destroy(); } diff --git a/unittests/ADT/ilistTest.cpp b/unittests/ADT/ilistTest.cpp index 134607c..44442eb 100644 --- a/unittests/ADT/ilistTest.cpp +++ b/unittests/ADT/ilistTest.cpp @@ -29,8 +29,8 @@ TEST(ilistTest, Basic) { ilist<Node> List; List.push_back(Node(1)); EXPECT_EQ(1, List.back().Value); - EXPECT_EQ(0, List.back().getPrevNode()); - EXPECT_EQ(0, List.back().getNextNode()); + EXPECT_EQ(nullptr, List.back().getPrevNode()); + EXPECT_EQ(nullptr, List.back().getNextNode()); List.push_back(Node(2)); EXPECT_EQ(2, List.back().Value); |