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 | |
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')
77 files changed, 3105 insertions, 1072 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); diff --git a/unittests/Analysis/CFGTest.cpp b/unittests/Analysis/CFGTest.cpp index 8d8c560..ac5e710 100644 --- a/unittests/Analysis/CFGTest.cpp +++ b/unittests/Analysis/CFGTest.cpp @@ -46,10 +46,10 @@ protected: } Function *F = M->getFunction("test"); - if (F == NULL) + if (F == nullptr) report_fatal_error("Test must have a function named @test"); - A = B = NULL; + A = B = nullptr; for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) { if (I->hasName()) { if (I->getName() == "A") @@ -58,9 +58,9 @@ protected: B = &*I; } } - if (A == NULL) + if (A == nullptr) report_fatal_error("@test must have an instruction %A"); - if (B == NULL) + if (B == nullptr) report_fatal_error("@test must have an instruction %B"); } @@ -74,7 +74,7 @@ protected: static int initialize() { PassInfo *PI = new PassInfo("isPotentiallyReachable testing pass", - "", &ID, 0, true, true); + "", &ID, nullptr, true, true); PassRegistry::getPassRegistry()->registerPass(*PI, false); initializeLoopInfoPass(*PassRegistry::getPassRegistry()); initializeDominatorTreeWrapperPassPass( @@ -95,9 +95,10 @@ protected: LoopInfo *LI = &getAnalysis<LoopInfo>(); DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); - EXPECT_EQ(isPotentiallyReachable(A, B, 0, 0), ExpectedResult); - EXPECT_EQ(isPotentiallyReachable(A, B, DT, 0), ExpectedResult); - EXPECT_EQ(isPotentiallyReachable(A, B, 0, LI), ExpectedResult); + EXPECT_EQ(isPotentiallyReachable(A, B, nullptr, nullptr), + ExpectedResult); + EXPECT_EQ(isPotentiallyReachable(A, B, DT, nullptr), ExpectedResult); + EXPECT_EQ(isPotentiallyReachable(A, B, nullptr, LI), ExpectedResult); EXPECT_EQ(isPotentiallyReachable(A, B, DT, LI), ExpectedResult); return false; } diff --git a/unittests/Analysis/MixedTBAATest.cpp b/unittests/Analysis/MixedTBAATest.cpp index 2cf7c73..142e047 100644 --- a/unittests/Analysis/MixedTBAATest.cpp +++ b/unittests/Analysis/MixedTBAATest.cpp @@ -43,7 +43,7 @@ TEST_F(MixedTBAATest, MixedTBAA) { auto *Store1 = new StoreInst(Value, Addr, BB); auto *Store2 = new StoreInst(Value, Addr, BB); - ReturnInst::Create(C, 0, BB); + ReturnInst::Create(C, nullptr, BB); // New TBAA metadata { diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp index 398d09e..90f6997 100644 --- a/unittests/Analysis/ScalarEvolutionTest.cpp +++ b/unittests/Analysis/ScalarEvolutionTest.cpp @@ -41,7 +41,7 @@ TEST_F(ScalarEvolutionsTest, SCEVUnknownRAUW) { std::vector<Type *>(), false); Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); - ReturnInst::Create(Context, 0, BB); + ReturnInst::Create(Context, nullptr, BB); Type *Ty = Type::getInt1Ty(Context); Constant *Init = Constant::getNullValue(Ty); @@ -94,7 +94,7 @@ TEST_F(ScalarEvolutionsTest, SCEVMultiplyAddRecs) { FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), Types, false); Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); - ReturnInst::Create(Context, 0, BB); + ReturnInst::Create(Context, nullptr, BB); // Create a ScalarEvolution and "run" it so that it gets initialized. PM.add(&SE); diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index bbab2a1..65930b5 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -21,7 +21,6 @@ add_subdirectory(IR) add_subdirectory(LineEditor) add_subdirectory(Linker) add_subdirectory(MC) -add_subdirectory(Object) add_subdirectory(Option) add_subdirectory(Support) add_subdirectory(Transforms) diff --git a/unittests/ExecutionEngine/CMakeLists.txt b/unittests/ExecutionEngine/CMakeLists.txt index 7ef509b..489eaaf 100644 --- a/unittests/ExecutionEngine/CMakeLists.txt +++ b/unittests/ExecutionEngine/CMakeLists.txt @@ -9,9 +9,10 @@ add_llvm_unittest(ExecutionEngineTests ExecutionEngineTest.cpp ) -# Include JIT/MCJIT tests only if native arch is a JIT target. -list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit) -if (NOT have_jit EQUAL -1 ) +# Include JIT/MCJIT tests only if native arch is a built JIT target. +list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" build_idx) +list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" jit_idx) +if (NOT build_idx LESS 0 AND NOT jit_idx LESS 0) add_subdirectory(JIT) add_subdirectory(MCJIT) endif() diff --git a/unittests/ExecutionEngine/ExecutionEngineTest.cpp b/unittests/ExecutionEngine/ExecutionEngineTest.cpp index e6f07dc..f23745c 100644 --- a/unittests/ExecutionEngine/ExecutionEngineTest.cpp +++ b/unittests/ExecutionEngine/ExecutionEngineTest.cpp @@ -26,13 +26,13 @@ protected: } virtual void SetUp() { - ASSERT_TRUE(Engine.get() != NULL) << "EngineBuilder returned error: '" + ASSERT_TRUE(Engine.get() != nullptr) << "EngineBuilder returned error: '" << Error << "'"; } GlobalVariable *NewExtGlobal(Type *T, const Twine &Name) { return new GlobalVariable(*M, T, false, // Not constant. - GlobalValue::ExternalLinkage, NULL, Name); + GlobalValue::ExternalLinkage, nullptr, Name); } Module *const M; @@ -49,14 +49,14 @@ TEST_F(ExecutionEngineTest, ForwardGlobalMapping) { int32_t Mem2 = 4; Engine->updateGlobalMapping(G1, &Mem2); EXPECT_EQ(&Mem2, Engine->getPointerToGlobalIfAvailable(G1)); - Engine->updateGlobalMapping(G1, NULL); - EXPECT_EQ(NULL, Engine->getPointerToGlobalIfAvailable(G1)); + Engine->updateGlobalMapping(G1, nullptr); + EXPECT_EQ(nullptr, Engine->getPointerToGlobalIfAvailable(G1)); Engine->updateGlobalMapping(G1, &Mem2); EXPECT_EQ(&Mem2, Engine->getPointerToGlobalIfAvailable(G1)); GlobalVariable *G2 = NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1"); - EXPECT_EQ(NULL, Engine->getPointerToGlobalIfAvailable(G2)) + EXPECT_EQ(nullptr, Engine->getPointerToGlobalIfAvailable(G2)) << "The NULL return shouldn't depend on having called" << " updateGlobalMapping(..., NULL)"; // Check that update...() can be called before add...(). @@ -75,7 +75,7 @@ TEST_F(ExecutionEngineTest, ReverseGlobalMapping) { EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem1)); int32_t Mem2 = 4; Engine->updateGlobalMapping(G1, &Mem2); - EXPECT_EQ(NULL, Engine->getGlobalValueAtAddress(&Mem1)); + EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1)); EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2)); GlobalVariable *G2 = @@ -83,12 +83,12 @@ TEST_F(ExecutionEngineTest, ReverseGlobalMapping) { Engine->updateGlobalMapping(G2, &Mem1); EXPECT_EQ(G2, Engine->getGlobalValueAtAddress(&Mem1)); EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2)); - Engine->updateGlobalMapping(G1, NULL); + Engine->updateGlobalMapping(G1, nullptr); EXPECT_EQ(G2, Engine->getGlobalValueAtAddress(&Mem1)) << "Removing one mapping doesn't affect a different one."; - EXPECT_EQ(NULL, Engine->getGlobalValueAtAddress(&Mem2)); + EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem2)); Engine->updateGlobalMapping(G2, &Mem2); - EXPECT_EQ(NULL, Engine->getGlobalValueAtAddress(&Mem1)); + EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1)); EXPECT_EQ(G2, Engine->getGlobalValueAtAddress(&Mem2)) << "Once a mapping is removed, we can point another GV at the" << " now-free address."; @@ -104,7 +104,7 @@ TEST_F(ExecutionEngineTest, ClearModuleMappings) { Engine->clearGlobalMappingsFromModule(M); - EXPECT_EQ(NULL, Engine->getGlobalValueAtAddress(&Mem1)); + EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1)); GlobalVariable *G2 = NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global2"); @@ -124,7 +124,7 @@ TEST_F(ExecutionEngineTest, DestructionRemovesGlobalMapping) { // When the GV goes away, the ExecutionEngine should remove any // mappings that refer to it. G1->eraseFromParent(); - EXPECT_EQ(NULL, Engine->getGlobalValueAtAddress(&Mem1)); + EXPECT_EQ(nullptr, Engine->getGlobalValueAtAddress(&Mem1)); } } diff --git a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp index ab30884..296838d 100644 --- a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp @@ -267,12 +267,12 @@ TEST(JITMemoryManagerTest, TestManyStubs) { // After allocating a bunch of stubs, we should have two. for (int I = 0; I < Iters; ++I) - MemMgr->allocateStub(NULL, Size, 8); + MemMgr->allocateStub(nullptr, Size, 8); EXPECT_EQ(2U, MemMgr->GetNumStubSlabs()); // And after much more, we should have three. for (int I = 0; I < Iters; ++I) - MemMgr->allocateStub(NULL, Size, 8); + MemMgr->allocateStub(nullptr, Size, 8); EXPECT_EQ(3U, MemMgr->GetNumStubSlabs()); } @@ -286,10 +286,10 @@ TEST(JITMemoryManagerTest, AllocateSection) { uint8_t *data2 = MemMgr->allocateDataSection(256, 64, 4, StringRef(), false); uint8_t *code3 = MemMgr->allocateCodeSection(258, 64, 5, StringRef()); - EXPECT_NE((uint8_t*)0, code1); - EXPECT_NE((uint8_t*)0, code2); - EXPECT_NE((uint8_t*)0, data1); - EXPECT_NE((uint8_t*)0, data2); + EXPECT_NE((uint8_t*)nullptr, code1); + EXPECT_NE((uint8_t*)nullptr, code2); + EXPECT_NE((uint8_t*)nullptr, data1); + EXPECT_NE((uint8_t*)nullptr, data2); // Check alignment EXPECT_EQ((uint64_t)code1 & 0xf, 0u); diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index f438286..817d207 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -169,7 +169,7 @@ public: bool LoadAssemblyInto(Module *M, const char *assembly) { SMDiagnostic Error; bool success = - NULL != ParseAssemblyString(assembly, M, Error, M->getContext()); + nullptr != ParseAssemblyString(assembly, M, Error, M->getContext()); std::string errMsg; raw_string_ostream os(errMsg); Error.print("", os); @@ -193,7 +193,7 @@ class JITTest : public testing::Test { .setJITMemoryManager(RJMM) .setErrorStr(&Error) .setTargetOptions(Options).create()); - ASSERT_TRUE(TheJIT.get() != NULL) << Error; + ASSERT_TRUE(TheJIT.get() != nullptr) << Error; } void LoadAssembly(const char *assembly) { @@ -249,7 +249,7 @@ TEST(JIT, GlobalInFunction) { // Since F1 was codegen'd, a pointer to G should be available. int32_t *GPtr = (int32_t*)JIT->getPointerToGlobalIfAvailable(G); - ASSERT_NE((int32_t*)NULL, GPtr); + ASSERT_NE((int32_t*)nullptr, GPtr); EXPECT_EQ(0, *GPtr); // F1() should increment G. @@ -633,10 +633,10 @@ ExecutionEngine *getJITFromBitcode( MemoryBuffer *BitcodeBuffer = MemoryBuffer::getMemBuffer(Bitcode, "Bitcode for test"); ErrorOr<Module*> ModuleOrErr = getLazyBitcodeModule(BitcodeBuffer, Context); - if (error_code EC = ModuleOrErr.getError()) { + if (std::error_code EC = ModuleOrErr.getError()) { ADD_FAILURE() << EC.message(); delete BitcodeBuffer; - return NULL; + return nullptr; } M = ModuleOrErr.get(); std::string errMsg; @@ -644,11 +644,11 @@ ExecutionEngine *getJITFromBitcode( .setEngineKind(EngineKind::JIT) .setErrorStr(&errMsg) .create(); - if (TheJIT == NULL) { + if (TheJIT == nullptr) { ADD_FAILURE() << errMsg; delete M; - M = NULL; - return NULL; + M = nullptr; + return nullptr; } return TheJIT; } diff --git a/unittests/ExecutionEngine/JIT/MultiJITTest.cpp b/unittests/ExecutionEngine/JIT/MultiJITTest.cpp index 5016532..f530e0d 100644 --- a/unittests/ExecutionEngine/JIT/MultiJITTest.cpp +++ b/unittests/ExecutionEngine/JIT/MultiJITTest.cpp @@ -27,7 +27,7 @@ namespace { bool LoadAssemblyInto(Module *M, const char *assembly) { SMDiagnostic Error; bool success = - NULL != ParseAssemblyString(assembly, M, Error, M->getContext()); + nullptr != ParseAssemblyString(assembly, M, Error, M->getContext()); std::string errMsg; raw_string_ostream os(errMsg); Error.print("", os); @@ -71,13 +71,13 @@ void createModule2(LLVMContext &Context2, Module *&M2, Function *&FooF2) { TEST(MultiJitTest, EagerMode) { LLVMContext Context1; - Module *M1 = 0; - Function *FooF1 = 0; + Module *M1 = nullptr; + Function *FooF1 = nullptr; createModule1(Context1, M1, FooF1); LLVMContext Context2; - Module *M2 = 0; - Function *FooF2 = 0; + Module *M2 = nullptr; + Function *FooF2 = nullptr; createModule2(Context2, M2, FooF2); // Now we create the JIT in eager mode @@ -101,13 +101,13 @@ TEST(MultiJitTest, EagerMode) { TEST(MultiJitTest, LazyMode) { LLVMContext Context1; - Module *M1 = 0; - Function *FooF1 = 0; + Module *M1 = nullptr; + Function *FooF1 = nullptr; createModule1(Context1, M1, FooF1); LLVMContext Context2; - Module *M2 = 0; - Function *FooF2 = 0; + Module *M2 = nullptr; + Function *FooF2 = nullptr; createModule2(Context2, M2, FooF2); // Now we create the JIT in lazy mode @@ -135,13 +135,13 @@ extern "C" { TEST(MultiJitTest, JitPool) { LLVMContext Context1; - Module *M1 = 0; - Function *FooF1 = 0; + Module *M1 = nullptr; + Function *FooF1 = nullptr; createModule1(Context1, M1, FooF1); LLVMContext Context2; - Module *M2 = 0; - Function *FooF2 = 0; + Module *M2 = nullptr; + Function *FooF2 = nullptr; createModule2(Context2, M2, FooF2); // Now we create two JITs diff --git a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp index 20d3f13..d03de89 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp @@ -148,10 +148,10 @@ protected: didCallAllocateCodeSection = false; didAllocateCompactUnwindSection = false; didCallYield = false; - Module = 0; - Function = 0; - Engine = 0; - Error = 0; + Module = nullptr; + Function = nullptr; + Engine = nullptr; + Error = nullptr; } virtual void TearDown() { @@ -166,8 +166,8 @@ protected: LLVMSetTarget(Module, HostTriple.c_str()); - Function = LLVMAddFunction( - Module, "simple_function", LLVMFunctionType(LLVMInt32Type(), 0, 0, 0)); + Function = LLVMAddFunction(Module, "simple_function", + LLVMFunctionType(LLVMInt32Type(), nullptr,0, 0)); LLVMSetFunctionCallConv(Function, LLVMCCallConv); LLVMBasicBlockRef entry = LLVMAppendBasicBlock(Function, "entry"); @@ -192,8 +192,8 @@ protected: LLVMFunctionType(LLVMVoidType(), stackmapParamTypes, 2, 1)); LLVMSetLinkage(stackmap, LLVMExternalLinkage); - Function = LLVMAddFunction( - Module, "simple_function", LLVMFunctionType(LLVMInt32Type(), 0, 0, 0)); + Function = LLVMAddFunction(Module, "simple_function", + LLVMFunctionType(LLVMInt32Type(), nullptr, 0, 0)); LLVMBasicBlockRef entry = LLVMAppendBasicBlock(Function, "entry"); LLVMBuilderRef builder = LLVMCreateBuilder(); @@ -221,8 +221,8 @@ protected: LLVMSetInitializer(GlobalVar, LLVMConstInt(LLVMInt32Type(), 42, 0)); { - Function = LLVMAddFunction( - Module, "getGlobal", LLVMFunctionType(LLVMInt32Type(), 0, 0, 0)); + Function = LLVMAddFunction(Module, "getGlobal", + LLVMFunctionType(LLVMInt32Type(), nullptr, 0, 0)); LLVMSetFunctionCallConv(Function, LLVMCCallConv); LLVMBasicBlockRef Entry = LLVMAppendBasicBlock(Function, "entry"); @@ -443,7 +443,7 @@ TEST_F(MCJITCAPITest, yield) { buildMCJITOptions(); buildMCJITEngine(); LLVMContextRef C = LLVMGetGlobalContext(); - LLVMContextSetYieldCallback(C, yield, NULL); + LLVMContextSetYieldCallback(C, yield, nullptr); buildAndRunPasses(); union { diff --git a/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp index f862999..98587f7 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp @@ -23,10 +23,10 @@ TEST(MCJITMemoryManagerTest, BasicAllocations) { uint8_t *code2 = MemMgr->allocateCodeSection(256, 0, 3, ""); uint8_t *data2 = MemMgr->allocateDataSection(256, 0, 4, "", false); - EXPECT_NE((uint8_t*)0, code1); - EXPECT_NE((uint8_t*)0, code2); - EXPECT_NE((uint8_t*)0, data1); - EXPECT_NE((uint8_t*)0, data2); + EXPECT_NE((uint8_t*)nullptr, code1); + EXPECT_NE((uint8_t*)nullptr, code2); + EXPECT_NE((uint8_t*)nullptr, data1); + EXPECT_NE((uint8_t*)nullptr, data2); // Initialize the data for (unsigned i = 0; i < 256; ++i) { @@ -56,10 +56,10 @@ TEST(MCJITMemoryManagerTest, LargeAllocations) { uint8_t *code2 = MemMgr->allocateCodeSection(0x100000, 0, 3, ""); uint8_t *data2 = MemMgr->allocateDataSection(0x100000, 0, 4, "", false); - EXPECT_NE((uint8_t*)0, code1); - EXPECT_NE((uint8_t*)0, code2); - EXPECT_NE((uint8_t*)0, data1); - EXPECT_NE((uint8_t*)0, data2); + EXPECT_NE((uint8_t*)nullptr, code1); + EXPECT_NE((uint8_t*)nullptr, code2); + EXPECT_NE((uint8_t*)nullptr, data1); + EXPECT_NE((uint8_t*)nullptr, data2); // Initialize the data for (unsigned i = 0; i < 0x100000; ++i) { @@ -98,8 +98,8 @@ TEST(MCJITMemoryManagerTest, ManyAllocations) { data[i][j] = 2 + (i % 254); } - EXPECT_NE((uint8_t *)0, code[i]); - EXPECT_NE((uint8_t *)0, data[i]); + EXPECT_NE((uint8_t *)nullptr, code[i]); + EXPECT_NE((uint8_t *)nullptr, data[i]); } // Verify the data (this is checking for overlaps in the addresses) @@ -141,8 +141,8 @@ TEST(MCJITMemoryManagerTest, ManyVariedAllocations) { data[i][j] = 2 + (i % 254); } - EXPECT_NE((uint8_t *)0, code[i]); - EXPECT_NE((uint8_t *)0, data[i]); + EXPECT_NE((uint8_t *)nullptr, code[i]); + EXPECT_NE((uint8_t *)nullptr, data[i]); uintptr_t CodeAlign = Align ? (uintptr_t)code[i] % Align : 0; uintptr_t DataAlign = Align ? (uintptr_t)data[i] % Align : 0; diff --git a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp index 46847d3..fbbab42 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp @@ -48,7 +48,7 @@ public: const MemoryBuffer* BufferFound = getObjectInternal(M); ModulesLookedUp.insert(M->getModuleIdentifier()); if (!BufferFound) - return NULL; + return nullptr; // Our test cache wants to maintain ownership of its object buffers // so we make a copy here for the execution engine. return MemoryBuffer::getMemBufferCopy(BufferFound->getBuffer()); @@ -67,7 +67,7 @@ public: const std::string ModuleID = M->getModuleIdentifier(); StringMap<const MemoryBuffer *>::iterator it = ObjMap.find(ModuleID); if (it == ObjMap.end()) - return 0; + return nullptr; return it->second; } @@ -101,13 +101,13 @@ protected: void compileAndRun(int ExpectedRC = OriginalRC) { // This function shouldn't be called until after SetUp. ASSERT_TRUE(bool(TheJIT)); - ASSERT_TRUE(0 != Main); + ASSERT_TRUE(nullptr != Main); // We may be using a null cache, so ensure compilation is valid. TheJIT->finalizeObject(); void *vPtr = TheJIT->getPointerToFunction(Main); - EXPECT_TRUE(0 != vPtr) + EXPECT_TRUE(nullptr != vPtr) << "Unable to get pointer to main() from JIT"; int (*FuncPtr)(void) = (int(*)(void))(intptr_t)vPtr; @@ -123,7 +123,7 @@ TEST_F(MCJITObjectCacheTest, SetNullObjectCache) { createJIT(M.release()); - TheJIT->setObjectCache(NULL); + TheJIT->setObjectCache(nullptr); compileAndRun(); } @@ -143,7 +143,7 @@ TEST_F(MCJITObjectCacheTest, VerifyBasicObjectCaching) { // Verify that our object cache does not contain the module yet. const MemoryBuffer *ObjBuffer = Cache->getObjectInternal(SavedModulePointer); - EXPECT_EQ(0, ObjBuffer); + EXPECT_EQ(nullptr, ObjBuffer); compileAndRun(); @@ -152,7 +152,7 @@ TEST_F(MCJITObjectCacheTest, VerifyBasicObjectCaching) { // Verify that our object cache now contains the module. ObjBuffer = Cache->getObjectInternal(SavedModulePointer); - EXPECT_TRUE(0 != ObjBuffer); + EXPECT_TRUE(nullptr != ObjBuffer); // Verify that the cache was only notified once. EXPECT_FALSE(Cache->wereDuplicatesInserted()); @@ -221,7 +221,7 @@ TEST_F(MCJITObjectCacheTest, VerifyNonLoadFromCache) { // Verify that our object cache does not contain the module yet. const MemoryBuffer *ObjBuffer = Cache->getObjectInternal(SecondModulePointer); - EXPECT_EQ(0, ObjBuffer); + EXPECT_EQ(nullptr, ObjBuffer); // Run the function and look for the replacement return code. compileAndRun(ReplacementRC); @@ -231,7 +231,7 @@ TEST_F(MCJITObjectCacheTest, VerifyNonLoadFromCache) { // Verify that our object cache now contains the module. ObjBuffer = Cache->getObjectInternal(SecondModulePointer); - EXPECT_TRUE(0 != ObjBuffer); + EXPECT_TRUE(nullptr != ObjBuffer); // Verify that MCJIT didn't try to cache this again. EXPECT_FALSE(Cache->wereDuplicatesInserted()); diff --git a/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp index a439508..c37c1d1 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITTest.cpp @@ -51,7 +51,7 @@ TEST_F(MCJITTest, global_variable) { GlobalValue *Global = insertGlobalInt32(M.get(), "test_global", initialValue); createJIT(M.release()); void *globalPtr = TheJIT->getPointerToGlobal(Global); - EXPECT_TRUE(0 != globalPtr) + EXPECT_TRUE(nullptr != globalPtr) << "Unable to get pointer to global value from JIT"; EXPECT_EQ(initialValue, *(int32_t*)globalPtr) diff --git a/unittests/IR/ConstantRangeTest.cpp b/unittests/IR/ConstantRangeTest.cpp index cdf7378..fa03302 100644 --- a/unittests/IR/ConstantRangeTest.cpp +++ b/unittests/IR/ConstantRangeTest.cpp @@ -99,11 +99,11 @@ TEST_F(ConstantRangeTest, Equality) { } TEST_F(ConstantRangeTest, SingleElement) { - EXPECT_EQ(Full.getSingleElement(), static_cast<APInt *>(NULL)); - EXPECT_EQ(Empty.getSingleElement(), static_cast<APInt *>(NULL)); + EXPECT_EQ(Full.getSingleElement(), static_cast<APInt *>(nullptr)); + EXPECT_EQ(Empty.getSingleElement(), static_cast<APInt *>(nullptr)); EXPECT_EQ(*One.getSingleElement(), APInt(16, 0xa)); - EXPECT_EQ(Some.getSingleElement(), static_cast<APInt *>(NULL)); - EXPECT_EQ(Wrap.getSingleElement(), static_cast<APInt *>(NULL)); + EXPECT_EQ(Some.getSingleElement(), static_cast<APInt *>(nullptr)); + EXPECT_EQ(Wrap.getSingleElement(), static_cast<APInt *>(nullptr)); EXPECT_FALSE(Full.isSingleElement()); EXPECT_FALSE(Empty.isSingleElement()); diff --git a/unittests/IR/ConstantsTest.cpp b/unittests/IR/ConstantsTest.cpp index c11729c..0cd8549 100644 --- a/unittests/IR/ConstantsTest.cpp +++ b/unittests/IR/ConstantsTest.cpp @@ -269,16 +269,6 @@ TEST(ConstantsTest, ReplaceWithConstantTest) { "this->replaceAllUsesWith\\(expr\\(this\\)\\) is NOT valid!"); } -TEST(ConstantsTest, ReplaceInAliasTest) { - std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext())); - - Type *Int32Ty = Type::getInt32Ty(getGlobalContext()); - auto *Global = cast<GlobalObject>(M->getOrInsertGlobal("dummy", Int32Ty)); - auto *GA = GlobalAlias::create(GlobalValue::ExternalLinkage, "alias", Global); - EXPECT_DEATH(Global->replaceAllUsesWith(GA), - "replaceAliasUseWith cannot form an alias cycle"); -} - #endif #endif diff --git a/unittests/IR/DominatorTreeTest.cpp b/unittests/IR/DominatorTreeTest.cpp index 98c2317..ab43d1c 100644 --- a/unittests/IR/DominatorTreeTest.cpp +++ b/unittests/IR/DominatorTreeTest.cpp @@ -213,7 +213,7 @@ namespace llvm { "}\n"; LLVMContext &C = getGlobalContext(); SMDiagnostic Err; - return ParseAssemblyString(ModuleStrig, NULL, Err, C); + return ParseAssemblyString(ModuleStrig, nullptr, Err, C); } TEST(DominatorTree, Unreachable) { diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp index 9796e44..2108575 100644 --- a/unittests/IR/IRBuilderTest.cpp +++ b/unittests/IR/IRBuilderTest.cpp @@ -31,11 +31,11 @@ protected: F = Function::Create(FTy, Function::ExternalLinkage, "", M.get()); BB = BasicBlock::Create(Ctx, "", F); GV = new GlobalVariable(*M, Type::getFloatTy(Ctx), true, - GlobalValue::ExternalLinkage, 0); + GlobalValue::ExternalLinkage, nullptr); } virtual void TearDown() { - BB = 0; + BB = nullptr; M.reset(); } @@ -71,9 +71,9 @@ TEST_F(IRBuilderTest, Lifetime) { IntrinsicInst *II_Start1 = dyn_cast<IntrinsicInst>(Start1); IntrinsicInst *II_End1 = dyn_cast<IntrinsicInst>(End1); - ASSERT_TRUE(II_Start1 != NULL); + ASSERT_TRUE(II_Start1 != nullptr); EXPECT_EQ(II_Start1->getIntrinsicID(), Intrinsic::lifetime_start); - ASSERT_TRUE(II_End1 != NULL); + ASSERT_TRUE(II_End1 != nullptr); EXPECT_EQ(II_End1->getIntrinsicID(), Intrinsic::lifetime_end); } @@ -203,7 +203,7 @@ TEST_F(IRBuilderTest, WrapFlags) { // Test instructions. GlobalVariable *G = new GlobalVariable(*M, Builder.getInt32Ty(), true, - GlobalValue::ExternalLinkage, 0); + GlobalValue::ExternalLinkage, nullptr); Value *V = Builder.CreateLoad(G); EXPECT_TRUE( cast<BinaryOperator>(Builder.CreateNSWAdd(V, V))->hasNoSignedWrap()); diff --git a/unittests/IR/InstructionsTest.cpp b/unittests/IR/InstructionsTest.cpp index 336f5a2..7ec9b62 100644 --- a/unittests/IR/InstructionsTest.cpp +++ b/unittests/IR/InstructionsTest.cpp @@ -415,7 +415,7 @@ TEST(InstructionsTest, isEliminableCastPair) { EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::PtrToInt, CastInst::IntToPtr, Int64PtrTy, Int64Ty, Int64PtrTy, - Int32Ty, 0, Int32Ty), + Int32Ty, nullptr, Int32Ty), CastInst::BitCast); // Source and destination have unknown sizes, but the same address space and @@ -423,7 +423,7 @@ TEST(InstructionsTest, isEliminableCastPair) { EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::PtrToInt, CastInst::IntToPtr, Int64PtrTy, Int64Ty, Int64PtrTy, - 0, 0, 0), + nullptr, nullptr, nullptr), CastInst::BitCast); // Source and destination have unknown sizes, but the same address space and @@ -431,21 +431,21 @@ TEST(InstructionsTest, isEliminableCastPair) { EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::PtrToInt, CastInst::IntToPtr, Int64PtrTy, Int32Ty, Int64PtrTy, - 0, 0, 0), + nullptr, nullptr, nullptr), 0U); // Middle pointer big enough -> bitcast. EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr, CastInst::PtrToInt, Int64Ty, Int64PtrTy, Int64Ty, - 0, Int64Ty, 0), + nullptr, Int64Ty, nullptr), CastInst::BitCast); // Middle pointer too small -> fail. EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr, CastInst::PtrToInt, Int64Ty, Int64PtrTy, Int64Ty, - 0, Int32Ty, 0), + nullptr, Int32Ty, nullptr), 0U); // Test that we don't eliminate bitcasts between different address spaces, @@ -464,21 +464,21 @@ TEST(InstructionsTest, isEliminableCastPair) { EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr, CastInst::AddrSpaceCast, Int16Ty, Int64PtrTyAS1, Int64PtrTyAS2, - 0, Int16SizePtr, Int64SizePtr), + nullptr, Int16SizePtr, Int64SizePtr), 0U); // Cannot simplify addrspacecast, ptrtoint EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::AddrSpaceCast, CastInst::PtrToInt, Int64PtrTyAS1, Int64PtrTyAS2, Int16Ty, - Int64SizePtr, Int16SizePtr, 0), + Int64SizePtr, Int16SizePtr, nullptr), 0U); // Pass since the bitcast address spaces are the same EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr, CastInst::BitCast, Int16Ty, Int64PtrTyAS1, Int64PtrTyAS1, - 0, 0, 0), + nullptr, nullptr, nullptr), CastInst::IntToPtr); } diff --git a/unittests/IR/LegacyPassManagerTest.cpp b/unittests/IR/LegacyPassManagerTest.cpp index df6f460..9c2a835 100644 --- a/unittests/IR/LegacyPassManagerTest.cpp +++ b/unittests/IR/LegacyPassManagerTest.cpp @@ -476,7 +476,7 @@ namespace llvm { // Function: test1 (func_test1) { - BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,0); + BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,nullptr); // Block entry (label_entry) CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry); @@ -491,7 +491,7 @@ namespace llvm { // Function: test2 (func_test2) { - BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,0); + BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,nullptr); // Block entry (label_entry_5) CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5); @@ -506,7 +506,7 @@ namespace llvm { // Function: test3 (func_test3) { - BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,0); + BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,nullptr); // Block entry (label_entry_8) CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8); @@ -524,10 +524,10 @@ namespace llvm { Value* int1_f = args++; int1_f->setName("f"); - BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,0); - BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,0); - BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,0); - BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,0); + BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,nullptr); + BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,nullptr); + BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,nullptr); + BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,nullptr); // Block entry (label_entry_11) BranchInst::Create(label_bb, label_entry_11); diff --git a/unittests/IR/MDBuilderTest.cpp b/unittests/IR/MDBuilderTest.cpp index c8b5a09..fc4674e 100644 --- a/unittests/IR/MDBuilderTest.cpp +++ b/unittests/IR/MDBuilderTest.cpp @@ -33,8 +33,8 @@ TEST_F(MDBuilderTest, createFPMath) { MDBuilder MDHelper(Context); MDNode *MD0 = MDHelper.createFPMath(0.0); MDNode *MD1 = MDHelper.createFPMath(1.0); - EXPECT_EQ(MD0, (MDNode *)0); - EXPECT_NE(MD1, (MDNode *)0); + EXPECT_EQ(MD0, (MDNode *)nullptr); + EXPECT_NE(MD1, (MDNode *)nullptr); EXPECT_EQ(MD1->getNumOperands(), 1U); Value *Op = MD1->getOperand(0); EXPECT_TRUE(isa<ConstantFP>(Op)); @@ -47,8 +47,8 @@ TEST_F(MDBuilderTest, createRangeMetadata) { APInt A(8, 1), B(8, 2); MDNode *R0 = MDHelper.createRange(A, A); MDNode *R1 = MDHelper.createRange(A, B); - EXPECT_EQ(R0, (MDNode *)0); - EXPECT_NE(R1, (MDNode *)0); + EXPECT_EQ(R0, (MDNode *)nullptr); + EXPECT_NE(R1, (MDNode *)nullptr); EXPECT_EQ(R1->getNumOperands(), 2U); EXPECT_TRUE(isa<ConstantInt>(R1->getOperand(0))); EXPECT_TRUE(isa<ConstantInt>(R1->getOperand(1))); @@ -66,8 +66,8 @@ TEST_F(MDBuilderTest, createAnonymousTBAARoot) { EXPECT_GE(R1->getNumOperands(), 1U); EXPECT_EQ(R0->getOperand(0), R0); EXPECT_EQ(R1->getOperand(0), R1); - EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == 0); - EXPECT_TRUE(R1->getNumOperands() == 1 || R1->getOperand(1) == 0); + EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == nullptr); + EXPECT_TRUE(R1->getNumOperands() == 1 || R1->getOperand(1) == nullptr); } TEST_F(MDBuilderTest, createTBAARoot) { MDBuilder MDHelper(Context); @@ -77,7 +77,7 @@ TEST_F(MDBuilderTest, createTBAARoot) { EXPECT_GE(R0->getNumOperands(), 1U); EXPECT_TRUE(isa<MDString>(R0->getOperand(0))); EXPECT_EQ(cast<MDString>(R0->getOperand(0))->getString(), "Root"); - EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == 0); + EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == nullptr); } TEST_F(MDBuilderTest, createTBAANode) { MDBuilder MDHelper(Context); diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp index 00a2783..4f7bd72 100644 --- a/unittests/IR/MetadataTest.cpp +++ b/unittests/IR/MetadataTest.cpp @@ -103,7 +103,7 @@ TEST_F(MDNodeTest, Simple) { #endif EXPECT_EQ(n4, n1); EXPECT_EQ(n5, n2); - EXPECT_EQ(n6, (Value*)0); + EXPECT_EQ(n6, (Value*)nullptr); EXPECT_EQ(3u, n1->getNumOperands()); EXPECT_EQ(s1, n1->getOperand(0)); diff --git a/unittests/IR/PassManagerTest.cpp b/unittests/IR/PassManagerTest.cpp index 310e48f..25037a7 100644 --- a/unittests/IR/PassManagerTest.cpp +++ b/unittests/IR/PassManagerTest.cpp @@ -168,7 +168,7 @@ struct TestInvalidationFunctionPass { Module *parseIR(const char *IR) { LLVMContext &C = getGlobalContext(); SMDiagnostic Err; - return ParseAssemblyString(IR, 0, Err, C); + return ParseAssemblyString(IR, nullptr, Err, C); } class PassManagerTest : public ::testing::Test { diff --git a/unittests/IR/PatternMatch.cpp b/unittests/IR/PatternMatch.cpp index bebee15..f3a27b8 100644 --- a/unittests/IR/PatternMatch.cpp +++ b/unittests/IR/PatternMatch.cpp @@ -230,17 +230,17 @@ TEST_F(PatternMatchTest, OverflowingBinOps) { m_NSWAdd(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNSWAdd(L, R))); EXPECT_EQ(L, MatchL); EXPECT_EQ(R, MatchR); - MatchL = MatchR = 0; + MatchL = MatchR = nullptr; EXPECT_TRUE( m_NSWSub(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNSWSub(L, R))); EXPECT_EQ(L, MatchL); EXPECT_EQ(R, MatchR); - MatchL = MatchR = 0; + MatchL = MatchR = nullptr; EXPECT_TRUE( m_NSWMul(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNSWMul(L, R))); EXPECT_EQ(L, MatchL); EXPECT_EQ(R, MatchR); - MatchL = MatchR = 0; + MatchL = MatchR = nullptr; EXPECT_TRUE(m_NSWShl(m_Value(MatchL), m_Value(MatchR)).match( IRB.CreateShl(L, R, "", /* NUW */ false, /* NSW */ true))); EXPECT_EQ(L, MatchL); @@ -250,17 +250,17 @@ TEST_F(PatternMatchTest, OverflowingBinOps) { m_NUWAdd(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNUWAdd(L, R))); EXPECT_EQ(L, MatchL); EXPECT_EQ(R, MatchR); - MatchL = MatchR = 0; + MatchL = MatchR = nullptr; EXPECT_TRUE( m_NUWSub(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNUWSub(L, R))); EXPECT_EQ(L, MatchL); EXPECT_EQ(R, MatchR); - MatchL = MatchR = 0; + MatchL = MatchR = nullptr; EXPECT_TRUE( m_NUWMul(m_Value(MatchL), m_Value(MatchR)).match(IRB.CreateNUWMul(L, R))); EXPECT_EQ(L, MatchL); EXPECT_EQ(R, MatchR); - MatchL = MatchR = 0; + MatchL = MatchR = nullptr; EXPECT_TRUE(m_NUWShl(m_Value(MatchL), m_Value(MatchR)).match( IRB.CreateShl(L, R, "", /* NUW */ true, /* NSW */ false))); EXPECT_EQ(L, MatchL); diff --git a/unittests/IR/TypeBuilderTest.cpp b/unittests/IR/TypeBuilderTest.cpp index be493cd..b7b3e45 100644 --- a/unittests/IR/TypeBuilderTest.cpp +++ b/unittests/IR/TypeBuilderTest.cpp @@ -234,19 +234,19 @@ TEST(TypeBuilderTest, Extensions) { TypeBuilder<int, false>::get(getGlobalContext()), TypeBuilder<int*, false>::get(getGlobalContext()), TypeBuilder<void*[], false>::get(getGlobalContext()), - (void*)0)), + (void*)nullptr)), (TypeBuilder<MyType*, false>::get(getGlobalContext()))); EXPECT_EQ(PointerType::getUnqual(StructType::get( TypeBuilder<types::i<32>, false>::get(getGlobalContext()), TypeBuilder<types::i<32>*, false>::get(getGlobalContext()), TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()), - (void*)0)), + (void*)nullptr)), (TypeBuilder<MyPortableType*, false>::get(getGlobalContext()))); EXPECT_EQ(PointerType::getUnqual(StructType::get( TypeBuilder<types::i<32>, false>::get(getGlobalContext()), TypeBuilder<types::i<32>*, false>::get(getGlobalContext()), TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()), - (void*)0)), + (void*)nullptr)), (TypeBuilder<MyPortableType*, true>::get(getGlobalContext()))); } diff --git a/unittests/IR/UserTest.cpp b/unittests/IR/UserTest.cpp index 9c0e7b2..eb07e82 100644 --- a/unittests/IR/UserTest.cpp +++ b/unittests/IR/UserTest.cpp @@ -65,7 +65,7 @@ TEST(UserTest, ValueOpIteration) { " ret void\n" "}\n"; SMDiagnostic Err; - Module *M = ParseAssemblyString(ModuleString, NULL, Err, C); + Module *M = ParseAssemblyString(ModuleString, nullptr, Err, C); Function *F = M->getFunction("f"); BasicBlock &ExitBB = F->back(); diff --git a/unittests/IR/ValueHandleTest.cpp b/unittests/IR/ValueHandleTest.cpp index 15a0c22..403d2bc 100644 --- a/unittests/IR/ValueHandleTest.cpp +++ b/unittests/IR/ValueHandleTest.cpp @@ -94,7 +94,7 @@ TEST_F(ValueHandle, WeakVH_NullOnDeletion) { WeakVH WVH_Copy(WVH); WeakVH WVH_Recreated(BitcastV.get()); BitcastV.reset(); - Value *null_value = NULL; + Value *null_value = nullptr; EXPECT_EQ(null_value, WVH); EXPECT_EQ(null_value, WVH_Copy); EXPECT_EQ(null_value, WVH_Recreated); @@ -178,10 +178,10 @@ TEST_F(ValueHandle, AssertingVH_Asserts) { EXPECT_DEATH({BitcastV.reset();}, "An asserting value handle still pointed to this value!"); AssertingVH<Value> Copy(AVH); - AVH = NULL; + AVH = nullptr; EXPECT_DEATH({BitcastV.reset();}, "An asserting value handle still pointed to this value!"); - Copy = NULL; + Copy = nullptr; BitcastV.reset(); } @@ -263,14 +263,14 @@ TEST_F(ValueHandle, CallbackVH_CallbackOnRAUW) { int DeletedCalls; Value *AURWArgument; - RecordingVH() : DeletedCalls(0), AURWArgument(NULL) {} + RecordingVH() : DeletedCalls(0), AURWArgument(nullptr) {} RecordingVH(Value *V) - : CallbackVH(V), DeletedCalls(0), AURWArgument(NULL) {} + : CallbackVH(V), DeletedCalls(0), AURWArgument(nullptr) {} private: virtual void deleted() { DeletedCalls++; CallbackVH::deleted(); } virtual void allUsesReplacedWith(Value *new_value) { - EXPECT_EQ(NULL, AURWArgument); + EXPECT_EQ(nullptr, AURWArgument); AURWArgument = new_value; } }; @@ -278,7 +278,7 @@ TEST_F(ValueHandle, CallbackVH_CallbackOnRAUW) { RecordingVH RVH; RVH = BitcastV.get(); EXPECT_EQ(0, RVH.DeletedCalls); - EXPECT_EQ(NULL, RVH.AURWArgument); + EXPECT_EQ(nullptr, RVH.AURWArgument); BitcastV->replaceAllUsesWith(ConstantV); EXPECT_EQ(0, RVH.DeletedCalls); EXPECT_EQ(ConstantV, RVH.AURWArgument); @@ -291,21 +291,21 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) { Value *AURWArgument; LLVMContext *Context; - RecoveringVH() : DeletedCalls(0), AURWArgument(NULL), + RecoveringVH() : DeletedCalls(0), AURWArgument(nullptr), Context(&getGlobalContext()) {} RecoveringVH(Value *V) - : CallbackVH(V), DeletedCalls(0), AURWArgument(NULL), + : CallbackVH(V), DeletedCalls(0), AURWArgument(nullptr), Context(&getGlobalContext()) {} private: virtual void deleted() { getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::getInt32Ty(getGlobalContext()))); - setValPtr(NULL); + setValPtr(nullptr); } virtual void allUsesReplacedWith(Value *new_value) { - ASSERT_TRUE(NULL != getValPtr()); + ASSERT_TRUE(nullptr != getValPtr()); EXPECT_EQ(1U, getValPtr()->getNumUses()); - EXPECT_EQ(NULL, AURWArgument); + EXPECT_EQ(nullptr, AURWArgument); AURWArgument = new_value; } }; @@ -368,8 +368,8 @@ TEST_F(ValueHandle, DestroyingOtherVHOnSameValueDoesntBreakIteration) { WeakVH ShouldBeVisited2(BitcastV.get()); BitcastV.reset(); - EXPECT_EQ(NULL, static_cast<Value*>(ShouldBeVisited1)); - EXPECT_EQ(NULL, static_cast<Value*>(ShouldBeVisited2)); + EXPECT_EQ(nullptr, static_cast<Value*>(ShouldBeVisited1)); + EXPECT_EQ(nullptr, static_cast<Value*>(ShouldBeVisited2)); } } @@ -389,8 +389,8 @@ TEST_F(ValueHandle, AssertingVHCheckedLast) { } virtual void deleted() { - *ToClear[0] = 0; - *ToClear[1] = 0; + *ToClear[0] = nullptr; + *ToClear[1] = nullptr; CallbackVH::deleted(); } }; diff --git a/unittests/IR/ValueMapTest.cpp b/unittests/IR/ValueMapTest.cpp index 6fd87b1..0b7198f 100644 --- a/unittests/IR/ValueMapTest.cpp +++ b/unittests/IR/ValueMapTest.cpp @@ -40,21 +40,21 @@ TYPED_TEST_CASE(ValueMapTest, KeyTypes); TYPED_TEST(ValueMapTest, Null) { ValueMap<TypeParam*, int> VM1; - VM1[NULL] = 7; - EXPECT_EQ(7, VM1.lookup(NULL)); + VM1[nullptr] = 7; + EXPECT_EQ(7, VM1.lookup(nullptr)); } TYPED_TEST(ValueMapTest, FollowsValue) { ValueMap<TypeParam*, int> VM; VM[this->BitcastV.get()] = 7; EXPECT_EQ(7, VM.lookup(this->BitcastV.get())); - EXPECT_EQ(0, VM.count(this->AddV.get())); + EXPECT_EQ(0u, VM.count(this->AddV.get())); this->BitcastV->replaceAllUsesWith(this->AddV.get()); EXPECT_EQ(7, VM.lookup(this->AddV.get())); - EXPECT_EQ(0, VM.count(this->BitcastV.get())); + EXPECT_EQ(0u, VM.count(this->BitcastV.get())); this->AddV.reset(); - EXPECT_EQ(0, VM.count(this->AddV.get())); - EXPECT_EQ(0, VM.count(this->BitcastV.get())); + EXPECT_EQ(0u, VM.count(this->AddV.get())); + EXPECT_EQ(0u, VM.count(this->BitcastV.get())); EXPECT_EQ(0U, VM.size()); } @@ -90,7 +90,7 @@ TYPED_TEST(ValueMapTest, OperationsWork) { EXPECT_EQ(this->AddV.get(), InsertResult1.first->first); EXPECT_EQ(3, InsertResult1.first->second); EXPECT_TRUE(InsertResult1.second); - EXPECT_EQ(true, VM.count(this->AddV.get())); + EXPECT_EQ(1u, VM.count(this->AddV.get())); std::pair<typename ValueMap<TypeParam*, int>::iterator, bool> InsertResult2 = VM.insert(std::make_pair(this->AddV.get(), 5)); EXPECT_EQ(this->AddV.get(), InsertResult2.first->first); @@ -169,7 +169,7 @@ TYPED_TEST(ValueMapTest, DefaultCollisionBehavior) { VM[this->BitcastV.get()] = 7; VM[this->AddV.get()] = 9; this->BitcastV->replaceAllUsesWith(this->AddV.get()); - EXPECT_EQ(0, VM.count(this->BitcastV.get())); + EXPECT_EQ(0u, VM.count(this->BitcastV.get())); EXPECT_EQ(9, VM.lookup(this->AddV.get())); } @@ -177,10 +177,10 @@ TYPED_TEST(ValueMapTest, ConfiguredCollisionBehavior) { // TODO: Implement this when someone needs it. } -template<typename KeyT> -struct LockMutex : ValueMapConfig<KeyT> { +template<typename KeyT, typename MutexT> +struct LockMutex : ValueMapConfig<KeyT, MutexT> { struct ExtraData { - sys::Mutex *M; + MutexT *M; bool *CalledRAUW; bool *CalledDeleted; }; @@ -192,15 +192,15 @@ struct LockMutex : ValueMapConfig<KeyT> { *Data.CalledDeleted = true; EXPECT_FALSE(Data.M->tryacquire()) << "Mutex should already be locked."; } - static sys::Mutex *getMutex(const ExtraData &Data) { return Data.M; } + static MutexT *getMutex(const ExtraData &Data) { return Data.M; } }; #if LLVM_ENABLE_THREADS TYPED_TEST(ValueMapTest, LocksMutex) { sys::Mutex M(false); // Not recursive. bool CalledRAUW = false, CalledDeleted = false; - typename LockMutex<TypeParam*>::ExtraData Data = - {&M, &CalledRAUW, &CalledDeleted}; - ValueMap<TypeParam*, int, LockMutex<TypeParam*> > VM(Data); + typedef LockMutex<TypeParam*, sys::Mutex> ConfigType; + typename ConfigType::ExtraData Data = {&M, &CalledRAUW, &CalledDeleted}; + ValueMap<TypeParam*, int, ConfigType> VM(Data); VM[this->BitcastV.get()] = 7; this->BitcastV->replaceAllUsesWith(this->AddV.get()); this->AddV.reset(); @@ -218,7 +218,7 @@ TYPED_TEST(ValueMapTest, NoFollowRAUW) { ValueMap<TypeParam*, int, NoFollow<TypeParam*> > VM; VM[this->BitcastV.get()] = 7; EXPECT_EQ(7, VM.lookup(this->BitcastV.get())); - EXPECT_EQ(0, VM.count(this->AddV.get())); + EXPECT_EQ(0u, VM.count(this->AddV.get())); this->BitcastV->replaceAllUsesWith(this->AddV.get()); EXPECT_EQ(7, VM.lookup(this->BitcastV.get())); EXPECT_EQ(0, VM.lookup(this->AddV.get())); @@ -284,11 +284,11 @@ TYPED_TEST(ValueMapTest, SurvivesModificationByConfig) { // Now the ModifyingConfig can modify the Map inside a callback. VM[this->BitcastV.get()] = 7; this->BitcastV->replaceAllUsesWith(this->AddV.get()); - EXPECT_FALSE(VM.count(this->BitcastV.get())); - EXPECT_FALSE(VM.count(this->AddV.get())); + EXPECT_EQ(0u, VM.count(this->BitcastV.get())); + EXPECT_EQ(0u, VM.count(this->AddV.get())); VM[this->AddV.get()] = 7; this->AddV.reset(); - EXPECT_FALSE(VM.count(this->AddV.get())); + EXPECT_EQ(0u, VM.count(this->AddV.get())); } } diff --git a/unittests/IR/ValueTest.cpp b/unittests/IR/ValueTest.cpp index d92bc82..61e44a9 100644 --- a/unittests/IR/ValueTest.cpp +++ b/unittests/IR/ValueTest.cpp @@ -34,7 +34,7 @@ TEST(ValueTest, UsedInBasicBlock) { " ret void\n" "}\n"; SMDiagnostic Err; - Module *M = ParseAssemblyString(ModuleString, NULL, Err, C); + Module *M = ParseAssemblyString(ModuleString, nullptr, Err, C); Function *F = M->getFunction("f"); @@ -56,7 +56,7 @@ TEST(GlobalTest, CreateAddressSpace) { GlobalValue::ExternalLinkage, Constant::getAllOnesValue(Int32Ty), "dummy", - 0, + nullptr, GlobalVariable::NotThreadLocal, 1); @@ -74,7 +74,7 @@ TEST(GlobalTest, CreateAddressSpace) { GlobalValue::ExternalLinkage, Constant::getAllOnesValue(Int32Ty), "dummy_cast", - 0, + nullptr, GlobalVariable::NotThreadLocal, 1); diff --git a/unittests/IR/VerifierTest.cpp b/unittests/IR/VerifierTest.cpp index 252bdd3..71e3168 100644 --- a/unittests/IR/VerifierTest.cpp +++ b/unittests/IR/VerifierTest.cpp @@ -44,23 +44,6 @@ TEST(VerifierTest, Branch_i1) { EXPECT_TRUE(verifyFunction(*F)); } -TEST(VerifierTest, AliasUnnamedAddr) { - LLVMContext &C = getGlobalContext(); - Module M("M", C); - Type *Ty = Type::getInt8Ty(C); - Constant *Init = Constant::getNullValue(Ty); - GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true, - GlobalValue::ExternalLinkage, - Init, "foo"); - auto *GA = GlobalAlias::create(GlobalValue::ExternalLinkage, "bar", Aliasee); - GA->setUnnamedAddr(true); - std::string Error; - raw_string_ostream ErrorOS(Error); - EXPECT_TRUE(verifyModule(M, &ErrorOS)); - EXPECT_TRUE( - StringRef(ErrorOS.str()).startswith("Alias cannot have unnamed_addr")); -} - TEST(VerifierTest, InvalidRetAttribute) { LLVMContext &C = getGlobalContext(); Module M("M", C); diff --git a/unittests/IR/WaymarkTest.cpp b/unittests/IR/WaymarkTest.cpp index 9a9b4a2..8e3cd45 100644 --- a/unittests/IR/WaymarkTest.cpp +++ b/unittests/IR/WaymarkTest.cpp @@ -31,7 +31,7 @@ TEST(WaymarkTest, NativeArray) { FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true); Function *F = Function::Create(FT, GlobalValue::ExternalLinkage); const CallInst *A = CallInst::Create(F, makeArrayRef(values)); - ASSERT_NE(A, (const CallInst*)NULL); + ASSERT_NE(A, (const CallInst*)nullptr); ASSERT_EQ(1U + 22, A->getNumOperands()); const Use *U = &A->getOperandUse(0); const Use *Ue = &A->getOperandUse(22); diff --git a/unittests/Linker/LinkModulesTest.cpp b/unittests/Linker/LinkModulesTest.cpp index 1d5db36..4ccced1 100644 --- a/unittests/Linker/LinkModulesTest.cpp +++ b/unittests/Linker/LinkModulesTest.cpp @@ -36,7 +36,7 @@ protected: ArrayType *AT = ArrayType::get(Type::getInt8PtrTy(Ctx), 3); GV = new GlobalVariable(*M.get(), AT, false /*=isConstant*/, - GlobalValue::InternalLinkage, 0, "switch.bas"); + GlobalValue::InternalLinkage, nullptr,"switch.bas"); // Global Initializer std::vector<Constant *> Init; @@ -88,7 +88,7 @@ TEST_F(LinkModuleTest, BlockAddress) { Builder.CreateRet(ConstantPointerNull::get(Type::getInt8PtrTy(Ctx))); Module *LinkedModule = new Module("MyModuleLinked", Ctx); - Linker::LinkModules(LinkedModule, M.get(), Linker::PreserveSource, 0); + Linker::LinkModules(LinkedModule, M.get(), Linker::PreserveSource, nullptr); // Delete the original module. M.reset(); @@ -138,16 +138,16 @@ TEST_F(LinkModuleTest, EmptyModule) { GlobalVariable *GV = new GlobalVariable(*InternalM, STy, false /*=isConstant*/, - GlobalValue::InternalLinkage, 0, "g"); + GlobalValue::InternalLinkage, nullptr, "g"); GV->setInitializer(ConstantStruct::get(STy, F)); Module *EmptyM = new Module("EmptyModule1", Ctx); - Linker::LinkModules(EmptyM, InternalM, Linker::PreserveSource, 0); + Linker::LinkModules(EmptyM, InternalM, Linker::PreserveSource, nullptr); delete EmptyM; EmptyM = new Module("EmptyModule2", Ctx); - Linker::LinkModules(InternalM, EmptyM, Linker::PreserveSource, 0); + Linker::LinkModules(InternalM, EmptyM, Linker::PreserveSource, nullptr); delete EmptyM; delete InternalM; diff --git a/unittests/MC/CMakeLists.txt b/unittests/MC/CMakeLists.txt index 0e4782c..e2beab2 100644 --- a/unittests/MC/CMakeLists.txt +++ b/unittests/MC/CMakeLists.txt @@ -1,11 +1,9 @@ set(LLVM_LINK_COMPONENTS - MC - ) - -set(MCSources - MCAtomTest.cpp + MCAnalysis ) add_llvm_unittest(MCTests - ${MCSources} + MCAtomTest.cpp + StringTableBuilderTest.cpp + YAMLTest.cpp ) diff --git a/unittests/MC/MCAtomTest.cpp b/unittests/MC/MCAtomTest.cpp index 17b056c..16228b5 100644 --- a/unittests/MC/MCAtomTest.cpp +++ b/unittests/MC/MCAtomTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/MC/MCAtom.h" -#include "llvm/MC/MCModule.h" +#include "llvm/MC/MCAnalysis/MCAtom.h" +#include "llvm/MC/MCAnalysis/MCModule.h" #include "gtest/gtest.h" namespace llvm { diff --git a/unittests/MC/Makefile b/unittests/MC/Makefile index 4c25697..07a608e 100644 --- a/unittests/MC/Makefile +++ b/unittests/MC/Makefile @@ -9,7 +9,7 @@ LEVEL = ../.. TESTNAME = MC -LINK_COMPONENTS := MC +LINK_COMPONENTS := MCAnalysis include $(LEVEL)/Makefile.config include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/unittests/Object/StringTableBuilderTest.cpp b/unittests/MC/StringTableBuilderTest.cpp index 130eb4a..d30dc62 100644 --- a/unittests/Object/StringTableBuilderTest.cpp +++ b/unittests/MC/StringTableBuilderTest.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// +#include "llvm/MC/StringTableBuilder.h" #include "gtest/gtest.h" -#include "llvm/Object/StringTableBuilder.h" #include <string> using namespace llvm; diff --git a/unittests/Object/YAMLTest.cpp b/unittests/MC/YAMLTest.cpp index 1eb1113..09709ad 100644 --- a/unittests/Object/YAMLTest.cpp +++ b/unittests/MC/YAMLTest.cpp @@ -7,14 +7,14 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Object/YAML.h" +#include "llvm/MC/YAML.h" #include "llvm/Support/YAMLTraits.h" #include "gtest/gtest.h" using namespace llvm; struct BinaryHolder { - object::yaml::BinaryRef Binary; + yaml::BinaryRef Binary; }; namespace llvm { diff --git a/unittests/Makefile b/unittests/Makefile index 37f6540..603e7d5 100644 --- a/unittests/Makefile +++ b/unittests/Makefile @@ -10,7 +10,7 @@ LEVEL = .. PARALLEL_DIRS = ADT Analysis Bitcode CodeGen DebugInfo ExecutionEngine IR \ - LineEditor Linker MC Object Option Support Transforms + LineEditor Linker MC Option Support Transforms include $(LEVEL)/Makefile.config include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/unittests/Object/CMakeLists.txt b/unittests/Object/CMakeLists.txt deleted file mode 100644 index 580a894..0000000 --- a/unittests/Object/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -set(LLVM_LINK_COMPONENTS - Object - Support - ) - -add_llvm_unittest(ObjectTests - StringTableBuilderTest.cpp - YAMLTest.cpp - ) diff --git a/unittests/Object/Makefile b/unittests/Object/Makefile deleted file mode 100644 index 9062149..0000000 --- a/unittests/Object/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -##===- unittests/Object/Makefile ---------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LEVEL = ../.. -TESTNAME = Object -LINK_COMPONENTS := object - -include $(LEVEL)/Makefile.config -include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt index 0ea9310..97c5c43 100644 --- a/unittests/Support/CMakeLists.txt +++ b/unittests/Support/CMakeLists.txt @@ -29,7 +29,10 @@ add_llvm_unittest(SupportTests ProcessTest.cpp ProgramTest.cpp RegexTest.cpp + ScaledNumberTest.cpp SourceMgrTest.cpp + SpecialCaseListTest.cpp + StringPool.cpp SwapByteOrderTest.cpp ThreadLocalTest.cpp TimeValueTest.cpp diff --git a/unittests/Support/Casting.cpp b/unittests/Support/Casting.cpp index 228c90b..88c7d19 100644 --- a/unittests/Support/Casting.cpp +++ b/unittests/Support/Casting.cpp @@ -18,7 +18,7 @@ namespace llvm { // Used to test illegal cast. If a cast doesn't match any of the "real" ones, // it will match this one. struct IllegalCast; -template <typename T> IllegalCast *cast(...) { return 0; } +template <typename T> IllegalCast *cast(...) { return nullptr; } // set up two example classes // with conversion facility @@ -90,7 +90,7 @@ static_assert(std::is_same<simplify_type<foo *>::SimpleType, foo *>::value, namespace { -const foo *null_foo = NULL; +const foo *null_foo = nullptr; bar B; extern bar &B1; @@ -175,7 +175,7 @@ TEST(CastingTest, dyn_cast_or_null) { const bar *B2 = &B; } // anonymous namespace -bar *llvm::fub() { return 0; } +bar *llvm::fub() { return nullptr; } namespace { namespace inferred_upcasting { @@ -203,7 +203,7 @@ TEST(CastingTest, UpcastIsInferred) { Derived D; EXPECT_TRUE(isa<Base>(D)); Base *BP = dyn_cast<Base>(&D); - EXPECT_TRUE(BP != NULL); + EXPECT_TRUE(BP != nullptr); } diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp index b0f1eb1..b2d71ab 100644 --- a/unittests/Support/CommandLineTest.cpp +++ b/unittests/Support/CommandLineTest.cpp @@ -23,7 +23,7 @@ class TempEnvVar { TempEnvVar(const char *name, const char *value) : name(name) { const char *old_value = getenv(name); - EXPECT_EQ(NULL, old_value) << old_value; + EXPECT_EQ(nullptr, old_value) << old_value; #if HAVE_SETENV setenv(name, value, true); #else diff --git a/unittests/Support/ConvertUTFTest.cpp b/unittests/Support/ConvertUTFTest.cpp index 13ea75b..16c9beb 100644 --- a/unittests/Support/ConvertUTFTest.cpp +++ b/unittests/Support/ConvertUTFTest.cpp @@ -10,6 +10,8 @@ #include "llvm/Support/ConvertUTF.h" #include "gtest/gtest.h" #include <string> +#include <vector> +#include <utility> using namespace llvm; @@ -63,3 +65,1600 @@ TEST(ConvertUTFTest, HasUTF16BOM) { HasBOM = hasUTF16ByteOrderMark(ArrayRef<char>("\xfe", 1)); EXPECT_FALSE(HasBOM); } + +struct ConvertUTFResultContainer { + ConversionResult ErrorCode; + std::vector<unsigned> UnicodeScalars; + + ConvertUTFResultContainer(ConversionResult ErrorCode) + : ErrorCode(ErrorCode) {} + + ConvertUTFResultContainer + withScalars(unsigned US0 = 0x110000, unsigned US1 = 0x110000, + unsigned US2 = 0x110000, unsigned US3 = 0x110000, + unsigned US4 = 0x110000, unsigned US5 = 0x110000, + unsigned US6 = 0x110000, unsigned US7 = 0x110000) { + ConvertUTFResultContainer Result(*this); + if (US0 != 0x110000) + Result.UnicodeScalars.push_back(US0); + if (US1 != 0x110000) + Result.UnicodeScalars.push_back(US1); + if (US2 != 0x110000) + Result.UnicodeScalars.push_back(US2); + if (US3 != 0x110000) + Result.UnicodeScalars.push_back(US3); + if (US4 != 0x110000) + Result.UnicodeScalars.push_back(US4); + if (US5 != 0x110000) + Result.UnicodeScalars.push_back(US5); + if (US6 != 0x110000) + Result.UnicodeScalars.push_back(US6); + if (US7 != 0x110000) + Result.UnicodeScalars.push_back(US7); + return Result; + } +}; + +std::pair<ConversionResult, std::vector<unsigned>> +ConvertUTF8ToUnicodeScalarsLenient(StringRef S) { + const UTF8 *SourceStart = reinterpret_cast<const UTF8 *>(S.data()); + + const UTF8 *SourceNext = SourceStart; + std::vector<UTF32> Decoded(S.size(), 0); + UTF32 *TargetStart = Decoded.data(); + + auto ErrorCode = + ConvertUTF8toUTF32(&SourceNext, SourceStart + S.size(), &TargetStart, + Decoded.data() + Decoded.size(), lenientConversion); + + Decoded.resize(TargetStart - Decoded.data()); + + return std::make_pair(ErrorCode, Decoded); +} + +std::pair<ConversionResult, std::vector<unsigned>> +ConvertUTF8ToUnicodeScalarsPartialLenient(StringRef S) { + const UTF8 *SourceStart = reinterpret_cast<const UTF8 *>(S.data()); + + const UTF8 *SourceNext = SourceStart; + std::vector<UTF32> Decoded(S.size(), 0); + UTF32 *TargetStart = Decoded.data(); + + auto ErrorCode = ConvertUTF8toUTF32Partial( + &SourceNext, SourceStart + S.size(), &TargetStart, + Decoded.data() + Decoded.size(), lenientConversion); + + Decoded.resize(TargetStart - Decoded.data()); + + return std::make_pair(ErrorCode, Decoded); +} + +::testing::AssertionResult +CheckConvertUTF8ToUnicodeScalars(ConvertUTFResultContainer Expected, + StringRef S, bool Partial = false) { + ConversionResult ErrorCode; + std::vector<unsigned> Decoded; + if (!Partial) + std::tie(ErrorCode, Decoded) = ConvertUTF8ToUnicodeScalarsLenient(S); + else + + std::tie(ErrorCode, Decoded) = ConvertUTF8ToUnicodeScalarsPartialLenient(S); + if (Expected.ErrorCode != ErrorCode) + return ::testing::AssertionFailure() << "Expected error code " + << Expected.ErrorCode << ", actual " + << ErrorCode; + + if (Expected.UnicodeScalars != Decoded) + return ::testing::AssertionFailure() + << "Expected lenient decoded result:\n" + << ::testing::PrintToString(Expected.UnicodeScalars) << "\n" + << "Actual result:\n" << ::testing::PrintToString(Decoded); + + return ::testing::AssertionSuccess(); +} + +TEST(ConvertUTFTest, UTF8ToUTF32Lenient) { + + // + // 1-byte sequences + // + + // U+0041 LATIN CAPITAL LETTER A + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x0041), "\x41")); + + // + // 2-byte sequences + // + + // U+0283 LATIN SMALL LETTER ESH + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x0283), + "\xca\x83")); + + // U+03BA GREEK SMALL LETTER KAPPA + // U+1F79 GREEK SMALL LETTER OMICRON WITH OXIA + // U+03C3 GREEK SMALL LETTER SIGMA + // U+03BC GREEK SMALL LETTER MU + // U+03B5 GREEK SMALL LETTER EPSILON + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK) + .withScalars(0x03ba, 0x1f79, 0x03c3, 0x03bc, 0x03b5), + "\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5")); + + // + // 3-byte sequences + // + + // U+4F8B CJK UNIFIED IDEOGRAPH-4F8B + // U+6587 CJK UNIFIED IDEOGRAPH-6587 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x4f8b, 0x6587), + "\xe4\xbe\x8b\xe6\x96\x87")); + + // U+D55C HANGUL SYLLABLE HAN + // U+AE00 HANGUL SYLLABLE GEUL + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xd55c, 0xae00), + "\xed\x95\x9c\xea\xb8\x80")); + + // U+1112 HANGUL CHOSEONG HIEUH + // U+1161 HANGUL JUNGSEONG A + // U+11AB HANGUL JONGSEONG NIEUN + // U+1100 HANGUL CHOSEONG KIYEOK + // U+1173 HANGUL JUNGSEONG EU + // U+11AF HANGUL JONGSEONG RIEUL + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK) + .withScalars(0x1112, 0x1161, 0x11ab, 0x1100, 0x1173, 0x11af), + "\xe1\x84\x92\xe1\x85\xa1\xe1\x86\xab\xe1\x84\x80\xe1\x85\xb3" + "\xe1\x86\xaf")); + + // + // 4-byte sequences + // + + // U+E0100 VARIATION SELECTOR-17 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x000E0100), + "\xf3\xa0\x84\x80")); + + // + // First possible sequence of a certain length + // + + // U+0000 NULL + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x0000), + StringRef("\x00", 1))); + + // U+0080 PADDING CHARACTER + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x0080), + "\xc2\x80")); + + // U+0800 SAMARITAN LETTER ALAF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x0800), + "\xe0\xa0\x80")); + + // U+10000 LINEAR B SYLLABLE B008 A + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x10000), + "\xf0\x90\x80\x80")); + + // U+200000 (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf8\x88\x80\x80\x80")); + + // U+4000000 (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\x84\x80\x80\x80\x80")); + + // + // Last possible sequence of a certain length + // + + // U+007F DELETE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x007f), "\x7f")); + + // U+07FF (unassigned) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x07ff), + "\xdf\xbf")); + + // U+FFFF (noncharacter) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xffff), + "\xef\xbf\xbf")); + + // U+1FFFFF (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf7\xbf\xbf\xbf")); + + // U+3FFFFFF (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfb\xbf\xbf\xbf\xbf")); + + // U+7FFFFFFF (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfd\xbf\xbf\xbf\xbf\xbf")); + + // + // Other boundary conditions + // + + // U+D7FF (unassigned) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xd7ff), + "\xed\x9f\xbf")); + + // U+E000 (private use) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xe000), + "\xee\x80\x80")); + + // U+FFFD REPLACEMENT CHARACTER + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfffd), + "\xef\xbf\xbd")); + + // U+10FFFF (noncharacter) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x10ffff), + "\xf4\x8f\xbf\xbf")); + + // U+110000 (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf4\x90\x80\x80")); + + // + // Unexpected continuation bytes + // + + // A sequence of unexpected continuation bytes that don't follow a first + // byte, every byte is a maximal subpart. + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\x80\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xbf\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\x80\xbf\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\x80\xbf\x80\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\x80\xbf\x82\xbf\xaa")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xaa\xb0\xbb\xbf\xaa\xa0")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xaa\xb0\xbb\xbf\xaa\xa0\x8f")); + + // All continuation bytes (0x80--0xbf). + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" + "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" + "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" + "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf")); + + // + // Lonely start bytes + // + + // Start bytes of 2-byte sequences (0xc0--0xdf). + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" + "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020), + "\xc0\x20\xc1\x20\xc2\x20\xc3\x20\xc4\x20\xc5\x20\xc6\x20\xc7\x20" + "\xc8\x20\xc9\x20\xca\x20\xcb\x20\xcc\x20\xcd\x20\xce\x20\xcf\x20" + "\xd0\x20\xd1\x20\xd2\x20\xd3\x20\xd4\x20\xd5\x20\xd6\x20\xd7\x20" + "\xd8\x20\xd9\x20\xda\x20\xdb\x20\xdc\x20\xdd\x20\xde\x20\xdf\x20")); + + // Start bytes of 3-byte sequences (0xe0--0xef). + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020), + "\xe0\x20\xe1\x20\xe2\x20\xe3\x20\xe4\x20\xe5\x20\xe6\x20\xe7\x20" + "\xe8\x20\xe9\x20\xea\x20\xeb\x20\xec\x20\xed\x20\xee\x20\xef\x20")); + + // Start bytes of 4-byte sequences (0xf0--0xf7). + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, + 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020), + "\xf0\x20\xf1\x20\xf2\x20\xf3\x20\xf4\x20\xf5\x20\xf6\x20\xf7\x20")); + + // Start bytes of 5-byte sequences (0xf8--0xfb). + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf8\xf9\xfa\xfb")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020), + "\xf8\x20\xf9\x20\xfa\x20\xfb\x20")); + + // Start bytes of 6-byte sequences (0xfc--0xfd). + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xfc\xfd")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020), + "\xfc\x20\xfd\x20")); + + // + // Other bytes (0xc0--0xc1, 0xfe--0xff). + // + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xc0")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xc1")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfe")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xff")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xc0\xc1\xfe\xff")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfe\xfe\xff\xff")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfe\x80\x80\x80\x80\x80")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xff\x80\x80\x80\x80\x80")); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0x0020, 0xfffd, 0x0020, + 0xfffd, 0x0020, 0xfffd, 0x0020), + "\xc0\x20\xc1\x20\xfe\x20\xff\x20")); + + // + // Sequences with one continuation byte missing + // + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xc2")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xdf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xe0\xa0")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xe0\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xe1\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xec\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xed\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xed\x9f")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xee\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xef\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf0\x90\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf0\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf1\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf3\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf4\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf4\x8f\xbf")); + + // Overlong sequences with one trailing byte missing. + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xc0")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xc1")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xe0\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xe0\x9f")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf0\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf0\x8f\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf8\x80\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\x80\x80\x80\x80")); + + // Sequences that represent surrogates with one trailing byte missing. + // High surrogates + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xed\xa0")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xed\xac")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xed\xaf")); + // Low surrogates + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xed\xb0")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xed\xb4")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xed\xbf")); + + // Ill-formed 4-byte sequences. + // 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+1100xx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf4\x90\x80")); + // U+13FBxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf4\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf5\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf6\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf7\x80\x80")); + // U+1FFBxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf7\xbf\xbf")); + + // Ill-formed 5-byte sequences. + // 111110uu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+2000xx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf8\x88\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf8\xbf\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf9\x80\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfa\x80\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfb\x80\x80\x80")); + // U+3FFFFxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfb\xbf\xbf\xbf")); + + // Ill-formed 6-byte sequences. + // 1111110u 10uuuuuu 10uzzzzz 10zzzyyyy 10yyyyxx 10xxxxxx + // U+40000xx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\x84\x80\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\xbf\xbf\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfd\x80\x80\x80\x80")); + // U+7FFFFFxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfd\xbf\xbf\xbf\xbf")); + + // + // Sequences with two continuation bytes missing + // + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf0\x90")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf0\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf1\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf3\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf4\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), + "\xf4\x8f")); + + // Overlong sequences with two trailing byte missing. + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xe0")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf0\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf0\x8f")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf8\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\x80\x80\x80")); + + // Sequences that represent surrogates with two trailing bytes missing. + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xed")); + + // Ill-formed 4-byte sequences. + // 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+110yxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf4\x90")); + // U+13Fyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf4\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf5\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf6\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf7\x80")); + // U+1FFyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf7\xbf")); + + // Ill-formed 5-byte sequences. + // 111110uu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+200yxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf8\x88\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf8\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xf9\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xfa\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xfb\x80\x80")); + // U+3FFFyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xfb\xbf\xbf")); + + // Ill-formed 6-byte sequences. + // 1111110u 10uuuuuu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+4000yxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\x84\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\xbf\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfd\x80\x80\x80")); + // U+7FFFFyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfd\xbf\xbf\xbf")); + + // + // Sequences with three continuation bytes missing + // + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf0")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf1")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf2")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf3")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf4")); + + // Broken overlong sequences. + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf0")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf8\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xfc\x80\x80")); + + // Ill-formed 4-byte sequences. + // 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+14yyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf5")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf6")); + // U+1Cyyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf7")); + + // Ill-formed 5-byte sequences. + // 111110uu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+20yyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf8\x88")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf8\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xf9\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xfa\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xfb\x80")); + // U+3FCyyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xfb\xbf")); + + // Ill-formed 6-byte sequences. + // 1111110u 10uuuuuu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+400yyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xfc\x84\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xfc\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xfd\x80\x80")); + // U+7FFCyyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd, 0xfffd), + "\xfd\xbf\xbf")); + + // + // Sequences with four continuation bytes missing + // + + // Ill-formed 5-byte sequences. + // 111110uu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+uzyyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf8")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf9")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfa")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfb")); + // U+3zyyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfb")); + + // Broken overlong sequences. + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xf8")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xfc\x80")); + + // Ill-formed 6-byte sequences. + // 1111110u 10uuuuuu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+uzzyyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xfc\x84")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xfc\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xfd\x80")); + // U+7Fzzyyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xfd\xbf")); + + // + // Sequences with five continuation bytes missing + // + + // Ill-formed 6-byte sequences. + // 1111110u 10uuuuuu 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx + // U+uzzyyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfc")); + // U+uuzzyyxx (invalid) + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd), "\xfd")); + + // + // Consecutive sequences with trailing bytes missing + // + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, /**/ 0xfffd, 0xfffd, /**/ 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, /**/ 0xfffd, /**/ 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xc0" "\xe0\x80" "\xf0\x80\x80" + "\xf8\x80\x80\x80" + "\xfc\x80\x80\x80\x80" + "\xdf" "\xef\xbf" "\xf7\xbf\xbf" + "\xfb\xbf\xbf\xbf" + "\xfd\xbf\xbf\xbf\xbf")); + + // + // Overlong UTF-8 sequences + // + + // U+002F SOLIDUS + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x002f), "\x2f")); + + // Overlong sequences of the above. + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xc0\xaf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xe0\x80\xaf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf0\x80\x80\xaf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf8\x80\x80\x80\xaf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\x80\x80\x80\x80\xaf")); + + // U+0000 NULL + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x0000), + StringRef("\x00", 1))); + + // Overlong sequences of the above. + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xc0\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xe0\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf0\x80\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf8\x80\x80\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\x80\x80\x80\x80\x80")); + + // Other overlong sequences. + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xc0\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xc1\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal).withScalars(0xfffd, 0xfffd), + "\xc1\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xe0\x9f\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xed\xa0\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xed\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf0\x8f\x80\x80")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf0\x8f\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xf8\x87\xbf\xbf\xbf")); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xfc\x83\xbf\xbf\xbf\xbf")); + + // + // Isolated surrogates + // + + // Unicode 6.3.0: + // + // D71. High-surrogate code point: A Unicode code point in the range + // U+D800 to U+DBFF. + // + // D73. Low-surrogate code point: A Unicode code point in the range + // U+DC00 to U+DFFF. + + // Note: U+E0100 is <DB40 DD00> in UTF16. + + // High surrogates + + // U+D800 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xed\xa0\x80")); + + // U+DB40 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xed\xac\xa0")); + + // U+DBFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xed\xaf\xbf")); + + // Low surrogates + + // U+DC00 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xed\xb0\x80")); + + // U+DD00 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xed\xb4\x80")); + + // U+DFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd), + "\xed\xbf\xbf")); + + // Surrogate pairs + + // U+D800 U+DC00 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xed\xa0\x80\xed\xb0\x80")); + + // U+D800 U+DD00 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xed\xa0\x80\xed\xb4\x80")); + + // U+D800 U+DFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xed\xa0\x80\xed\xbf\xbf")); + + // U+DB40 U+DC00 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xed\xac\xa0\xed\xb0\x80")); + + // U+DB40 U+DD00 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xed\xac\xa0\xed\xb4\x80")); + + // U+DB40 U+DFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xed\xac\xa0\xed\xbf\xbf")); + + // U+DBFF U+DC00 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xed\xaf\xbf\xed\xb0\x80")); + + // U+DBFF U+DD00 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xed\xaf\xbf\xed\xb4\x80")); + + // U+DBFF U+DFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceIllegal) + .withScalars(0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd), + "\xed\xaf\xbf\xed\xbf\xbf")); + + // + // Noncharacters + // + + // Unicode 6.3.0: + // + // D14. Noncharacter: A code point that is permanently reserved for + // internal use and that should never be interchanged. Noncharacters + // consist of the values U+nFFFE and U+nFFFF (where n is from 0 to 1016) + // and the values U+FDD0..U+FDEF. + + // U+FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfffe), + "\xef\xbf\xbe")); + + // U+FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xffff), + "\xef\xbf\xbf")); + + // U+1FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x1fffe), + "\xf0\x9f\xbf\xbe")); + + // U+1FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x1ffff), + "\xf0\x9f\xbf\xbf")); + + // U+2FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x2fffe), + "\xf0\xaf\xbf\xbe")); + + // U+2FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x2ffff), + "\xf0\xaf\xbf\xbf")); + + // U+3FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x3fffe), + "\xf0\xbf\xbf\xbe")); + + // U+3FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x3ffff), + "\xf0\xbf\xbf\xbf")); + + // U+4FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x4fffe), + "\xf1\x8f\xbf\xbe")); + + // U+4FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x4ffff), + "\xf1\x8f\xbf\xbf")); + + // U+5FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x5fffe), + "\xf1\x9f\xbf\xbe")); + + // U+5FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x5ffff), + "\xf1\x9f\xbf\xbf")); + + // U+6FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x6fffe), + "\xf1\xaf\xbf\xbe")); + + // U+6FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x6ffff), + "\xf1\xaf\xbf\xbf")); + + // U+7FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x7fffe), + "\xf1\xbf\xbf\xbe")); + + // U+7FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x7ffff), + "\xf1\xbf\xbf\xbf")); + + // U+8FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x8fffe), + "\xf2\x8f\xbf\xbe")); + + // U+8FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x8ffff), + "\xf2\x8f\xbf\xbf")); + + // U+9FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x9fffe), + "\xf2\x9f\xbf\xbe")); + + // U+9FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x9ffff), + "\xf2\x9f\xbf\xbf")); + + // U+AFFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xafffe), + "\xf2\xaf\xbf\xbe")); + + // U+AFFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xaffff), + "\xf2\xaf\xbf\xbf")); + + // U+BFFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xbfffe), + "\xf2\xbf\xbf\xbe")); + + // U+BFFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xbffff), + "\xf2\xbf\xbf\xbf")); + + // U+CFFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xcfffe), + "\xf3\x8f\xbf\xbe")); + + // U+CFFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xcfffF), + "\xf3\x8f\xbf\xbf")); + + // U+DFFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xdfffe), + "\xf3\x9f\xbf\xbe")); + + // U+DFFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xdffff), + "\xf3\x9f\xbf\xbf")); + + // U+EFFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xefffe), + "\xf3\xaf\xbf\xbe")); + + // U+EFFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xeffff), + "\xf3\xaf\xbf\xbf")); + + // U+FFFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xffffe), + "\xf3\xbf\xbf\xbe")); + + // U+FFFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfffff), + "\xf3\xbf\xbf\xbf")); + + // U+10FFFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x10fffe), + "\xf4\x8f\xbf\xbe")); + + // U+10FFFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x10ffff), + "\xf4\x8f\xbf\xbf")); + + // U+FDD0 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd0), + "\xef\xb7\x90")); + + // U+FDD1 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd1), + "\xef\xb7\x91")); + + // U+FDD2 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd2), + "\xef\xb7\x92")); + + // U+FDD3 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd3), + "\xef\xb7\x93")); + + // U+FDD4 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd4), + "\xef\xb7\x94")); + + // U+FDD5 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd5), + "\xef\xb7\x95")); + + // U+FDD6 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd6), + "\xef\xb7\x96")); + + // U+FDD7 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd7), + "\xef\xb7\x97")); + + // U+FDD8 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd8), + "\xef\xb7\x98")); + + // U+FDD9 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdd9), + "\xef\xb7\x99")); + + // U+FDDA + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdda), + "\xef\xb7\x9a")); + + // U+FDDB + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfddb), + "\xef\xb7\x9b")); + + // U+FDDC + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfddc), + "\xef\xb7\x9c")); + + // U+FDDD + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfddd), + "\xef\xb7\x9d")); + + // U+FDDE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdde), + "\xef\xb7\x9e")); + + // U+FDDF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfddf), + "\xef\xb7\x9f")); + + // U+FDE0 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde0), + "\xef\xb7\xa0")); + + // U+FDE1 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde1), + "\xef\xb7\xa1")); + + // U+FDE2 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde2), + "\xef\xb7\xa2")); + + // U+FDE3 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde3), + "\xef\xb7\xa3")); + + // U+FDE4 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde4), + "\xef\xb7\xa4")); + + // U+FDE5 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde5), + "\xef\xb7\xa5")); + + // U+FDE6 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde6), + "\xef\xb7\xa6")); + + // U+FDE7 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde7), + "\xef\xb7\xa7")); + + // U+FDE8 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde8), + "\xef\xb7\xa8")); + + // U+FDE9 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfde9), + "\xef\xb7\xa9")); + + // U+FDEA + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdea), + "\xef\xb7\xaa")); + + // U+FDEB + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdeb), + "\xef\xb7\xab")); + + // U+FDEC + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdec), + "\xef\xb7\xac")); + + // U+FDED + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfded), + "\xef\xb7\xad")); + + // U+FDEE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdee), + "\xef\xb7\xae")); + + // U+FDEF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdef), + "\xef\xb7\xaf")); + + // U+FDF0 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf0), + "\xef\xb7\xb0")); + + // U+FDF1 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf1), + "\xef\xb7\xb1")); + + // U+FDF2 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf2), + "\xef\xb7\xb2")); + + // U+FDF3 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf3), + "\xef\xb7\xb3")); + + // U+FDF4 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf4), + "\xef\xb7\xb4")); + + // U+FDF5 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf5), + "\xef\xb7\xb5")); + + // U+FDF6 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf6), + "\xef\xb7\xb6")); + + // U+FDF7 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf7), + "\xef\xb7\xb7")); + + // U+FDF8 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf8), + "\xef\xb7\xb8")); + + // U+FDF9 + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdf9), + "\xef\xb7\xb9")); + + // U+FDFA + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdfa), + "\xef\xb7\xba")); + + // U+FDFB + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdfb), + "\xef\xb7\xbb")); + + // U+FDFC + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdfc), + "\xef\xb7\xbc")); + + // U+FDFD + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdfd), + "\xef\xb7\xbd")); + + // U+FDFE + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdfe), + "\xef\xb7\xbe")); + + // U+FDFF + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0xfdff), + "\xef\xb7\xbf")); +} + +TEST(ConvertUTFTest, UTF8ToUTF32PartialLenient) { + // U+0041 LATIN CAPITAL LETTER A + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(conversionOK).withScalars(0x0041), + "\x41", true)); + + // + // Sequences with one continuation byte missing + // + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xc2", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xdf", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xe0\xa0", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xe0\xbf", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xe1\x80", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xec\xbf", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xed\x80", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xed\x9f", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xee\x80", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xef\xbf", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xf0\x90\x80", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xf0\xbf\xbf", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xf1\x80\x80", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xf3\xbf\xbf", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xf4\x80\x80", true)); + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted), + "\xf4\x8f\xbf", true)); + + EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( + ConvertUTFResultContainer(sourceExhausted).withScalars(0x0041), + "\x41\xc2", true)); +} + diff --git a/unittests/Support/DataExtractorTest.cpp b/unittests/Support/DataExtractorTest.cpp index ec8bd3d..81de983 100644 --- a/unittests/Support/DataExtractorTest.cpp +++ b/unittests/Support/DataExtractorTest.cpp @@ -94,7 +94,7 @@ TEST(DataExtractorTest, Strings) { EXPECT_EQ(stringData, DE.getCStr(&offset)); EXPECT_EQ(11U, offset); - EXPECT_EQ(NULL, DE.getCStr(&offset)); + EXPECT_EQ(nullptr, DE.getCStr(&offset)); EXPECT_EQ(11U, offset); } diff --git a/unittests/Support/ErrorOrTest.cpp b/unittests/Support/ErrorOrTest.cpp index 18ce507..d76e7d6 100644 --- a/unittests/Support/ErrorOrTest.cpp +++ b/unittests/Support/ErrorOrTest.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/ErrorOr.h" +#include "llvm/Support/Errc.h" #include "gtest/gtest.h" #include <memory> @@ -30,7 +31,7 @@ TEST(ErrorOr, SimpleValue) { a = t2(); EXPECT_FALSE(a); - EXPECT_EQ(errc::invalid_argument, a.getError()); + EXPECT_EQ(a.getError(), errc::invalid_argument); #ifdef EXPECT_DEBUG_DEATH EXPECT_DEBUG_DEATH(*a, "Cannot get value when an error exists"); #endif @@ -54,10 +55,10 @@ struct B {}; struct D : B {}; TEST(ErrorOr, Covariant) { - ErrorOr<B*> b(ErrorOr<D*>(0)); - b = ErrorOr<D*>(0); + ErrorOr<B*> b(ErrorOr<D*>(nullptr)); + b = ErrorOr<D*>(nullptr); - ErrorOr<std::unique_ptr<B> > b1(ErrorOr<std::unique_ptr<D> >(0)); - b1 = ErrorOr<std::unique_ptr<D> >(0); + ErrorOr<std::unique_ptr<B> > b1(ErrorOr<std::unique_ptr<D> >(nullptr)); + b1 = ErrorOr<std::unique_ptr<D> >(nullptr); } } // end anon namespace diff --git a/unittests/Support/FileOutputBufferTest.cpp b/unittests/Support/FileOutputBufferTest.cpp index 0801f85..b086f1e 100644 --- a/unittests/Support/FileOutputBufferTest.cpp +++ b/unittests/Support/FileOutputBufferTest.cpp @@ -17,12 +17,13 @@ using namespace llvm; using namespace llvm::sys; -#define ASSERT_NO_ERROR(x) \ - if (error_code ASSERT_NO_ERROR_ec = x) { \ - errs() << #x ": did not return errc::success.\n" \ - << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ - << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ - } else {} +#define ASSERT_NO_ERROR(x) \ + if (std::error_code ASSERT_NO_ERROR_ec = x) { \ + errs() << #x ": did not return errc::success.\n" \ + << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ + << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ + } else { \ + } namespace { TEST(FileOutputBuffer, Test) { @@ -46,11 +47,7 @@ TEST(FileOutputBuffer, Test) { // Commit buffer. ASSERT_NO_ERROR(Buffer->commit()); } - // Verify file exists and starts with special header. - bool MagicMatches = false; - ASSERT_NO_ERROR(fs::has_magic(Twine(File1), Twine("AABBCCDDEEFFGGHHIIJJ"), - MagicMatches)); - EXPECT_TRUE(MagicMatches); + // Verify file is correct size. uint64_t File1Size; ASSERT_NO_ERROR(fs::file_size(Twine(File1), File1Size)); @@ -86,11 +83,7 @@ TEST(FileOutputBuffer, Test) { // Commit buffer, but size down to smaller size ASSERT_NO_ERROR(Buffer->commit(5000)); } - // Verify file exists and starts with special header. - bool MagicMatches3 = false; - ASSERT_NO_ERROR(fs::has_magic(Twine(File3), Twine("AABBCCDDEEFFGGHHIIJJ"), - MagicMatches3)); - EXPECT_TRUE(MagicMatches3); + // Verify file is correct size. uint64_t File3Size; ASSERT_NO_ERROR(fs::file_size(Twine(File3), File3Size)); diff --git a/unittests/Support/LockFileManagerTest.cpp b/unittests/Support/LockFileManagerTest.cpp index 93fa10b..885b7d6 100644 --- a/unittests/Support/LockFileManagerTest.cpp +++ b/unittests/Support/LockFileManagerTest.cpp @@ -19,7 +19,7 @@ namespace { TEST(LockFileManagerTest, Basic) { SmallString<64> TmpDir; - error_code EC; + std::error_code EC; EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir); ASSERT_FALSE(EC); @@ -46,7 +46,7 @@ TEST(LockFileManagerTest, Basic) { TEST(LockFileManagerTest, LinkLockExists) { SmallString<64> TmpDir; - error_code EC; + std::error_code EC; EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir); ASSERT_FALSE(EC); @@ -89,7 +89,7 @@ TEST(LockFileManagerTest, LinkLockExists) { TEST(LockFileManagerTest, RelativePath) { SmallString<64> TmpDir; - error_code EC; + std::error_code EC; EC = sys::fs::createUniqueDirectory("LockFileManagerTestDir", TmpDir); ASSERT_FALSE(EC); diff --git a/unittests/Support/ManagedStatic.cpp b/unittests/Support/ManagedStatic.cpp index 1497f4e..153884b 100644 --- a/unittests/Support/ManagedStatic.cpp +++ b/unittests/Support/ManagedStatic.cpp @@ -25,7 +25,7 @@ namespace test1 { llvm::ManagedStatic<int> ms; void *helper(void*) { *ms; - return NULL; + return nullptr; } // Valgrind's leak checker complains glibc's stack allocation. @@ -47,15 +47,13 @@ TEST(Initialize, MultipleThreads) { void *p1 = test1::allocate_stack(a1); void *p2 = test1::allocate_stack(a2); - llvm_start_multithreaded(); pthread_t t1, t2; - pthread_create(&t1, &a1, test1::helper, NULL); - pthread_create(&t2, &a2, test1::helper, NULL); - pthread_join(t1, NULL); - pthread_join(t2, NULL); + pthread_create(&t1, &a1, test1::helper, nullptr); + pthread_create(&t2, &a2, test1::helper, nullptr); + pthread_join(t1, nullptr); + pthread_join(t2, nullptr); free(p1); free(p2); - llvm_stop_multithreaded(); } #endif diff --git a/unittests/Support/MemoryBufferTest.cpp b/unittests/Support/MemoryBufferTest.cpp index 6790d0c..93bf301 100644 --- a/unittests/Support/MemoryBufferTest.cpp +++ b/unittests/Support/MemoryBufferTest.cpp @@ -43,15 +43,15 @@ protected: TEST_F(MemoryBufferTest, get) { // Default name and null-terminator flag OwningBuffer MB1(MemoryBuffer::getMemBuffer(data)); - EXPECT_TRUE(0 != MB1.get()); + EXPECT_TRUE(nullptr != MB1.get()); // RequiresNullTerminator = false OwningBuffer MB2(MemoryBuffer::getMemBuffer(data, "one", false)); - EXPECT_TRUE(0 != MB2.get()); + EXPECT_TRUE(nullptr != MB2.get()); // RequiresNullTerminator = true OwningBuffer MB3(MemoryBuffer::getMemBuffer(data, "two", true)); - EXPECT_TRUE(0 != MB3.get()); + EXPECT_TRUE(nullptr != MB3.get()); // verify all 3 buffers point to the same address EXPECT_EQ(MB1->getBufferStart(), MB2->getBufferStart()); @@ -77,11 +77,11 @@ TEST_F(MemoryBufferTest, NullTerminator4K) { } OF.close(); - OwningBuffer MB; - error_code EC = MemoryBuffer::getFile(TestPath.c_str(), MB); + ErrorOr<OwningBuffer> MB = MemoryBuffer::getFile(TestPath.c_str()); + std::error_code EC = MB.getError(); ASSERT_FALSE(EC); - const char *BufData = MB->getBufferStart(); + const char *BufData = MB.get()->getBufferStart(); EXPECT_EQ('f', BufData[4095]); EXPECT_EQ('\0', BufData[4096]); } @@ -89,11 +89,11 @@ TEST_F(MemoryBufferTest, NullTerminator4K) { TEST_F(MemoryBufferTest, copy) { // copy with no name OwningBuffer MBC1(MemoryBuffer::getMemBufferCopy(data)); - EXPECT_TRUE(0 != MBC1.get()); + EXPECT_TRUE(nullptr != MBC1.get()); // copy with a name OwningBuffer MBC2(MemoryBuffer::getMemBufferCopy(data, "copy")); - EXPECT_TRUE(0 != MBC2.get()); + EXPECT_TRUE(nullptr != MBC2.get()); // verify the two copies do not point to the same place EXPECT_NE(MBC1->getBufferStart(), MBC2->getBufferStart()); @@ -102,25 +102,25 @@ TEST_F(MemoryBufferTest, copy) { TEST_F(MemoryBufferTest, make_new) { // 0-sized buffer OwningBuffer Zero(MemoryBuffer::getNewUninitMemBuffer(0)); - EXPECT_TRUE(0 != Zero.get()); + EXPECT_TRUE(nullptr != Zero.get()); // uninitialized buffer with no name OwningBuffer One(MemoryBuffer::getNewUninitMemBuffer(321)); - EXPECT_TRUE(0 != One.get()); + EXPECT_TRUE(nullptr != One.get()); // uninitialized buffer with name OwningBuffer Two(MemoryBuffer::getNewUninitMemBuffer(123, "bla")); - EXPECT_TRUE(0 != Two.get()); + EXPECT_TRUE(nullptr != Two.get()); // 0-initialized buffer with no name OwningBuffer Three(MemoryBuffer::getNewMemBuffer(321, data)); - EXPECT_TRUE(0 != Three.get()); + EXPECT_TRUE(nullptr != Three.get()); for (size_t i = 0; i < 321; ++i) EXPECT_EQ(0, Three->getBufferStart()[0]); // 0-initialized buffer with name OwningBuffer Four(MemoryBuffer::getNewMemBuffer(123, "zeros")); - EXPECT_TRUE(0 != Four.get()); + EXPECT_TRUE(nullptr != Four.get()); for (size_t i = 0; i < 123; ++i) EXPECT_EQ(0, Four->getBufferStart()[0]); } @@ -146,14 +146,16 @@ void MemoryBufferTest::testGetOpenFileSlice(bool Reopen) { EXPECT_FALSE(sys::fs::openFileForRead(TestPath.c_str(), TestFD)); } - OwningBuffer Buf; - error_code EC = MemoryBuffer::getOpenFileSlice(TestFD, TestPath.c_str(), Buf, - 40000, // Size - 80000 // Offset - ); + ErrorOr<OwningBuffer> Buf = + MemoryBuffer::getOpenFileSlice(TestFD, TestPath.c_str(), + 40000, // Size + 80000 // Offset + ); + + std::error_code EC = Buf.getError(); EXPECT_FALSE(EC); - StringRef BufData = Buf->getBuffer(); + StringRef BufData = Buf.get()->getBuffer(); EXPECT_EQ(BufData.size(), 40000U); EXPECT_EQ(BufData[0], '0'); EXPECT_EQ(BufData[9], '9'); diff --git a/unittests/Support/MemoryTest.cpp b/unittests/Support/MemoryTest.cpp index fae67a8..8ad90e0 100644 --- a/unittests/Support/MemoryTest.cpp +++ b/unittests/Support/MemoryTest.cpp @@ -57,30 +57,30 @@ protected: }; TEST_P(MappedMemoryTest, AllocAndRelease) { - error_code EC; - MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + std::error_code EC; + MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), nullptr, Flags,EC); + EXPECT_EQ(std::error_code(), EC); - EXPECT_NE((void*)0, M1.base()); + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(sizeof(int), M1.size()); EXPECT_FALSE(Memory::releaseMappedMemory(M1)); } TEST_P(MappedMemoryTest, MultipleAllocAndRelease) { - error_code EC; - MemoryBlock M1 = Memory::allocateMappedMemory(16, 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - MemoryBlock M2 = Memory::allocateMappedMemory(64, 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - MemoryBlock M3 = Memory::allocateMappedMemory(32, 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - - EXPECT_NE((void*)0, M1.base()); + std::error_code EC; + MemoryBlock M1 = Memory::allocateMappedMemory(16, nullptr, Flags, EC); + EXPECT_EQ(std::error_code(), EC); + MemoryBlock M2 = Memory::allocateMappedMemory(64, nullptr, Flags, EC); + EXPECT_EQ(std::error_code(), EC); + MemoryBlock M3 = Memory::allocateMappedMemory(32, nullptr, Flags, EC); + EXPECT_EQ(std::error_code(), EC); + + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(16U, M1.size()); - EXPECT_NE((void*)0, M2.base()); + EXPECT_NE((void*)nullptr, M2.base()); EXPECT_LE(64U, M2.size()); - EXPECT_NE((void*)0, M3.base()); + EXPECT_NE((void*)nullptr, M3.base()); EXPECT_LE(32U, M3.size()); EXPECT_FALSE(doesOverlap(M1, M2)); @@ -89,9 +89,9 @@ TEST_P(MappedMemoryTest, MultipleAllocAndRelease) { EXPECT_FALSE(Memory::releaseMappedMemory(M1)); EXPECT_FALSE(Memory::releaseMappedMemory(M3)); - MemoryBlock M4 = Memory::allocateMappedMemory(16, 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - EXPECT_NE((void*)0, M4.base()); + MemoryBlock M4 = Memory::allocateMappedMemory(16, nullptr, Flags, EC); + EXPECT_EQ(std::error_code(), EC); + EXPECT_NE((void*)nullptr, M4.base()); EXPECT_LE(16U, M4.size()); EXPECT_FALSE(Memory::releaseMappedMemory(M4)); EXPECT_FALSE(Memory::releaseMappedMemory(M2)); @@ -103,11 +103,11 @@ TEST_P(MappedMemoryTest, BasicWrite) { !((Flags & Memory::MF_READ) && (Flags & Memory::MF_WRITE))) return; - error_code EC; - MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + std::error_code EC; + MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), nullptr, Flags,EC); + EXPECT_EQ(std::error_code(), EC); - EXPECT_NE((void*)0, M1.base()); + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(sizeof(int), M1.size()); int *a = (int*)M1.base(); @@ -122,23 +122,26 @@ TEST_P(MappedMemoryTest, MultipleWrite) { if (Flags && !((Flags & Memory::MF_READ) && (Flags & Memory::MF_WRITE))) return; - error_code EC; - MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - MemoryBlock M2 = Memory::allocateMappedMemory(8 * sizeof(int), 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - MemoryBlock M3 = Memory::allocateMappedMemory(4 * sizeof(int), 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + std::error_code EC; + MemoryBlock M1 = Memory::allocateMappedMemory(sizeof(int), nullptr, Flags, + EC); + EXPECT_EQ(std::error_code(), EC); + MemoryBlock M2 = Memory::allocateMappedMemory(8 * sizeof(int), nullptr, Flags, + EC); + EXPECT_EQ(std::error_code(), EC); + MemoryBlock M3 = Memory::allocateMappedMemory(4 * sizeof(int), nullptr, Flags, + EC); + EXPECT_EQ(std::error_code(), EC); EXPECT_FALSE(doesOverlap(M1, M2)); EXPECT_FALSE(doesOverlap(M2, M3)); EXPECT_FALSE(doesOverlap(M1, M3)); - EXPECT_NE((void*)0, M1.base()); + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(1U * sizeof(int), M1.size()); - EXPECT_NE((void*)0, M2.base()); + EXPECT_NE((void*)nullptr, M2.base()); EXPECT_LE(8U * sizeof(int), M2.size()); - EXPECT_NE((void*)0, M3.base()); + EXPECT_NE((void*)nullptr, M3.base()); EXPECT_LE(4U * sizeof(int), M3.size()); int *x = (int*)M1.base(); @@ -159,9 +162,10 @@ TEST_P(MappedMemoryTest, MultipleWrite) { EXPECT_FALSE(Memory::releaseMappedMemory(M1)); EXPECT_FALSE(Memory::releaseMappedMemory(M3)); - MemoryBlock M4 = Memory::allocateMappedMemory(64 * sizeof(int), 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - EXPECT_NE((void*)0, M4.base()); + MemoryBlock M4 = Memory::allocateMappedMemory(64 * sizeof(int), nullptr, + Flags, EC); + EXPECT_EQ(std::error_code(), EC); + EXPECT_NE((void*)nullptr, M4.base()); EXPECT_LE(64U * sizeof(int), M4.size()); x = (int*)M4.base(); *x = 4; @@ -176,19 +180,22 @@ TEST_P(MappedMemoryTest, MultipleWrite) { } TEST_P(MappedMemoryTest, EnabledWrite) { - error_code EC; - MemoryBlock M1 = Memory::allocateMappedMemory(2 * sizeof(int), 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - MemoryBlock M2 = Memory::allocateMappedMemory(8 * sizeof(int), 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - MemoryBlock M3 = Memory::allocateMappedMemory(4 * sizeof(int), 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - - EXPECT_NE((void*)0, M1.base()); + std::error_code EC; + MemoryBlock M1 = Memory::allocateMappedMemory(2 * sizeof(int), nullptr, Flags, + EC); + EXPECT_EQ(std::error_code(), EC); + MemoryBlock M2 = Memory::allocateMappedMemory(8 * sizeof(int), nullptr, Flags, + EC); + EXPECT_EQ(std::error_code(), EC); + MemoryBlock M3 = Memory::allocateMappedMemory(4 * sizeof(int), nullptr, Flags, + EC); + EXPECT_EQ(std::error_code(), EC); + + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(2U * sizeof(int), M1.size()); - EXPECT_NE((void*)0, M2.base()); + EXPECT_NE((void*)nullptr, M2.base()); EXPECT_LE(8U * sizeof(int), M2.size()); - EXPECT_NE((void*)0, M3.base()); + EXPECT_NE((void*)nullptr, M3.base()); EXPECT_LE(4U * sizeof(int), M3.size()); EXPECT_FALSE(Memory::protectMappedMemory(M1, getTestableEquivalent(Flags))); @@ -216,11 +223,12 @@ TEST_P(MappedMemoryTest, EnabledWrite) { EXPECT_FALSE(Memory::releaseMappedMemory(M3)); EXPECT_EQ(6, y[6]); - MemoryBlock M4 = Memory::allocateMappedMemory(16, 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); - EXPECT_NE((void*)0, M4.base()); + MemoryBlock M4 = Memory::allocateMappedMemory(16, nullptr, Flags, EC); + EXPECT_EQ(std::error_code(), EC); + EXPECT_NE((void*)nullptr, M4.base()); EXPECT_LE(16U, M4.size()); - EXPECT_EQ(error_code::success(), Memory::protectMappedMemory(M4, getTestableEquivalent(Flags))); + EXPECT_EQ(std::error_code(), + Memory::protectMappedMemory(M4, getTestableEquivalent(Flags))); x = (int*)M4.base(); *x = 4; EXPECT_EQ(4, *x); @@ -229,19 +237,19 @@ TEST_P(MappedMemoryTest, EnabledWrite) { } TEST_P(MappedMemoryTest, SuccessiveNear) { - error_code EC; - MemoryBlock M1 = Memory::allocateMappedMemory(16, 0, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + std::error_code EC; + MemoryBlock M1 = Memory::allocateMappedMemory(16, nullptr, Flags, EC); + EXPECT_EQ(std::error_code(), EC); MemoryBlock M2 = Memory::allocateMappedMemory(64, &M1, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); MemoryBlock M3 = Memory::allocateMappedMemory(32, &M2, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); - EXPECT_NE((void*)0, M1.base()); + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(16U, M1.size()); - EXPECT_NE((void*)0, M2.base()); + EXPECT_NE((void*)nullptr, M2.base()); EXPECT_LE(64U, M2.size()); - EXPECT_NE((void*)0, M3.base()); + EXPECT_NE((void*)nullptr, M3.base()); EXPECT_LE(32U, M3.size()); EXPECT_FALSE(doesOverlap(M1, M2)); @@ -254,20 +262,20 @@ TEST_P(MappedMemoryTest, SuccessiveNear) { } TEST_P(MappedMemoryTest, DuplicateNear) { - error_code EC; + std::error_code EC; MemoryBlock Near((void*)(3*PageSize), 16); MemoryBlock M1 = Memory::allocateMappedMemory(16, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); MemoryBlock M2 = Memory::allocateMappedMemory(64, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); MemoryBlock M3 = Memory::allocateMappedMemory(32, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); - EXPECT_NE((void*)0, M1.base()); + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(16U, M1.size()); - EXPECT_NE((void*)0, M2.base()); + EXPECT_NE((void*)nullptr, M2.base()); EXPECT_LE(64U, M2.size()); - EXPECT_NE((void*)0, M3.base()); + EXPECT_NE((void*)nullptr, M3.base()); EXPECT_LE(32U, M3.size()); EXPECT_FALSE(Memory::releaseMappedMemory(M1)); @@ -276,20 +284,20 @@ TEST_P(MappedMemoryTest, DuplicateNear) { } TEST_P(MappedMemoryTest, ZeroNear) { - error_code EC; - MemoryBlock Near(0, 0); + std::error_code EC; + MemoryBlock Near(nullptr, 0); MemoryBlock M1 = Memory::allocateMappedMemory(16, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); MemoryBlock M2 = Memory::allocateMappedMemory(64, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); MemoryBlock M3 = Memory::allocateMappedMemory(32, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); - EXPECT_NE((void*)0, M1.base()); + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(16U, M1.size()); - EXPECT_NE((void*)0, M2.base()); + EXPECT_NE((void*)nullptr, M2.base()); EXPECT_LE(64U, M2.size()); - EXPECT_NE((void*)0, M3.base()); + EXPECT_NE((void*)nullptr, M3.base()); EXPECT_LE(32U, M3.size()); EXPECT_FALSE(doesOverlap(M1, M2)); @@ -302,20 +310,20 @@ TEST_P(MappedMemoryTest, ZeroNear) { } TEST_P(MappedMemoryTest, ZeroSizeNear) { - error_code EC; + std::error_code EC; MemoryBlock Near((void*)(4*PageSize), 0); MemoryBlock M1 = Memory::allocateMappedMemory(16, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); MemoryBlock M2 = Memory::allocateMappedMemory(64, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); MemoryBlock M3 = Memory::allocateMappedMemory(32, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); - EXPECT_NE((void*)0, M1.base()); + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(16U, M1.size()); - EXPECT_NE((void*)0, M2.base()); + EXPECT_NE((void*)nullptr, M2.base()); EXPECT_LE(64U, M2.size()); - EXPECT_NE((void*)0, M3.base()); + EXPECT_NE((void*)nullptr, M3.base()); EXPECT_LE(32U, M3.size()); EXPECT_FALSE(doesOverlap(M1, M2)); @@ -328,12 +336,12 @@ TEST_P(MappedMemoryTest, ZeroSizeNear) { } TEST_P(MappedMemoryTest, UnalignedNear) { - error_code EC; + std::error_code EC; MemoryBlock Near((void*)(2*PageSize+5), 0); MemoryBlock M1 = Memory::allocateMappedMemory(15, &Near, Flags, EC); - EXPECT_EQ(error_code::success(), EC); + EXPECT_EQ(std::error_code(), EC); - EXPECT_NE((void*)0, M1.base()); + EXPECT_NE((void*)nullptr, M1.base()); EXPECT_LE(sizeof(int), M1.size()); EXPECT_FALSE(Memory::releaseMappedMemory(M1)); diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index b79d055..cf2e1ee 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -8,24 +8,30 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Path.h" +#include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" +#ifdef LLVM_ON_WIN32 +#include <winerror.h> +#endif + using namespace llvm; using namespace llvm::sys; -#define ASSERT_NO_ERROR(x) \ - if (error_code ASSERT_NO_ERROR_ec = x) { \ - SmallString<128> MessageStorage; \ - raw_svector_ostream Message(MessageStorage); \ - Message << #x ": did not return errc::success.\n" \ - << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ - << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ - GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ - } else {} +#define ASSERT_NO_ERROR(x) \ + if (std::error_code ASSERT_NO_ERROR_ec = x) { \ + SmallString<128> MessageStorage; \ + raw_svector_ostream Message(MessageStorage); \ + Message << #x ": did not return errc::success.\n" \ + << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ + << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ + GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ + } else { \ + } namespace { @@ -352,7 +358,7 @@ TEST_F(FileSystemTest, TempFiles) { ASSERT_EQ(fs::remove(Twine(TempPath2), false), errc::no_such_file_or_directory); - error_code EC = fs::status(TempPath2.c_str(), B); + std::error_code EC = fs::status(TempPath2.c_str(), B); EXPECT_EQ(EC, errc::no_such_file_or_directory); EXPECT_EQ(B.type(), fs::file_type::file_not_found); @@ -393,7 +399,7 @@ TEST_F(FileSystemTest, TempFiles) { "abcdefghijklmnopqrstuvwxyz3abcdefghijklmnopqrstuvwxyz2" "abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz0"; EXPECT_EQ(fs::createUniqueFile(Twine(Path270), FileDescriptor, TempPath), - windows_error::path_not_found); + errc::no_such_file_or_directory); #endif } @@ -406,7 +412,7 @@ TEST_F(FileSystemTest, CreateDir) { } TEST_F(FileSystemTest, DirectoryIteration) { - error_code ec; + std::error_code ec; for (fs::directory_iterator i(".", ec), e; i != e; i.increment(ec)) ASSERT_NO_ERROR(ec); @@ -535,9 +541,6 @@ TEST_F(FileSystemTest, Magic) { StringRef magic(i->magic_str, i->magic_str_len); file << magic; file.close(); - bool res = false; - ASSERT_NO_ERROR(fs::has_magic(file_pathname.c_str(), magic, res)); - EXPECT_TRUE(res); EXPECT_EQ(i->magic, fs::identify_magic(magic)); ASSERT_NO_ERROR(fs::remove(Twine(file_pathname))); } @@ -555,9 +558,9 @@ TEST_F(FileSystemTest, CarriageReturn) { File << '\n'; } { - std::unique_ptr<MemoryBuffer> Buf; - MemoryBuffer::getFile(FilePathname.c_str(), Buf); - EXPECT_EQ(Buf->getBuffer(), "\r\n"); + auto Buf = MemoryBuffer::getFile(FilePathname.c_str()); + EXPECT_TRUE((bool)Buf); + EXPECT_EQ(Buf.get()->getBuffer(), "\r\n"); } { @@ -566,9 +569,9 @@ TEST_F(FileSystemTest, CarriageReturn) { File << '\n'; } { - std::unique_ptr<MemoryBuffer> Buf; - MemoryBuffer::getFile(FilePathname.c_str(), Buf); - EXPECT_EQ(Buf->getBuffer(), "\n"); + auto Buf = MemoryBuffer::getFile(FilePathname.c_str()); + EXPECT_TRUE((bool)Buf); + EXPECT_EQ(Buf.get()->getBuffer(), "\n"); } ASSERT_NO_ERROR(fs::remove(Twine(FilePathname))); } @@ -581,7 +584,7 @@ TEST_F(FileSystemTest, FileMapping) { ASSERT_NO_ERROR( fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); // Map in temp file and add some content - error_code EC; + std::error_code EC; StringRef Val("hello there"); { fs::mapped_file_region mfr(FileDescriptor, diff --git a/unittests/Support/ProgramTest.cpp b/unittests/Support/ProgramTest.cpp index 800df14..4e7316f 100644 --- a/unittests/Support/ProgramTest.cpp +++ b/unittests/Support/ProgramTest.cpp @@ -54,7 +54,7 @@ static void CopyEnvironment(std::vector<const char *> &out) { // environ seems to work for Windows and most other Unices. char **envp = environ; #endif - while (*envp != 0) { + while (*envp != nullptr) { out.push_back(*envp); ++envp; } @@ -76,14 +76,14 @@ TEST(ProgramTest, CreateProcessTrailingSlash) { "--gtest_filter=ProgramTest.CreateProcessTrailingSlash", "-program-test-string-arg1", "has\\\\ trailing\\", "-program-test-string-arg2", "has\\\\ trailing\\", - 0 + nullptr }; // Add LLVM_PROGRAM_TEST_CHILD to the environment of the child. std::vector<const char *> envp; CopyEnvironment(envp); envp.push_back("LLVM_PROGRAM_TEST_CHILD=1"); - envp.push_back(0); + envp.push_back(nullptr); std::string error; bool ExecutionFailed; @@ -93,7 +93,7 @@ TEST(ProgramTest, CreateProcessTrailingSlash) { #else StringRef nul("/dev/null"); #endif - const StringRef *redirects[] = { &nul, &nul, 0 }; + const StringRef *redirects[] = { &nul, &nul, nullptr }; int rc = ExecuteAndWait(my_exe, argv, &envp[0], redirects, /*secondsToWait=*/ 10, /*memoryLimit=*/ 0, &error, &ExecutionFailed); @@ -114,19 +114,19 @@ TEST(ProgramTest, TestExecuteNoWait) { const char *argv[] = { Executable.c_str(), "--gtest_filter=ProgramTest.TestExecuteNoWait", - 0 + nullptr }; // Add LLVM_PROGRAM_TEST_EXECUTE_NO_WAIT to the environment of the child. std::vector<const char *> envp; CopyEnvironment(envp); envp.push_back("LLVM_PROGRAM_TEST_EXECUTE_NO_WAIT=1"); - envp.push_back(0); + envp.push_back(nullptr); std::string Error; bool ExecutionFailed; - ProcessInfo PI1 = - ExecuteNoWait(Executable, argv, &envp[0], 0, 0, &Error, &ExecutionFailed); + ProcessInfo PI1 = ExecuteNoWait(Executable, argv, &envp[0], nullptr, 0, + &Error, &ExecutionFailed); ASSERT_FALSE(ExecutionFailed) << Error; ASSERT_NE(PI1.Pid, 0) << "Invalid process id"; @@ -144,8 +144,8 @@ TEST(ProgramTest, TestExecuteNoWait) { EXPECT_EQ(LoopCount, 1u) << "LoopCount should be 1"; - ProcessInfo PI2 = - ExecuteNoWait(Executable, argv, &envp[0], 0, 0, &Error, &ExecutionFailed); + ProcessInfo PI2 = ExecuteNoWait(Executable, argv, &envp[0], nullptr, 0, + &Error, &ExecutionFailed); ASSERT_FALSE(ExecutionFailed) << Error; ASSERT_NE(PI2.Pid, 0) << "Invalid process id"; @@ -162,15 +162,45 @@ TEST(ProgramTest, TestExecuteNoWait) { ASSERT_GT(LoopCount, 1u) << "LoopCount should be >1"; } +TEST(ProgramTest, TestExecuteAndWaitTimeout) { + using namespace llvm::sys; + + if (getenv("LLVM_PROGRAM_TEST_TIMEOUT")) { + sleep_for(/*seconds*/ 10); + exit(0); + } + + std::string Executable = + sys::fs::getMainExecutable(TestMainArgv0, &ProgramTestStringArg1); + const char *argv[] = { + Executable.c_str(), + "--gtest_filter=ProgramTest.TestExecuteAndWaitTimeout", + nullptr + }; + + // Add LLVM_PROGRAM_TEST_TIMEOUT to the environment of the child. + std::vector<const char *> envp; + CopyEnvironment(envp); + envp.push_back("LLVM_PROGRAM_TEST_TIMEOUT=1"); + envp.push_back(nullptr); + + std::string Error; + bool ExecutionFailed; + int RetCode = + ExecuteAndWait(Executable, argv, &envp[0], nullptr, /*secondsToWait=*/1, 0, + &Error, &ExecutionFailed); + ASSERT_EQ(-2, RetCode); +} + TEST(ProgramTest, TestExecuteNegative) { std::string Executable = "i_dont_exist"; - const char *argv[] = { Executable.c_str(), 0 }; + const char *argv[] = { Executable.c_str(), nullptr }; { std::string Error; bool ExecutionFailed; - int RetCode = - ExecuteAndWait(Executable, argv, 0, 0, 0, 0, &Error, &ExecutionFailed); + int RetCode = ExecuteAndWait(Executable, argv, nullptr, nullptr, 0, 0, + &Error, &ExecutionFailed); ASSERT_TRUE(RetCode < 0) << "On error ExecuteAndWait should return 0 or " "positive value indicating the result code"; ASSERT_TRUE(ExecutionFailed); @@ -180,8 +210,8 @@ TEST(ProgramTest, TestExecuteNegative) { { std::string Error; bool ExecutionFailed; - ProcessInfo PI = - ExecuteNoWait(Executable, argv, 0, 0, 0, &Error, &ExecutionFailed); + ProcessInfo PI = ExecuteNoWait(Executable, argv, nullptr, nullptr, 0, + &Error, &ExecutionFailed); ASSERT_EQ(PI.Pid, 0) << "On error ExecuteNoWait should return an invalid ProcessInfo"; ASSERT_TRUE(ExecutionFailed); diff --git a/unittests/Support/ScaledNumberTest.cpp b/unittests/Support/ScaledNumberTest.cpp new file mode 100644 index 0000000..7bbef7e --- /dev/null +++ b/unittests/Support/ScaledNumberTest.cpp @@ -0,0 +1,536 @@ +//===- llvm/unittest/Support/ScaledNumberTest.cpp - ScaledPair tests -----==// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/ScaledNumber.h" + +#include "llvm/Support/DataTypes.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace llvm::ScaledNumbers; + +namespace { + +template <class UIntT> struct ScaledPair { + UIntT D; + int S; + ScaledPair(const std::pair<UIntT, int16_t> &F) : D(F.first), S(F.second) {} + ScaledPair(UIntT D, int S) : D(D), S(S) {} + + bool operator==(const ScaledPair<UIntT> &X) const { + return D == X.D && S == X.S; + } +}; +template <class UIntT> +bool operator==(const std::pair<UIntT, int16_t> &L, + const ScaledPair<UIntT> &R) { + return ScaledPair<UIntT>(L) == R; +} +template <class UIntT> +void PrintTo(const ScaledPair<UIntT> &F, ::std::ostream *os) { + *os << F.D << "*2^" << F.S; +} + +typedef ScaledPair<uint32_t> SP32; +typedef ScaledPair<uint64_t> SP64; + +TEST(ScaledNumberHelpersTest, getRounded) { + EXPECT_EQ(getRounded32(0, 0, false), SP32(0, 0)); + EXPECT_EQ(getRounded32(0, 0, true), SP32(1, 0)); + EXPECT_EQ(getRounded32(20, 21, true), SP32(21, 21)); + EXPECT_EQ(getRounded32(UINT32_MAX, 0, false), SP32(UINT32_MAX, 0)); + EXPECT_EQ(getRounded32(UINT32_MAX, 0, true), SP32(1 << 31, 1)); + + EXPECT_EQ(getRounded64(0, 0, false), SP64(0, 0)); + EXPECT_EQ(getRounded64(0, 0, true), SP64(1, 0)); + EXPECT_EQ(getRounded64(20, 21, true), SP64(21, 21)); + EXPECT_EQ(getRounded64(UINT32_MAX, 0, false), SP64(UINT32_MAX, 0)); + EXPECT_EQ(getRounded64(UINT32_MAX, 0, true), SP64(UINT64_C(1) << 32, 0)); + EXPECT_EQ(getRounded64(UINT64_MAX, 0, false), SP64(UINT64_MAX, 0)); + EXPECT_EQ(getRounded64(UINT64_MAX, 0, true), SP64(UINT64_C(1) << 63, 1)); +} + +TEST(ScaledNumberHelpersTest, getAdjusted) { + const uint64_t Max32In64 = UINT32_MAX; + EXPECT_EQ(getAdjusted32(0), SP32(0, 0)); + EXPECT_EQ(getAdjusted32(0, 5), SP32(0, 5)); + EXPECT_EQ(getAdjusted32(UINT32_MAX), SP32(UINT32_MAX, 0)); + EXPECT_EQ(getAdjusted32(Max32In64 << 1), SP32(UINT32_MAX, 1)); + EXPECT_EQ(getAdjusted32(Max32In64 << 1, 1), SP32(UINT32_MAX, 2)); + EXPECT_EQ(getAdjusted32(Max32In64 << 31), SP32(UINT32_MAX, 31)); + EXPECT_EQ(getAdjusted32(Max32In64 << 32), SP32(UINT32_MAX, 32)); + EXPECT_EQ(getAdjusted32(Max32In64 + 1), SP32(1u << 31, 1)); + EXPECT_EQ(getAdjusted32(UINT64_MAX), SP32(1u << 31, 33)); + + EXPECT_EQ(getAdjusted64(0), SP64(0, 0)); + EXPECT_EQ(getAdjusted64(0, 5), SP64(0, 5)); + EXPECT_EQ(getAdjusted64(UINT32_MAX), SP64(UINT32_MAX, 0)); + EXPECT_EQ(getAdjusted64(Max32In64 << 1), SP64(Max32In64 << 1, 0)); + EXPECT_EQ(getAdjusted64(Max32In64 << 1, 1), SP64(Max32In64 << 1, 1)); + EXPECT_EQ(getAdjusted64(Max32In64 << 31), SP64(Max32In64 << 31, 0)); + EXPECT_EQ(getAdjusted64(Max32In64 << 32), SP64(Max32In64 << 32, 0)); + EXPECT_EQ(getAdjusted64(Max32In64 + 1), SP64(Max32In64 + 1, 0)); + EXPECT_EQ(getAdjusted64(UINT64_MAX), SP64(UINT64_MAX, 0)); +} + +TEST(ScaledNumberHelpersTest, getProduct) { + // Zero. + EXPECT_EQ(SP32(0, 0), getProduct32(0, 0)); + EXPECT_EQ(SP32(0, 0), getProduct32(0, 1)); + EXPECT_EQ(SP32(0, 0), getProduct32(0, 33)); + + // Basic. + EXPECT_EQ(SP32(6, 0), getProduct32(2, 3)); + EXPECT_EQ(SP32(UINT16_MAX / 3 * UINT16_MAX / 5 * 2, 0), + getProduct32(UINT16_MAX / 3, UINT16_MAX / 5 * 2)); + + // Overflow, no loss of precision. + // ==> 0xf00010 * 0x1001 + // ==> 0xf00f00000 + 0x10010 + // ==> 0xf00f10010 + // ==> 0xf00f1001 * 2^4 + EXPECT_EQ(SP32(0xf00f1001, 4), getProduct32(0xf00010, 0x1001)); + + // Overflow, loss of precision, rounds down. + // ==> 0xf000070 * 0x1001 + // ==> 0xf00f000000 + 0x70070 + // ==> 0xf00f070070 + // ==> 0xf00f0700 * 2^8 + EXPECT_EQ(SP32(0xf00f0700, 8), getProduct32(0xf000070, 0x1001)); + + // Overflow, loss of precision, rounds up. + // ==> 0xf000080 * 0x1001 + // ==> 0xf00f000000 + 0x80080 + // ==> 0xf00f080080 + // ==> 0xf00f0801 * 2^8 + EXPECT_EQ(SP32(0xf00f0801, 8), getProduct32(0xf000080, 0x1001)); + + // Reverse operand order. + EXPECT_EQ(SP32(0, 0), getProduct32(1, 0)); + EXPECT_EQ(SP32(0, 0), getProduct32(33, 0)); + EXPECT_EQ(SP32(6, 0), getProduct32(3, 2)); + EXPECT_EQ(SP32(UINT16_MAX / 3 * UINT16_MAX / 5 * 2, 0), + getProduct32(UINT16_MAX / 5 * 2, UINT16_MAX / 3)); + EXPECT_EQ(SP32(0xf00f1001, 4), getProduct32(0x1001, 0xf00010)); + EXPECT_EQ(SP32(0xf00f0700, 8), getProduct32(0x1001, 0xf000070)); + EXPECT_EQ(SP32(0xf00f0801, 8), getProduct32(0x1001, 0xf000080)); + + // Round to overflow. + EXPECT_EQ(SP64(UINT64_C(1) << 63, 64), + getProduct64(UINT64_C(10376293541461622786), + UINT64_C(16397105843297379211))); + + // Big number with rounding. + EXPECT_EQ(SP64(UINT64_C(9223372036854775810), 64), + getProduct64(UINT64_C(18446744073709551556), + UINT64_C(9223372036854775840))); +} + +TEST(ScaledNumberHelpersTest, getQuotient) { + // Zero. + EXPECT_EQ(SP32(0, 0), getQuotient32(0, 0)); + EXPECT_EQ(SP32(0, 0), getQuotient32(0, 1)); + EXPECT_EQ(SP32(0, 0), getQuotient32(0, 73)); + EXPECT_EQ(SP32(UINT32_MAX, MaxScale), getQuotient32(1, 0)); + EXPECT_EQ(SP32(UINT32_MAX, MaxScale), getQuotient32(6, 0)); + + // Powers of two. + EXPECT_EQ(SP32(1u << 31, -31), getQuotient32(1, 1)); + EXPECT_EQ(SP32(1u << 31, -30), getQuotient32(2, 1)); + EXPECT_EQ(SP32(1u << 31, -33), getQuotient32(4, 16)); + EXPECT_EQ(SP32(7u << 29, -29), getQuotient32(7, 1)); + EXPECT_EQ(SP32(7u << 29, -30), getQuotient32(7, 2)); + EXPECT_EQ(SP32(7u << 29, -33), getQuotient32(7, 16)); + + // Divide evenly. + EXPECT_EQ(SP32(3u << 30, -30), getQuotient32(9, 3)); + EXPECT_EQ(SP32(9u << 28, -28), getQuotient32(63, 7)); + + // Divide unevenly. + EXPECT_EQ(SP32(0xaaaaaaab, -33), getQuotient32(1, 3)); + EXPECT_EQ(SP32(0xd5555555, -31), getQuotient32(5, 3)); + + // 64-bit division is hard to test, since divide64 doesn't canonicalized its + // output. However, this is the algorithm the implementation uses: + // + // - Shift divisor right. + // - If we have 1 (power of 2), return early -- not canonicalized. + // - Shift dividend left. + // - 64-bit integer divide. + // - If there's a remainder, continue with long division. + // + // TODO: require less knowledge about the implementation in the test. + + // Zero. + EXPECT_EQ(SP64(0, 0), getQuotient64(0, 0)); + EXPECT_EQ(SP64(0, 0), getQuotient64(0, 1)); + EXPECT_EQ(SP64(0, 0), getQuotient64(0, 73)); + EXPECT_EQ(SP64(UINT64_MAX, MaxScale), getQuotient64(1, 0)); + EXPECT_EQ(SP64(UINT64_MAX, MaxScale), getQuotient64(6, 0)); + + // Powers of two. + EXPECT_EQ(SP64(1, 0), getQuotient64(1, 1)); + EXPECT_EQ(SP64(2, 0), getQuotient64(2, 1)); + EXPECT_EQ(SP64(4, -4), getQuotient64(4, 16)); + EXPECT_EQ(SP64(7, 0), getQuotient64(7, 1)); + EXPECT_EQ(SP64(7, -1), getQuotient64(7, 2)); + EXPECT_EQ(SP64(7, -4), getQuotient64(7, 16)); + + // Divide evenly. + EXPECT_EQ(SP64(UINT64_C(3) << 60, -60), getQuotient64(9, 3)); + EXPECT_EQ(SP64(UINT64_C(9) << 58, -58), getQuotient64(63, 7)); + + // Divide unevenly. + EXPECT_EQ(SP64(0xaaaaaaaaaaaaaaab, -65), getQuotient64(1, 3)); + EXPECT_EQ(SP64(0xd555555555555555, -63), getQuotient64(5, 3)); +} + +TEST(ScaledNumberHelpersTest, getLg) { + EXPECT_EQ(0, getLg(UINT32_C(1), 0)); + EXPECT_EQ(1, getLg(UINT32_C(1), 1)); + EXPECT_EQ(1, getLg(UINT32_C(2), 0)); + EXPECT_EQ(3, getLg(UINT32_C(1), 3)); + EXPECT_EQ(3, getLg(UINT32_C(7), 0)); + EXPECT_EQ(3, getLg(UINT32_C(8), 0)); + EXPECT_EQ(3, getLg(UINT32_C(9), 0)); + EXPECT_EQ(3, getLg(UINT32_C(64), -3)); + EXPECT_EQ(31, getLg((UINT32_MAX >> 1) + 2, 0)); + EXPECT_EQ(32, getLg(UINT32_MAX, 0)); + EXPECT_EQ(-1, getLg(UINT32_C(1), -1)); + EXPECT_EQ(-1, getLg(UINT32_C(2), -2)); + EXPECT_EQ(INT32_MIN, getLg(UINT32_C(0), -1)); + EXPECT_EQ(INT32_MIN, getLg(UINT32_C(0), 0)); + EXPECT_EQ(INT32_MIN, getLg(UINT32_C(0), 1)); + + EXPECT_EQ(0, getLg(UINT64_C(1), 0)); + EXPECT_EQ(1, getLg(UINT64_C(1), 1)); + EXPECT_EQ(1, getLg(UINT64_C(2), 0)); + EXPECT_EQ(3, getLg(UINT64_C(1), 3)); + EXPECT_EQ(3, getLg(UINT64_C(7), 0)); + EXPECT_EQ(3, getLg(UINT64_C(8), 0)); + EXPECT_EQ(3, getLg(UINT64_C(9), 0)); + EXPECT_EQ(3, getLg(UINT64_C(64), -3)); + EXPECT_EQ(63, getLg((UINT64_MAX >> 1) + 2, 0)); + EXPECT_EQ(64, getLg(UINT64_MAX, 0)); + EXPECT_EQ(-1, getLg(UINT64_C(1), -1)); + EXPECT_EQ(-1, getLg(UINT64_C(2), -2)); + EXPECT_EQ(INT32_MIN, getLg(UINT64_C(0), -1)); + EXPECT_EQ(INT32_MIN, getLg(UINT64_C(0), 0)); + EXPECT_EQ(INT32_MIN, getLg(UINT64_C(0), 1)); +} + +TEST(ScaledNumberHelpersTest, getLgFloor) { + EXPECT_EQ(0, getLgFloor(UINT32_C(1), 0)); + EXPECT_EQ(1, getLgFloor(UINT32_C(1), 1)); + EXPECT_EQ(1, getLgFloor(UINT32_C(2), 0)); + EXPECT_EQ(2, getLgFloor(UINT32_C(7), 0)); + EXPECT_EQ(3, getLgFloor(UINT32_C(1), 3)); + EXPECT_EQ(3, getLgFloor(UINT32_C(8), 0)); + EXPECT_EQ(3, getLgFloor(UINT32_C(9), 0)); + EXPECT_EQ(3, getLgFloor(UINT32_C(64), -3)); + EXPECT_EQ(31, getLgFloor((UINT32_MAX >> 1) + 2, 0)); + EXPECT_EQ(31, getLgFloor(UINT32_MAX, 0)); + EXPECT_EQ(INT32_MIN, getLgFloor(UINT32_C(0), -1)); + EXPECT_EQ(INT32_MIN, getLgFloor(UINT32_C(0), 0)); + EXPECT_EQ(INT32_MIN, getLgFloor(UINT32_C(0), 1)); + + EXPECT_EQ(0, getLgFloor(UINT64_C(1), 0)); + EXPECT_EQ(1, getLgFloor(UINT64_C(1), 1)); + EXPECT_EQ(1, getLgFloor(UINT64_C(2), 0)); + EXPECT_EQ(2, getLgFloor(UINT64_C(7), 0)); + EXPECT_EQ(3, getLgFloor(UINT64_C(1), 3)); + EXPECT_EQ(3, getLgFloor(UINT64_C(8), 0)); + EXPECT_EQ(3, getLgFloor(UINT64_C(9), 0)); + EXPECT_EQ(3, getLgFloor(UINT64_C(64), -3)); + EXPECT_EQ(63, getLgFloor((UINT64_MAX >> 1) + 2, 0)); + EXPECT_EQ(63, getLgFloor(UINT64_MAX, 0)); + EXPECT_EQ(INT32_MIN, getLgFloor(UINT64_C(0), -1)); + EXPECT_EQ(INT32_MIN, getLgFloor(UINT64_C(0), 0)); + EXPECT_EQ(INT32_MIN, getLgFloor(UINT64_C(0), 1)); +} + +TEST(ScaledNumberHelpersTest, getLgCeiling) { + EXPECT_EQ(0, getLgCeiling(UINT32_C(1), 0)); + EXPECT_EQ(1, getLgCeiling(UINT32_C(1), 1)); + EXPECT_EQ(1, getLgCeiling(UINT32_C(2), 0)); + EXPECT_EQ(3, getLgCeiling(UINT32_C(1), 3)); + EXPECT_EQ(3, getLgCeiling(UINT32_C(7), 0)); + EXPECT_EQ(3, getLgCeiling(UINT32_C(8), 0)); + EXPECT_EQ(3, getLgCeiling(UINT32_C(64), -3)); + EXPECT_EQ(4, getLgCeiling(UINT32_C(9), 0)); + EXPECT_EQ(32, getLgCeiling(UINT32_MAX, 0)); + EXPECT_EQ(32, getLgCeiling((UINT32_MAX >> 1) + 2, 0)); + EXPECT_EQ(INT32_MIN, getLgCeiling(UINT32_C(0), -1)); + EXPECT_EQ(INT32_MIN, getLgCeiling(UINT32_C(0), 0)); + EXPECT_EQ(INT32_MIN, getLgCeiling(UINT32_C(0), 1)); + + EXPECT_EQ(0, getLgCeiling(UINT64_C(1), 0)); + EXPECT_EQ(1, getLgCeiling(UINT64_C(1), 1)); + EXPECT_EQ(1, getLgCeiling(UINT64_C(2), 0)); + EXPECT_EQ(3, getLgCeiling(UINT64_C(1), 3)); + EXPECT_EQ(3, getLgCeiling(UINT64_C(7), 0)); + EXPECT_EQ(3, getLgCeiling(UINT64_C(8), 0)); + EXPECT_EQ(3, getLgCeiling(UINT64_C(64), -3)); + EXPECT_EQ(4, getLgCeiling(UINT64_C(9), 0)); + EXPECT_EQ(64, getLgCeiling((UINT64_MAX >> 1) + 2, 0)); + EXPECT_EQ(64, getLgCeiling(UINT64_MAX, 0)); + EXPECT_EQ(INT32_MIN, getLgCeiling(UINT64_C(0), -1)); + EXPECT_EQ(INT32_MIN, getLgCeiling(UINT64_C(0), 0)); + EXPECT_EQ(INT32_MIN, getLgCeiling(UINT64_C(0), 1)); +} + +TEST(ScaledNumberHelpersTest, compare) { + EXPECT_EQ(0, compare(UINT32_C(0), 0, UINT32_C(0), 1)); + EXPECT_EQ(0, compare(UINT32_C(0), 0, UINT32_C(0), -10)); + EXPECT_EQ(0, compare(UINT32_C(0), 0, UINT32_C(0), 20)); + EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(64), -3)); + EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(32), -2)); + EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(16), -1)); + EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(8), 0)); + EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(4), 1)); + EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(2), 2)); + EXPECT_EQ(0, compare(UINT32_C(8), 0, UINT32_C(1), 3)); + EXPECT_EQ(-1, compare(UINT32_C(0), 0, UINT32_C(1), 3)); + EXPECT_EQ(-1, compare(UINT32_C(7), 0, UINT32_C(1), 3)); + EXPECT_EQ(-1, compare(UINT32_C(7), 0, UINT32_C(64), -3)); + EXPECT_EQ(1, compare(UINT32_C(9), 0, UINT32_C(1), 3)); + EXPECT_EQ(1, compare(UINT32_C(9), 0, UINT32_C(64), -3)); + EXPECT_EQ(1, compare(UINT32_C(9), 0, UINT32_C(0), 0)); + + EXPECT_EQ(0, compare(UINT64_C(0), 0, UINT64_C(0), 1)); + EXPECT_EQ(0, compare(UINT64_C(0), 0, UINT64_C(0), -10)); + EXPECT_EQ(0, compare(UINT64_C(0), 0, UINT64_C(0), 20)); + EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(64), -3)); + EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(32), -2)); + EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(16), -1)); + EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(8), 0)); + EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(4), 1)); + EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(2), 2)); + EXPECT_EQ(0, compare(UINT64_C(8), 0, UINT64_C(1), 3)); + EXPECT_EQ(-1, compare(UINT64_C(0), 0, UINT64_C(1), 3)); + EXPECT_EQ(-1, compare(UINT64_C(7), 0, UINT64_C(1), 3)); + EXPECT_EQ(-1, compare(UINT64_C(7), 0, UINT64_C(64), -3)); + EXPECT_EQ(1, compare(UINT64_C(9), 0, UINT64_C(1), 3)); + EXPECT_EQ(1, compare(UINT64_C(9), 0, UINT64_C(64), -3)); + EXPECT_EQ(1, compare(UINT64_C(9), 0, UINT64_C(0), 0)); + EXPECT_EQ(-1, compare(UINT64_MAX, 0, UINT64_C(1), 64)); +} + +TEST(ScaledNumberHelpersTest, matchScales) { +#define MATCH_SCALES(T, LDIn, LSIn, RDIn, RSIn, LDOut, RDOut, SOut) \ + do { \ + T LDx = LDIn; \ + T RDx = RDIn; \ + T LDy = LDOut; \ + T RDy = RDOut; \ + int16_t LSx = LSIn; \ + int16_t RSx = RSIn; \ + int16_t Sy = SOut; \ + \ + EXPECT_EQ(SOut, matchScales(LDx, LSx, RDx, RSx)); \ + EXPECT_EQ(LDy, LDx); \ + EXPECT_EQ(RDy, RDx); \ + if (LDy) \ + EXPECT_EQ(Sy, LSx); \ + if (RDy) \ + EXPECT_EQ(Sy, RSx); \ + } while (false) + + MATCH_SCALES(uint32_t, 0, 0, 0, 0, 0, 0, 0); + MATCH_SCALES(uint32_t, 0, 50, 7, 1, 0, 7, 1); + MATCH_SCALES(uint32_t, UINT32_C(1) << 31, 1, 9, 0, UINT32_C(1) << 31, 4, 1); + MATCH_SCALES(uint32_t, UINT32_C(1) << 31, 2, 9, 0, UINT32_C(1) << 31, 2, 2); + MATCH_SCALES(uint32_t, UINT32_C(1) << 31, 3, 9, 0, UINT32_C(1) << 31, 1, 3); + MATCH_SCALES(uint32_t, UINT32_C(1) << 31, 4, 9, 0, UINT32_C(1) << 31, 0, 4); + MATCH_SCALES(uint32_t, UINT32_C(1) << 30, 4, 9, 0, UINT32_C(1) << 31, 1, 3); + MATCH_SCALES(uint32_t, UINT32_C(1) << 29, 4, 9, 0, UINT32_C(1) << 31, 2, 2); + MATCH_SCALES(uint32_t, UINT32_C(1) << 28, 4, 9, 0, UINT32_C(1) << 31, 4, 1); + MATCH_SCALES(uint32_t, UINT32_C(1) << 27, 4, 9, 0, UINT32_C(1) << 31, 9, 0); + MATCH_SCALES(uint32_t, 7, 1, 0, 50, 7, 0, 1); + MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 31, 1, 4, UINT32_C(1) << 31, 1); + MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 31, 2, 2, UINT32_C(1) << 31, 2); + MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 31, 3, 1, UINT32_C(1) << 31, 3); + MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 31, 4, 0, UINT32_C(1) << 31, 4); + MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 30, 4, 1, UINT32_C(1) << 31, 3); + MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 29, 4, 2, UINT32_C(1) << 31, 2); + MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 28, 4, 4, UINT32_C(1) << 31, 1); + MATCH_SCALES(uint32_t, 9, 0, UINT32_C(1) << 27, 4, 9, UINT32_C(1) << 31, 0); + + MATCH_SCALES(uint64_t, 0, 0, 0, 0, 0, 0, 0); + MATCH_SCALES(uint64_t, 0, 100, 7, 1, 0, 7, 1); + MATCH_SCALES(uint64_t, UINT64_C(1) << 63, 1, 9, 0, UINT64_C(1) << 63, 4, 1); + MATCH_SCALES(uint64_t, UINT64_C(1) << 63, 2, 9, 0, UINT64_C(1) << 63, 2, 2); + MATCH_SCALES(uint64_t, UINT64_C(1) << 63, 3, 9, 0, UINT64_C(1) << 63, 1, 3); + MATCH_SCALES(uint64_t, UINT64_C(1) << 63, 4, 9, 0, UINT64_C(1) << 63, 0, 4); + MATCH_SCALES(uint64_t, UINT64_C(1) << 62, 4, 9, 0, UINT64_C(1) << 63, 1, 3); + MATCH_SCALES(uint64_t, UINT64_C(1) << 61, 4, 9, 0, UINT64_C(1) << 63, 2, 2); + MATCH_SCALES(uint64_t, UINT64_C(1) << 60, 4, 9, 0, UINT64_C(1) << 63, 4, 1); + MATCH_SCALES(uint64_t, UINT64_C(1) << 59, 4, 9, 0, UINT64_C(1) << 63, 9, 0); + MATCH_SCALES(uint64_t, 7, 1, 0, 100, 7, 0, 1); + MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 63, 1, 4, UINT64_C(1) << 63, 1); + MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 63, 2, 2, UINT64_C(1) << 63, 2); + MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 63, 3, 1, UINT64_C(1) << 63, 3); + MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 63, 4, 0, UINT64_C(1) << 63, 4); + MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 62, 4, 1, UINT64_C(1) << 63, 3); + MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 61, 4, 2, UINT64_C(1) << 63, 2); + MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 60, 4, 4, UINT64_C(1) << 63, 1); + MATCH_SCALES(uint64_t, 9, 0, UINT64_C(1) << 59, 4, 9, UINT64_C(1) << 63, 0); +} + +TEST(ScaledNumberHelpersTest, getSum) { + // Zero. + EXPECT_EQ(SP32(1, 0), getSum32(0, 0, 1, 0)); + EXPECT_EQ(SP32(8, -3), getSum32(0, 0, 8, -3)); + EXPECT_EQ(SP32(UINT32_MAX, 0), getSum32(0, 0, UINT32_MAX, 0)); + + // Basic. + EXPECT_EQ(SP32(2, 0), getSum32(1, 0, 1, 0)); + EXPECT_EQ(SP32(3, 0), getSum32(1, 0, 2, 0)); + EXPECT_EQ(SP32(67, 0), getSum32(7, 0, 60, 0)); + + // Different scales. + EXPECT_EQ(SP32(3, 0), getSum32(1, 0, 1, 1)); + EXPECT_EQ(SP32(4, 0), getSum32(2, 0, 1, 1)); + + // Loss of precision. + EXPECT_EQ(SP32(UINT32_C(1) << 31, 1), getSum32(1, 32, 1, 0)); + EXPECT_EQ(SP32(UINT32_C(1) << 31, -31), getSum32(1, -32, 1, 0)); + + // Not quite loss of precision. + EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, 1), getSum32(1, 32, 1, 1)); + EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, -32), getSum32(1, -32, 1, -1)); + + // Overflow. + EXPECT_EQ(SP32(UINT32_C(1) << 31, 1), getSum32(1, 0, UINT32_MAX, 0)); + + // Reverse operand order. + EXPECT_EQ(SP32(1, 0), getSum32(1, 0, 0, 0)); + EXPECT_EQ(SP32(8, -3), getSum32(8, -3, 0, 0)); + EXPECT_EQ(SP32(UINT32_MAX, 0), getSum32(UINT32_MAX, 0, 0, 0)); + EXPECT_EQ(SP32(3, 0), getSum32(2, 0, 1, 0)); + EXPECT_EQ(SP32(67, 0), getSum32(60, 0, 7, 0)); + EXPECT_EQ(SP32(3, 0), getSum32(1, 1, 1, 0)); + EXPECT_EQ(SP32(4, 0), getSum32(1, 1, 2, 0)); + EXPECT_EQ(SP32(UINT32_C(1) << 31, 1), getSum32(1, 0, 1, 32)); + EXPECT_EQ(SP32(UINT32_C(1) << 31, -31), getSum32(1, 0, 1, -32)); + EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, 1), getSum32(1, 1, 1, 32)); + EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, -32), getSum32(1, -1, 1, -32)); + EXPECT_EQ(SP32(UINT32_C(1) << 31, 1), getSum32(UINT32_MAX, 0, 1, 0)); + + // Zero. + EXPECT_EQ(SP64(1, 0), getSum64(0, 0, 1, 0)); + EXPECT_EQ(SP64(8, -3), getSum64(0, 0, 8, -3)); + EXPECT_EQ(SP64(UINT64_MAX, 0), getSum64(0, 0, UINT64_MAX, 0)); + + // Basic. + EXPECT_EQ(SP64(2, 0), getSum64(1, 0, 1, 0)); + EXPECT_EQ(SP64(3, 0), getSum64(1, 0, 2, 0)); + EXPECT_EQ(SP64(67, 0), getSum64(7, 0, 60, 0)); + + // Different scales. + EXPECT_EQ(SP64(3, 0), getSum64(1, 0, 1, 1)); + EXPECT_EQ(SP64(4, 0), getSum64(2, 0, 1, 1)); + + // Loss of precision. + EXPECT_EQ(SP64(UINT64_C(1) << 63, 1), getSum64(1, 64, 1, 0)); + EXPECT_EQ(SP64(UINT64_C(1) << 63, -63), getSum64(1, -64, 1, 0)); + + // Not quite loss of precision. + EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, 1), getSum64(1, 64, 1, 1)); + EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, -64), getSum64(1, -64, 1, -1)); + + // Overflow. + EXPECT_EQ(SP64(UINT64_C(1) << 63, 1), getSum64(1, 0, UINT64_MAX, 0)); + + // Reverse operand order. + EXPECT_EQ(SP64(1, 0), getSum64(1, 0, 0, 0)); + EXPECT_EQ(SP64(8, -3), getSum64(8, -3, 0, 0)); + EXPECT_EQ(SP64(UINT64_MAX, 0), getSum64(UINT64_MAX, 0, 0, 0)); + EXPECT_EQ(SP64(3, 0), getSum64(2, 0, 1, 0)); + EXPECT_EQ(SP64(67, 0), getSum64(60, 0, 7, 0)); + EXPECT_EQ(SP64(3, 0), getSum64(1, 1, 1, 0)); + EXPECT_EQ(SP64(4, 0), getSum64(1, 1, 2, 0)); + EXPECT_EQ(SP64(UINT64_C(1) << 63, 1), getSum64(1, 0, 1, 64)); + EXPECT_EQ(SP64(UINT64_C(1) << 63, -63), getSum64(1, 0, 1, -64)); + EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, 1), getSum64(1, 1, 1, 64)); + EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, -64), getSum64(1, -1, 1, -64)); + EXPECT_EQ(SP64(UINT64_C(1) << 63, 1), getSum64(UINT64_MAX, 0, 1, 0)); +} + +TEST(ScaledNumberHelpersTest, getDifference) { + // Basic. + EXPECT_EQ(SP32(0, 0), getDifference32(1, 0, 1, 0)); + EXPECT_EQ(SP32(1, 0), getDifference32(2, 0, 1, 0)); + EXPECT_EQ(SP32(53, 0), getDifference32(60, 0, 7, 0)); + + // Equals "0", different scales. + EXPECT_EQ(SP32(0, 0), getDifference32(2, 0, 1, 1)); + + // Subtract "0". + EXPECT_EQ(SP32(1, 0), getDifference32(1, 0, 0, 0)); + EXPECT_EQ(SP32(8, -3), getDifference32(8, -3, 0, 0)); + EXPECT_EQ(SP32(UINT32_MAX, 0), getDifference32(UINT32_MAX, 0, 0, 0)); + + // Loss of precision. + EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, 1), + getDifference32((UINT32_C(1) << 31) + 1, 1, 1, 0)); + EXPECT_EQ(SP32((UINT32_C(1) << 31) + 1, -31), + getDifference32((UINT32_C(1) << 31) + 1, -31, 1, -32)); + + // Not quite loss of precision. + EXPECT_EQ(SP32(UINT32_MAX, 0), getDifference32(1, 32, 1, 0)); + EXPECT_EQ(SP32(UINT32_MAX, -32), getDifference32(1, 0, 1, -32)); + + // Saturate to "0". + EXPECT_EQ(SP32(0, 0), getDifference32(0, 0, 1, 0)); + EXPECT_EQ(SP32(0, 0), getDifference32(0, 0, 8, -3)); + EXPECT_EQ(SP32(0, 0), getDifference32(0, 0, UINT32_MAX, 0)); + EXPECT_EQ(SP32(0, 0), getDifference32(7, 0, 60, 0)); + EXPECT_EQ(SP32(0, 0), getDifference32(1, 0, 1, 1)); + EXPECT_EQ(SP32(0, 0), getDifference32(1, -32, 1, 0)); + EXPECT_EQ(SP32(0, 0), getDifference32(1, -32, 1, -1)); + + // Regression tests for cases that failed during bringup. + EXPECT_EQ(SP32(UINT32_C(1) << 26, -31), + getDifference32(1, 0, UINT32_C(31) << 27, -32)); + + // Basic. + EXPECT_EQ(SP64(0, 0), getDifference64(1, 0, 1, 0)); + EXPECT_EQ(SP64(1, 0), getDifference64(2, 0, 1, 0)); + EXPECT_EQ(SP64(53, 0), getDifference64(60, 0, 7, 0)); + + // Equals "0", different scales. + EXPECT_EQ(SP64(0, 0), getDifference64(2, 0, 1, 1)); + + // Subtract "0". + EXPECT_EQ(SP64(1, 0), getDifference64(1, 0, 0, 0)); + EXPECT_EQ(SP64(8, -3), getDifference64(8, -3, 0, 0)); + EXPECT_EQ(SP64(UINT64_MAX, 0), getDifference64(UINT64_MAX, 0, 0, 0)); + + // Loss of precision. + EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, 1), + getDifference64((UINT64_C(1) << 63) + 1, 1, 1, 0)); + EXPECT_EQ(SP64((UINT64_C(1) << 63) + 1, -63), + getDifference64((UINT64_C(1) << 63) + 1, -63, 1, -64)); + + // Not quite loss of precision. + EXPECT_EQ(SP64(UINT64_MAX, 0), getDifference64(1, 64, 1, 0)); + EXPECT_EQ(SP64(UINT64_MAX, -64), getDifference64(1, 0, 1, -64)); + + // Saturate to "0". + EXPECT_EQ(SP64(0, 0), getDifference64(0, 0, 1, 0)); + EXPECT_EQ(SP64(0, 0), getDifference64(0, 0, 8, -3)); + EXPECT_EQ(SP64(0, 0), getDifference64(0, 0, UINT64_MAX, 0)); + EXPECT_EQ(SP64(0, 0), getDifference64(7, 0, 60, 0)); + EXPECT_EQ(SP64(0, 0), getDifference64(1, 0, 1, 1)); + EXPECT_EQ(SP64(0, 0), getDifference64(1, -64, 1, 0)); + EXPECT_EQ(SP64(0, 0), getDifference64(1, -64, 1, -1)); +} + +} // end namespace diff --git a/unittests/Support/SpecialCaseListTest.cpp b/unittests/Support/SpecialCaseListTest.cpp new file mode 100644 index 0000000..bb9c351 --- /dev/null +++ b/unittests/Support/SpecialCaseListTest.cpp @@ -0,0 +1,126 @@ +//===- SpecialCaseListTest.cpp - Unit tests for SpecialCaseList -----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/SpecialCaseList.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +class SpecialCaseListTest : public ::testing::Test { +protected: + SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) { + std::unique_ptr<MemoryBuffer> MB(MemoryBuffer::getMemBuffer(List)); + return SpecialCaseList::create(MB.get(), Error); + } + + SpecialCaseList *makeSpecialCaseList(StringRef List) { + std::string Error; + SpecialCaseList *SCL = makeSpecialCaseList(List, Error); + assert(SCL); + assert(Error == ""); + return SCL; + } +}; + +TEST_F(SpecialCaseListTest, Basic) { + std::unique_ptr<SpecialCaseList> SCL( + makeSpecialCaseList("# This is a comment.\n" + "\n" + "src:hello\n" + "src:bye\n" + "src:hi=category\n" + "src:z*=category\n")); + EXPECT_TRUE(SCL->inSection("src", "hello")); + EXPECT_TRUE(SCL->inSection("src", "bye")); + EXPECT_TRUE(SCL->inSection("src", "hi", "category")); + EXPECT_TRUE(SCL->inSection("src", "zzzz", "category")); + EXPECT_FALSE(SCL->inSection("src", "hi")); + EXPECT_FALSE(SCL->inSection("fun", "hello")); + EXPECT_FALSE(SCL->inSection("src", "hello", "category")); +} + +TEST_F(SpecialCaseListTest, GlobalInitCompat) { + std::unique_ptr<SpecialCaseList> SCL( + makeSpecialCaseList("global:foo=init\n")); + EXPECT_FALSE(SCL->inSection("global", "foo")); + EXPECT_FALSE(SCL->inSection("global", "bar")); + EXPECT_TRUE(SCL->inSection("global", "foo", "init")); + EXPECT_FALSE(SCL->inSection("global", "bar", "init")); + + SCL.reset(makeSpecialCaseList("global-init:foo\n")); + EXPECT_FALSE(SCL->inSection("global", "foo")); + EXPECT_FALSE(SCL->inSection("global", "bar")); + EXPECT_TRUE(SCL->inSection("global", "foo", "init")); + EXPECT_FALSE(SCL->inSection("global", "bar", "init")); + + SCL.reset(makeSpecialCaseList("type:t2=init\n")); + EXPECT_FALSE(SCL->inSection("type", "t1")); + EXPECT_FALSE(SCL->inSection("type", "t2")); + EXPECT_FALSE(SCL->inSection("type", "t1", "init")); + EXPECT_TRUE(SCL->inSection("type", "t2", "init")); + + SCL.reset(makeSpecialCaseList("global-init-type:t2\n")); + EXPECT_FALSE(SCL->inSection("type", "t1")); + EXPECT_FALSE(SCL->inSection("type", "t2")); + EXPECT_FALSE(SCL->inSection("type", "t1", "init")); + EXPECT_TRUE(SCL->inSection("type", "t2", "init")); + + SCL.reset(makeSpecialCaseList("src:hello=init\n")); + EXPECT_FALSE(SCL->inSection("src", "hello")); + EXPECT_FALSE(SCL->inSection("src", "bye")); + EXPECT_TRUE(SCL->inSection("src", "hello", "init")); + EXPECT_FALSE(SCL->inSection("src", "bye", "init")); + + SCL.reset(makeSpecialCaseList("global-init-src:hello\n")); + EXPECT_FALSE(SCL->inSection("src", "hello")); + EXPECT_FALSE(SCL->inSection("src", "bye")); + EXPECT_TRUE(SCL->inSection("src", "hello", "init")); + EXPECT_FALSE(SCL->inSection("src", "bye", "init")); +} + +TEST_F(SpecialCaseListTest, Substring) { + std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("src:hello\n" + "fun:foo\n" + "global:bar\n")); + EXPECT_FALSE(SCL->inSection("src", "othello")); + EXPECT_FALSE(SCL->inSection("fun", "tomfoolery")); + EXPECT_FALSE(SCL->inSection("global", "bartender")); + + SCL.reset(makeSpecialCaseList("fun:*foo*\n")); + EXPECT_TRUE(SCL->inSection("fun", "tomfoolery")); + EXPECT_TRUE(SCL->inSection("fun", "foobar")); +} + +TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) { + std::string Error; + EXPECT_EQ(nullptr, makeSpecialCaseList("badline", Error)); + EXPECT_EQ("Malformed line 1: 'badline'", Error); + EXPECT_EQ(nullptr, makeSpecialCaseList("src:bad[a-", Error)); + EXPECT_EQ("Malformed regex in line 1: 'bad[a-': invalid character range", + Error); + EXPECT_EQ(nullptr, makeSpecialCaseList("src:a.c\n" + "fun:fun(a\n", + Error)); + EXPECT_EQ("Malformed regex in line 2: 'fun(a': parentheses not balanced", + Error); + EXPECT_EQ(nullptr, SpecialCaseList::create("unexisting", Error)); + EXPECT_EQ(0U, Error.find("Can't open file 'unexisting':")); +} + +TEST_F(SpecialCaseListTest, EmptySpecialCaseList) { + std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("")); + EXPECT_FALSE(SCL->inSection("foo", "bar")); +} + +} + + diff --git a/unittests/Support/StringPool.cpp b/unittests/Support/StringPool.cpp new file mode 100644 index 0000000..7b7805f --- /dev/null +++ b/unittests/Support/StringPool.cpp @@ -0,0 +1,31 @@ +//===- llvm/unittest/Support/ThreadLocalTest.cpp - Therad Local tests ---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/StringPool.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +TEST(PooledStringPtrTest, OperatorEquals) { + StringPool pool; + const PooledStringPtr a = pool.intern("a"); + const PooledStringPtr b = pool.intern("b"); + EXPECT_FALSE(a == b); +} + +TEST(PooledStringPtrTest, OperatorNotEquals) { + StringPool pool; + const PooledStringPtr a = pool.intern("a"); + const PooledStringPtr b = pool.intern("b"); + EXPECT_TRUE(a != b); +} + +} diff --git a/unittests/Support/SwapByteOrderTest.cpp b/unittests/Support/SwapByteOrderTest.cpp index 85ac6f3..525cfc1 100644 --- a/unittests/Support/SwapByteOrderTest.cpp +++ b/unittests/Support/SwapByteOrderTest.cpp @@ -20,70 +20,70 @@ namespace { // In these first two tests all of the original_uintx values are truncated // except for 64. We could avoid this, but there's really no point. -TEST(SwapByteOrder, UnsignedRoundTrip) { +TEST(getSwappedBytes, UnsignedRoundTrip) { // The point of the bit twiddling of magic is to test with and without bits // in every byte. uint64_t value = 1; for (std::size_t i = 0; i <= sizeof(value); ++i) { uint8_t original_uint8 = static_cast<uint8_t>(value); EXPECT_EQ(original_uint8, - sys::SwapByteOrder(sys::SwapByteOrder(original_uint8))); + sys::getSwappedBytes(sys::getSwappedBytes(original_uint8))); uint16_t original_uint16 = static_cast<uint16_t>(value); EXPECT_EQ(original_uint16, - sys::SwapByteOrder(sys::SwapByteOrder(original_uint16))); + sys::getSwappedBytes(sys::getSwappedBytes(original_uint16))); uint32_t original_uint32 = static_cast<uint32_t>(value); EXPECT_EQ(original_uint32, - sys::SwapByteOrder(sys::SwapByteOrder(original_uint32))); + sys::getSwappedBytes(sys::getSwappedBytes(original_uint32))); uint64_t original_uint64 = static_cast<uint64_t>(value); EXPECT_EQ(original_uint64, - sys::SwapByteOrder(sys::SwapByteOrder(original_uint64))); + sys::getSwappedBytes(sys::getSwappedBytes(original_uint64))); value = (value << 8) | 0x55; // binary 0101 0101. } } -TEST(SwapByteOrder, SignedRoundTrip) { +TEST(getSwappedBytes, SignedRoundTrip) { // The point of the bit twiddling of magic is to test with and without bits // in every byte. uint64_t value = 1; for (std::size_t i = 0; i <= sizeof(value); ++i) { int8_t original_int8 = static_cast<int8_t>(value); EXPECT_EQ(original_int8, - sys::SwapByteOrder(sys::SwapByteOrder(original_int8))); + sys::getSwappedBytes(sys::getSwappedBytes(original_int8))); int16_t original_int16 = static_cast<int16_t>(value); EXPECT_EQ(original_int16, - sys::SwapByteOrder(sys::SwapByteOrder(original_int16))); + sys::getSwappedBytes(sys::getSwappedBytes(original_int16))); int32_t original_int32 = static_cast<int32_t>(value); EXPECT_EQ(original_int32, - sys::SwapByteOrder(sys::SwapByteOrder(original_int32))); + sys::getSwappedBytes(sys::getSwappedBytes(original_int32))); int64_t original_int64 = static_cast<int64_t>(value); EXPECT_EQ(original_int64, - sys::SwapByteOrder(sys::SwapByteOrder(original_int64))); + sys::getSwappedBytes(sys::getSwappedBytes(original_int64))); // Test other sign. value *= -1; original_int8 = static_cast<int8_t>(value); EXPECT_EQ(original_int8, - sys::SwapByteOrder(sys::SwapByteOrder(original_int8))); + sys::getSwappedBytes(sys::getSwappedBytes(original_int8))); original_int16 = static_cast<int16_t>(value); EXPECT_EQ(original_int16, - sys::SwapByteOrder(sys::SwapByteOrder(original_int16))); + sys::getSwappedBytes(sys::getSwappedBytes(original_int16))); original_int32 = static_cast<int32_t>(value); EXPECT_EQ(original_int32, - sys::SwapByteOrder(sys::SwapByteOrder(original_int32))); + sys::getSwappedBytes(sys::getSwappedBytes(original_int32))); original_int64 = static_cast<int64_t>(value); EXPECT_EQ(original_int64, - sys::SwapByteOrder(sys::SwapByteOrder(original_int64))); + sys::getSwappedBytes(sys::getSwappedBytes(original_int64))); // Return to normal sign and twiddle. value *= -1; @@ -91,38 +91,86 @@ TEST(SwapByteOrder, SignedRoundTrip) { } } -TEST(SwapByteOrder, uint8_t) { - EXPECT_EQ(uint8_t(0x11), sys::SwapByteOrder(uint8_t(0x11))); +TEST(getSwappedBytes, uint8_t) { + EXPECT_EQ(uint8_t(0x11), sys::getSwappedBytes(uint8_t(0x11))); } -TEST(SwapByteOrder, uint16_t) { - EXPECT_EQ(uint16_t(0x1122), sys::SwapByteOrder(uint16_t(0x2211))); +TEST(getSwappedBytes, uint16_t) { + EXPECT_EQ(uint16_t(0x1122), sys::getSwappedBytes(uint16_t(0x2211))); } -TEST(SwapByteOrder, uint32_t) { - EXPECT_EQ(uint32_t(0x11223344), sys::SwapByteOrder(uint32_t(0x44332211))); +TEST(getSwappedBytes, uint32_t) { + EXPECT_EQ(uint32_t(0x11223344), sys::getSwappedBytes(uint32_t(0x44332211))); } -TEST(SwapByteOrder, uint64_t) { +TEST(getSwappedBytes, uint64_t) { EXPECT_EQ(uint64_t(0x1122334455667788ULL), - sys::SwapByteOrder(uint64_t(0x8877665544332211ULL))); + sys::getSwappedBytes(uint64_t(0x8877665544332211ULL))); } -TEST(SwapByteOrder, int8_t) { - EXPECT_EQ(int8_t(0x11), sys::SwapByteOrder(int8_t(0x11))); +TEST(getSwappedBytes, int8_t) { + EXPECT_EQ(int8_t(0x11), sys::getSwappedBytes(int8_t(0x11))); } -TEST(SwapByteOrder, int16_t) { - EXPECT_EQ(int16_t(0x1122), sys::SwapByteOrder(int16_t(0x2211))); +TEST(getSwappedBytes, int16_t) { + EXPECT_EQ(int16_t(0x1122), sys::getSwappedBytes(int16_t(0x2211))); } -TEST(SwapByteOrder, int32_t) { - EXPECT_EQ(int32_t(0x11223344), sys::SwapByteOrder(int32_t(0x44332211))); +TEST(getSwappedBytes, int32_t) { + EXPECT_EQ(int32_t(0x11223344), sys::getSwappedBytes(int32_t(0x44332211))); } -TEST(SwapByteOrder, int64_t) { +TEST(getSwappedBytes, int64_t) { EXPECT_EQ(int64_t(0x1122334455667788LL), - sys::SwapByteOrder(int64_t(0x8877665544332211LL))); + sys::getSwappedBytes(int64_t(0x8877665544332211LL))); +} + +TEST(swapByteOrder, uint8_t) { + uint8_t value = 0x11; + sys::swapByteOrder(value); + EXPECT_EQ(uint8_t(0x11), value); +} + +TEST(swapByteOrder, uint16_t) { + uint16_t value = 0x2211; + sys::swapByteOrder(value); + EXPECT_EQ(uint16_t(0x1122), value); +} + +TEST(swapByteOrder, uint32_t) { + uint32_t value = 0x44332211; + sys::swapByteOrder(value); + EXPECT_EQ(uint32_t(0x11223344), value); +} + +TEST(swapByteOrder, uint64_t) { + uint64_t value = 0x8877665544332211ULL; + sys::swapByteOrder(value); + EXPECT_EQ(uint64_t(0x1122334455667788ULL), value); +} + +TEST(swapByteOrder, int8_t) { + int8_t value = 0x11; + sys::swapByteOrder(value); + EXPECT_EQ(int8_t(0x11), value); +} + +TEST(swapByteOrder, int16_t) { + int16_t value = 0x2211; + sys::swapByteOrder(value); + EXPECT_EQ(int16_t(0x1122), value); +} + +TEST(swapByteOrder, int32_t) { + int32_t value = 0x44332211; + sys::swapByteOrder(value); + EXPECT_EQ(int32_t(0x11223344), value); +} + +TEST(swapByteOrder, int64_t) { + int64_t value = 0x8877665544332211LL; + sys::swapByteOrder(value); + EXPECT_EQ(int64_t(0x1122334455667788LL), value); } } diff --git a/unittests/Support/ThreadLocalTest.cpp b/unittests/Support/ThreadLocalTest.cpp index dd4d706..ea751be 100644 --- a/unittests/Support/ThreadLocalTest.cpp +++ b/unittests/Support/ThreadLocalTest.cpp @@ -25,14 +25,14 @@ struct S { TEST_F(ThreadLocalTest, Basics) { ThreadLocal<const S> x; - EXPECT_EQ(0, x.get()); + EXPECT_EQ(nullptr, x.get()); S s; x.set(&s); EXPECT_EQ(&s, x.get()); x.erase(); - EXPECT_EQ(0, x.get()); + EXPECT_EQ(nullptr, x.get()); } } diff --git a/unittests/Support/TimeValueTest.cpp b/unittests/Support/TimeValueTest.cpp index 8058812..3d2b978 100644 --- a/unittests/Support/TimeValueTest.cpp +++ b/unittests/Support/TimeValueTest.cpp @@ -16,7 +16,7 @@ namespace { TEST(TimeValue, time_t) { sys::TimeValue now = sys::TimeValue::now(); - time_t now_t = time(NULL); + time_t now_t = time(nullptr); EXPECT_TRUE(std::abs(static_cast<long>(now_t - now.toEpochTime())) < 2); } diff --git a/unittests/Support/YAMLIOTest.cpp b/unittests/Support/YAMLIOTest.cpp index cf95532..8aed980 100644 --- a/unittests/Support/YAMLIOTest.cpp +++ b/unittests/Support/YAMLIOTest.cpp @@ -1204,9 +1204,9 @@ TEST(YAMLIO, TestValidatingInput) { std::vector<MyValidation> docList; Input yin("--- \nvalue: 3.0\n" "--- \nvalue: -1.0\n...\n", - NULL, suppressErrorMessages); + nullptr, suppressErrorMessages); yin >> docList; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1224,10 +1224,10 @@ TEST(YAMLIO, TestColorsReadError) { "c2: purple\n" "c3: green\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> map; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1241,11 +1241,11 @@ TEST(YAMLIO, TestFlagsReadError) { "f2: [ round, hollow ]\n" "f3: []\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> map; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1260,11 +1260,11 @@ TEST(YAMLIO, TestReadBuiltInTypesUint8Error) { "- 0\n" "- 257\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1279,11 +1279,11 @@ TEST(YAMLIO, TestReadBuiltInTypesUint16Error) { "- 0\n" "- 66000\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1298,11 +1298,11 @@ TEST(YAMLIO, TestReadBuiltInTypesUint32Error) { "- 0\n" "- 5000000000\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1317,11 +1317,11 @@ TEST(YAMLIO, TestReadBuiltInTypesUint64Error) { "- 0\n" "- 19446744073709551615\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1337,11 +1337,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint8OverError) { "- 127\n" "- 128\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } // @@ -1355,11 +1355,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint8UnderError) { "- 127\n" "- -129\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1375,11 +1375,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint16UnderError) { "- -32768\n" "- -32769\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1394,11 +1394,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint16OverError) { "- -32768\n" "- 32768\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1414,11 +1414,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint32UnderError) { "- -2147483648\n" "- -2147483649\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } // @@ -1432,11 +1432,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint32OverError) { "- -2147483648\n" "- 2147483649\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1452,11 +1452,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint64UnderError) { "- 9223372036854775807\n" "- -9223372036854775809\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } // @@ -1470,11 +1470,11 @@ TEST(YAMLIO, TestReadBuiltInTypesint64OverError) { "- 9223372036854775807\n" "- 9223372036854775809\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } // @@ -1489,11 +1489,11 @@ TEST(YAMLIO, TestReadBuiltInTypesFloatError) { "- -123.456\n" "- 1.2.3\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } // @@ -1508,11 +1508,11 @@ TEST(YAMLIO, TestReadBuiltInTypesDoubleError) { "- -123.456\n" "- 1.2.3\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } // @@ -1526,11 +1526,11 @@ TEST(YAMLIO, TestReadBuiltInTypesHex8Error) { "- 0xFE\n" "- 0x123\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } @@ -1545,11 +1545,11 @@ TEST(YAMLIO, TestReadBuiltInTypesHex16Error) { "- 0xFEFF\n" "- 0x12345\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } // @@ -1563,11 +1563,11 @@ TEST(YAMLIO, TestReadBuiltInTypesHex32Error) { "- 0xFEFF0000\n" "- 0x1234556789\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } // @@ -1581,11 +1581,11 @@ TEST(YAMLIO, TestReadBuiltInTypesHex64Error) { "- 0xFFEEDDCCBBAA9988\n" "- 0x12345567890ABCDEF0\n" "...\n", - /*Ctxt=*/NULL, + /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } TEST(YAMLIO, TestMalformedMapFailsGracefully) { @@ -1593,15 +1593,15 @@ TEST(YAMLIO, TestMalformedMapFailsGracefully) { { // We pass the suppressErrorMessages handler to handle the error // message generated in the constructor of Input. - Input yin("{foo:3, bar: 5}", /*Ctxt=*/NULL, suppressErrorMessages); + Input yin("{foo:3, bar: 5}", /*Ctxt=*/nullptr, suppressErrorMessages); yin >> doc; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } { - Input yin("---\nfoo:3\nbar: 5\n...\n", /*Ctxt=*/NULL, suppressErrorMessages); + Input yin("---\nfoo:3\nbar: 5\n...\n", /*Ctxt=*/nullptr, suppressErrorMessages); yin >> doc; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } } @@ -1673,7 +1673,7 @@ TEST(YAMLIO, TestEmptyStringFailsForMapWithRequiredFields) { FooBar doc; Input yin(""); yin >> doc; - EXPECT_TRUE(yin.error()); + EXPECT_TRUE(!!yin.error()); } TEST(YAMLIO, TestEmptyStringSucceedsForMapWithOptionalFields) { @@ -1685,7 +1685,7 @@ TEST(YAMLIO, TestEmptyStringSucceedsForMapWithOptionalFields) { TEST(YAMLIO, TestEmptyStringSucceedsForSequence) { std::vector<uint8_t> seq; - Input yin("", /*Ctxt=*/NULL, suppressErrorMessages); + Input yin("", /*Ctxt=*/nullptr, suppressErrorMessages); yin >> seq; EXPECT_FALSE(yin.error()); diff --git a/unittests/Support/raw_ostream_test.cpp b/unittests/Support/raw_ostream_test.cpp index 2b797b4..44d27d0 100644 --- a/unittests/Support/raw_ostream_test.cpp +++ b/unittests/Support/raw_ostream_test.cpp @@ -69,7 +69,7 @@ TEST(raw_ostreamTest, Types_Buffered) { EXPECT_EQ("1.100000e+00", printToString(1.1)); // void* - EXPECT_EQ("0x0", printToString((void*) 0)); + EXPECT_EQ("0x0", printToString((void*) nullptr)); EXPECT_EQ("0xbeef", printToString((void*) 0xbeef)); EXPECT_EQ("0xdeadbeef", printToString((void*) 0xdeadbeef)); @@ -100,7 +100,7 @@ TEST(raw_ostreamTest, Types_Unbuffered) { EXPECT_EQ("1.100000e+00", printToStringUnbuffered(1.1)); // void* - EXPECT_EQ("0x0", printToStringUnbuffered((void*) 0)); + EXPECT_EQ("0x0", printToStringUnbuffered((void*) nullptr)); EXPECT_EQ("0xbeef", printToStringUnbuffered((void*) 0xbeef)); EXPECT_EQ("0xdeadbeef", printToStringUnbuffered((void*) 0xdeadbeef)); diff --git a/unittests/Transforms/DebugIR/DebugIR.cpp b/unittests/Transforms/DebugIR/DebugIR.cpp index 9b89c15..41df147 100644 --- a/unittests/Transforms/DebugIR/DebugIR.cpp +++ b/unittests/Transforms/DebugIR/DebugIR.cpp @@ -18,6 +18,7 @@ #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/Module.h" +#include "llvm/Support/Errc.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Host.h" #include "llvm/Support/Path.h" @@ -57,7 +58,7 @@ void insertCUDescriptor(Module *M, StringRef File, StringRef Dir, bool removeIfExists(StringRef Path) { // This is an approximation, on error we don't know in general if the file // existed or not. - llvm::error_code EC = sys::fs::remove(Path, false); + std::error_code EC = sys::fs::remove(Path, false); return EC != llvm::errc::no_such_file_or_directory; } @@ -65,7 +66,7 @@ char * current_dir() { #if defined(LLVM_ON_WIN32) || defined(HAVE_GETCWD) // calling getcwd (or _getcwd() on windows) with a null buffer makes it // allocate a sufficiently sized buffer to store the current working dir. - return getcwd_impl(0, 0); + return getcwd_impl(nullptr, 0); #else return 0; #endif diff --git a/unittests/Transforms/Utils/CMakeLists.txt b/unittests/Transforms/Utils/CMakeLists.txt index 60447bb..ffa1d49 100644 --- a/unittests/Transforms/Utils/CMakeLists.txt +++ b/unittests/Transforms/Utils/CMakeLists.txt @@ -9,5 +9,4 @@ add_llvm_unittest(UtilsTests Cloning.cpp IntegerDivision.cpp Local.cpp - SpecialCaseList.cpp ) diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp index fb27dc1..b3a1f5b 100644 --- a/unittests/Transforms/Utils/Cloning.cpp +++ b/unittests/Transforms/Utils/Cloning.cpp @@ -32,7 +32,7 @@ namespace { class CloneInstruction : public ::testing::Test { protected: virtual void SetUp() { - V = NULL; + V = nullptr; } template <typename T> @@ -272,7 +272,7 @@ protected: void CreateNewFunc() { ValueToValueMapTy VMap; - NewFunc = CloneFunction(OldFunc, VMap, true, NULL); + NewFunc = CloneFunction(OldFunc, VMap, true, nullptr); M->getFunctionList().push_back(NewFunc); } diff --git a/unittests/Transforms/Utils/SpecialCaseList.cpp b/unittests/Transforms/Utils/SpecialCaseList.cpp deleted file mode 100644 index fd00687..0000000 --- a/unittests/Transforms/Utils/SpecialCaseList.cpp +++ /dev/null @@ -1,232 +0,0 @@ -//===- SpecialCaseList.cpp - Unit tests for SpecialCaseList ---------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/IR/Function.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/Module.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Transforms/Utils/SpecialCaseList.h" -#include "gtest/gtest.h" - -using namespace llvm; - -namespace { - -class SpecialCaseListTest : public ::testing::Test { -protected: - Function *makeFunction(StringRef Name, Module &M) { - return Function::Create(FunctionType::get(Type::getVoidTy(Ctx), false), - GlobalValue::ExternalLinkage, - Name, - &M); - } - - GlobalVariable *makeGlobal(StringRef Name, StringRef StructName, Module &M) { - StructType *ST = - StructType::create(StructName, Type::getInt32Ty(Ctx), (Type*)0); - return new GlobalVariable( - M, ST, false, GlobalValue::ExternalLinkage, 0, Name); - } - - GlobalAlias *makeAlias(StringRef Name, GlobalObject *Aliasee) { - return GlobalAlias::create(GlobalValue::ExternalLinkage, Name, Aliasee); - } - - SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) { - std::unique_ptr<MemoryBuffer> MB(MemoryBuffer::getMemBuffer(List)); - return SpecialCaseList::create(MB.get(), Error); - } - - SpecialCaseList *makeSpecialCaseList(StringRef List) { - std::string Error; - SpecialCaseList *SCL = makeSpecialCaseList(List, Error); - assert(SCL); - assert(Error == ""); - return SCL; - } - - LLVMContext Ctx; -}; - -TEST_F(SpecialCaseListTest, ModuleIsIn) { - Module M("hello", Ctx); - Function *F = makeFunction("foo", M); - GlobalVariable *GV = makeGlobal("bar", "t", M); - - std::unique_ptr<SpecialCaseList> SCL( - makeSpecialCaseList("# This is a comment.\n" - "\n" - "src:hello\n")); - EXPECT_TRUE(SCL->isIn(M)); - EXPECT_TRUE(SCL->isIn(*F)); - EXPECT_TRUE(SCL->isIn(*GV)); - - SCL.reset(makeSpecialCaseList("src:he*o\n")); - EXPECT_TRUE(SCL->isIn(M)); - EXPECT_TRUE(SCL->isIn(*F)); - EXPECT_TRUE(SCL->isIn(*GV)); - - SCL.reset(makeSpecialCaseList("src:hi\n")); - EXPECT_FALSE(SCL->isIn(M)); - EXPECT_FALSE(SCL->isIn(*F)); - EXPECT_FALSE(SCL->isIn(*GV)); -} - -TEST_F(SpecialCaseListTest, FunctionIsIn) { - Module M("hello", Ctx); - Function *Foo = makeFunction("foo", M); - Function *Bar = makeFunction("bar", M); - - std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("fun:foo\n")); - EXPECT_TRUE(SCL->isIn(*Foo)); - EXPECT_FALSE(SCL->isIn(*Bar)); - - SCL.reset(makeSpecialCaseList("fun:b*\n")); - EXPECT_FALSE(SCL->isIn(*Foo)); - EXPECT_TRUE(SCL->isIn(*Bar)); - - SCL.reset(makeSpecialCaseList("fun:f*\n" - "fun:bar\n")); - EXPECT_TRUE(SCL->isIn(*Foo)); - EXPECT_TRUE(SCL->isIn(*Bar)); - - SCL.reset(makeSpecialCaseList("fun:foo=functional\n")); - EXPECT_TRUE(SCL->isIn(*Foo, "functional")); - StringRef Category; - EXPECT_FALSE(SCL->isIn(*Bar, "functional")); -} - -TEST_F(SpecialCaseListTest, GlobalIsIn) { - Module M("hello", Ctx); - GlobalVariable *Foo = makeGlobal("foo", "t1", M); - GlobalVariable *Bar = makeGlobal("bar", "t2", M); - - std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("global:foo\n")); - EXPECT_TRUE(SCL->isIn(*Foo)); - EXPECT_FALSE(SCL->isIn(*Bar)); - EXPECT_FALSE(SCL->isIn(*Foo, "init")); - EXPECT_FALSE(SCL->isIn(*Bar, "init")); - - SCL.reset(makeSpecialCaseList("global:foo=init\n")); - EXPECT_FALSE(SCL->isIn(*Foo)); - EXPECT_FALSE(SCL->isIn(*Bar)); - EXPECT_TRUE(SCL->isIn(*Foo, "init")); - EXPECT_FALSE(SCL->isIn(*Bar, "init")); - - SCL.reset(makeSpecialCaseList("global-init:foo\n")); - EXPECT_FALSE(SCL->isIn(*Foo)); - EXPECT_FALSE(SCL->isIn(*Bar)); - EXPECT_TRUE(SCL->isIn(*Foo, "init")); - EXPECT_FALSE(SCL->isIn(*Bar, "init")); - - SCL.reset(makeSpecialCaseList("type:t2=init\n")); - EXPECT_FALSE(SCL->isIn(*Foo)); - EXPECT_FALSE(SCL->isIn(*Bar)); - EXPECT_FALSE(SCL->isIn(*Foo, "init")); - EXPECT_TRUE(SCL->isIn(*Bar, "init")); - - SCL.reset(makeSpecialCaseList("global-init-type:t2\n")); - EXPECT_FALSE(SCL->isIn(*Foo)); - EXPECT_FALSE(SCL->isIn(*Bar)); - EXPECT_FALSE(SCL->isIn(*Foo, "init")); - EXPECT_TRUE(SCL->isIn(*Bar, "init")); - - SCL.reset(makeSpecialCaseList("src:hello=init\n")); - EXPECT_FALSE(SCL->isIn(*Foo)); - EXPECT_FALSE(SCL->isIn(*Bar)); - EXPECT_TRUE(SCL->isIn(*Foo, "init")); - EXPECT_TRUE(SCL->isIn(*Bar, "init")); - - SCL.reset(makeSpecialCaseList("global-init-src:hello\n")); - EXPECT_FALSE(SCL->isIn(*Foo)); - EXPECT_FALSE(SCL->isIn(*Bar)); - EXPECT_TRUE(SCL->isIn(*Foo, "init")); - EXPECT_TRUE(SCL->isIn(*Bar, "init")); -} - -TEST_F(SpecialCaseListTest, AliasIsIn) { - Module M("hello", Ctx); - Function *Foo = makeFunction("foo", M); - GlobalVariable *Bar = makeGlobal("bar", "t", M); - GlobalAlias *FooAlias = makeAlias("fooalias", Foo); - GlobalAlias *BarAlias = makeAlias("baralias", Bar); - - std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("fun:foo\n")); - EXPECT_FALSE(SCL->isIn(*FooAlias)); - EXPECT_FALSE(SCL->isIn(*BarAlias)); - - SCL.reset(makeSpecialCaseList("global:bar\n")); - EXPECT_FALSE(SCL->isIn(*FooAlias)); - EXPECT_FALSE(SCL->isIn(*BarAlias)); - - SCL.reset(makeSpecialCaseList("global:fooalias\n")); - EXPECT_FALSE(SCL->isIn(*FooAlias)); - EXPECT_FALSE(SCL->isIn(*BarAlias)); - - SCL.reset(makeSpecialCaseList("fun:fooalias\n")); - EXPECT_TRUE(SCL->isIn(*FooAlias)); - EXPECT_FALSE(SCL->isIn(*BarAlias)); - - SCL.reset(makeSpecialCaseList("global:baralias=init\n")); - EXPECT_FALSE(SCL->isIn(*FooAlias, "init")); - EXPECT_TRUE(SCL->isIn(*BarAlias, "init")); - - SCL.reset(makeSpecialCaseList("type:t=init\n")); - EXPECT_FALSE(SCL->isIn(*FooAlias, "init")); - EXPECT_TRUE(SCL->isIn(*BarAlias, "init")); - - SCL.reset(makeSpecialCaseList("fun:baralias=init\n")); - EXPECT_FALSE(SCL->isIn(*FooAlias, "init")); - EXPECT_FALSE(SCL->isIn(*BarAlias, "init")); -} - -TEST_F(SpecialCaseListTest, Substring) { - Module M("othello", Ctx); - Function *F = makeFunction("tomfoolery", M); - GlobalVariable *GV = makeGlobal("bartender", "t", M); - GlobalAlias *GA1 = makeAlias("buffoonery", F); - GlobalAlias *GA2 = makeAlias("foobar", GV); - - std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("src:hello\n" - "fun:foo\n" - "global:bar\n")); - EXPECT_FALSE(SCL->isIn(M)); - EXPECT_FALSE(SCL->isIn(*F)); - EXPECT_FALSE(SCL->isIn(*GV)); - EXPECT_FALSE(SCL->isIn(*GA1)); - EXPECT_FALSE(SCL->isIn(*GA2)); - - SCL.reset(makeSpecialCaseList("fun:*foo*\n")); - EXPECT_TRUE(SCL->isIn(*F)); - EXPECT_TRUE(SCL->isIn(*GA1)); -} - -TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) { - std::string Error; - EXPECT_EQ(0, makeSpecialCaseList("badline", Error)); - EXPECT_EQ("Malformed line 1: 'badline'", Error); - EXPECT_EQ(0, makeSpecialCaseList("src:bad[a-", Error)); - EXPECT_EQ("Malformed regex in line 1: 'bad[a-': invalid character range", - Error); - EXPECT_EQ(0, makeSpecialCaseList("src:a.c\n" - "fun:fun(a\n", - Error)); - EXPECT_EQ("Malformed regex in line 2: 'fun(a': parentheses not balanced", - Error); - EXPECT_EQ(0, SpecialCaseList::create("unexisting", Error)); - EXPECT_EQ(0U, Error.find("Can't open file 'unexisting':")); -} - -TEST_F(SpecialCaseListTest, EmptySpecialCaseList) { - std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("")); - Module M("foo", Ctx); - EXPECT_FALSE(SCL->isIn(M)); -} - -} |