diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-06-10 19:59:23 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-06-10 19:59:23 +0000 |
commit | da32c729a8e4c8fdfd1a30d4dcd2955d1366f22c (patch) | |
tree | 5df31f11bd529d5065815f704c0fb41bc9ce26a1 /contrib/llvm/unittests/Support | |
parent | 88ae17c7ef1b0e23829cd4e275aeb58b58df7609 (diff) | |
download | FreeBSD-src-da32c729a8e4c8fdfd1a30d4dcd2955d1366f22c.zip FreeBSD-src-da32c729a8e4c8fdfd1a30d4dcd2955d1366f22c.tar.gz |
Remove Xcode cmake win32 projects unittests from LLVM and
clang.xcodeproj INPUTS win32 from clang.
Requested by: jkim
Approved by: ed (mentor)
Diffstat (limited to 'contrib/llvm/unittests/Support')
-rw-r--r-- | contrib/llvm/unittests/Support/AllocatorTest.cpp | 143 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/CommandLineTest.cpp | 60 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/ConstantRangeTest.cpp | 351 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/LeakDetectorTest.cpp | 31 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/Makefile | 15 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/MathExtrasTest.cpp | 104 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/RegexTest.cpp | 94 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/System.cpp | 16 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/TypeBuilderTest.cpp | 253 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/ValueHandleTest.cpp | 412 | ||||
-rw-r--r-- | contrib/llvm/unittests/Support/raw_ostream_test.cpp | 146 |
11 files changed, 0 insertions, 1625 deletions
diff --git a/contrib/llvm/unittests/Support/AllocatorTest.cpp b/contrib/llvm/unittests/Support/AllocatorTest.cpp deleted file mode 100644 index 6c0fca9..0000000 --- a/contrib/llvm/unittests/Support/AllocatorTest.cpp +++ /dev/null @@ -1,143 +0,0 @@ -//===- llvm/unittest/Support/AllocatorTest.cpp - BumpPtrAllocator 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/Allocator.h" - -#include "gtest/gtest.h" -#include <cstdlib> - -using namespace llvm; - -namespace { - -TEST(AllocatorTest, Basics) { - BumpPtrAllocator Alloc; - int *a = (int*)Alloc.Allocate(sizeof(int), 0); - int *b = (int*)Alloc.Allocate(sizeof(int) * 10, 0); - int *c = (int*)Alloc.Allocate(sizeof(int), 0); - *a = 1; - b[0] = 2; - b[9] = 2; - *c = 3; - EXPECT_EQ(1, *a); - EXPECT_EQ(2, b[0]); - EXPECT_EQ(2, b[9]); - EXPECT_EQ(3, *c); - EXPECT_EQ(1U, Alloc.GetNumSlabs()); -} - -// Allocate enough bytes to create three slabs. -TEST(AllocatorTest, ThreeSlabs) { - BumpPtrAllocator Alloc(4096, 4096); - Alloc.Allocate(3000, 0); - EXPECT_EQ(1U, Alloc.GetNumSlabs()); - Alloc.Allocate(3000, 0); - EXPECT_EQ(2U, Alloc.GetNumSlabs()); - Alloc.Allocate(3000, 0); - EXPECT_EQ(3U, Alloc.GetNumSlabs()); -} - -// Allocate enough bytes to create two slabs, reset the allocator, and do it -// again. -TEST(AllocatorTest, TestReset) { - BumpPtrAllocator Alloc(4096, 4096); - Alloc.Allocate(3000, 0); - EXPECT_EQ(1U, Alloc.GetNumSlabs()); - Alloc.Allocate(3000, 0); - EXPECT_EQ(2U, Alloc.GetNumSlabs()); - Alloc.Reset(); - EXPECT_EQ(1U, Alloc.GetNumSlabs()); - Alloc.Allocate(3000, 0); - EXPECT_EQ(1U, Alloc.GetNumSlabs()); - Alloc.Allocate(3000, 0); - EXPECT_EQ(2U, Alloc.GetNumSlabs()); -} - -// Test some allocations at varying alignments. -TEST(AllocatorTest, TestAlignment) { - BumpPtrAllocator Alloc; - uintptr_t a; - a = (uintptr_t)Alloc.Allocate(1, 2); - EXPECT_EQ(0U, a & 1); - a = (uintptr_t)Alloc.Allocate(1, 4); - EXPECT_EQ(0U, a & 3); - a = (uintptr_t)Alloc.Allocate(1, 8); - EXPECT_EQ(0U, a & 7); - a = (uintptr_t)Alloc.Allocate(1, 16); - EXPECT_EQ(0U, a & 15); - a = (uintptr_t)Alloc.Allocate(1, 32); - EXPECT_EQ(0U, a & 31); - a = (uintptr_t)Alloc.Allocate(1, 64); - EXPECT_EQ(0U, a & 63); - a = (uintptr_t)Alloc.Allocate(1, 128); - EXPECT_EQ(0U, a & 127); -} - -// Test allocating just over the slab size. This tests a bug where before the -// allocator incorrectly calculated the buffer end pointer. -TEST(AllocatorTest, TestOverflow) { - BumpPtrAllocator Alloc(4096, 4096); - - // Fill the slab right up until the end pointer. - Alloc.Allocate(4096 - sizeof(MemSlab), 0); - EXPECT_EQ(1U, Alloc.GetNumSlabs()); - - // If we don't allocate a new slab, then we will have overflowed. - Alloc.Allocate(1, 0); - EXPECT_EQ(2U, Alloc.GetNumSlabs()); -} - -// Mock slab allocator that returns slabs aligned on 4096 bytes. There is no -// easy portable way to do this, so this is kind of a hack. -class MockSlabAllocator : public SlabAllocator { - MemSlab *LastSlab; - -public: - virtual ~MockSlabAllocator() { } - - virtual MemSlab *Allocate(size_t Size) { - // Allocate space for the alignment, the slab, and a void* that goes right - // before the slab. - size_t Alignment = 4096; - void *MemBase = malloc(Size + Alignment - 1 + sizeof(void*)); - - // Make the slab. - MemSlab *Slab = (MemSlab*)(((uintptr_t)MemBase+sizeof(void*)+Alignment-1) & - ~(uintptr_t)(Alignment - 1)); - Slab->Size = Size; - Slab->NextPtr = 0; - - // Hold a pointer to the base so we can free the whole malloced block. - ((void**)Slab)[-1] = MemBase; - - LastSlab = Slab; - return Slab; - } - - virtual void Deallocate(MemSlab *Slab) { - free(((void**)Slab)[-1]); - } - - MemSlab *GetLastSlab() { - return LastSlab; - } -}; - -// Allocate a large-ish block with a really large alignment so that the -// allocator will think that it has space, but after it does the alignment it -// will not. -TEST(AllocatorTest, TestBigAlignment) { - MockSlabAllocator SlabAlloc; - BumpPtrAllocator Alloc(4096, 4096, SlabAlloc); - uintptr_t Ptr = (uintptr_t)Alloc.Allocate(3000, 2048); - MemSlab *Slab = SlabAlloc.GetLastSlab(); - EXPECT_LE(Ptr + 3000, ((uintptr_t)Slab) + Slab->Size); -} - -} // anonymous namespace diff --git a/contrib/llvm/unittests/Support/CommandLineTest.cpp b/contrib/llvm/unittests/Support/CommandLineTest.cpp deleted file mode 100644 index 72fa24a..0000000 --- a/contrib/llvm/unittests/Support/CommandLineTest.cpp +++ /dev/null @@ -1,60 +0,0 @@ -//===- llvm/unittest/Support/CommandLineTest.cpp - CommandLine 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/CommandLine.h" -#include "llvm/Config/config.h" - -#include "gtest/gtest.h" - -#include <string> -#include <stdlib.h> - -using namespace llvm; - -namespace { - -class TempEnvVar { - public: - TempEnvVar(const char *name, const char *value) - : name(name) { - const char *old_value = getenv(name); - EXPECT_EQ(NULL, old_value) << old_value; -#if HAVE_SETENV - setenv(name, value, true); -#else -# define SKIP_ENVIRONMENT_TESTS -#endif - } - - ~TempEnvVar() { -#if HAVE_SETENV - // Assume setenv and unsetenv come together. - unsetenv(name); -#endif - } - - private: - const char *const name; -}; - -#ifndef SKIP_ENVIRONMENT_TESTS - -const char test_env_var[] = "LLVM_TEST_COMMAND_LINE_FLAGS"; - -cl::opt<std::string> EnvironmentTestOption("env-test-opt"); -TEST(CommandLineTest, ParseEnvironment) { - TempEnvVar TEV(test_env_var, "-env-test-opt=hello"); - EXPECT_EQ("", EnvironmentTestOption); - cl::ParseEnvironmentOptions("CommandLineTest", test_env_var); - EXPECT_EQ("hello", EnvironmentTestOption); -} - -#endif // SKIP_ENVIRONMENT_TESTS - -} // anonymous namespace diff --git a/contrib/llvm/unittests/Support/ConstantRangeTest.cpp b/contrib/llvm/unittests/Support/ConstantRangeTest.cpp deleted file mode 100644 index 6b8d01d..0000000 --- a/contrib/llvm/unittests/Support/ConstantRangeTest.cpp +++ /dev/null @@ -1,351 +0,0 @@ -//===- llvm/unittest/Support/ConstantRangeTest.cpp - ConstantRange 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/ConstantRange.h" - -#include "gtest/gtest.h" - -using namespace llvm; - -namespace { - -class ConstantRangeTest : public ::testing::Test { -protected: - static ConstantRange Full; - static ConstantRange Empty; - static ConstantRange One; - static ConstantRange Some; - static ConstantRange Wrap; -}; - -ConstantRange ConstantRangeTest::Full(16); -ConstantRange ConstantRangeTest::Empty(16, false); -ConstantRange ConstantRangeTest::One(APInt(16, 0xa)); -ConstantRange ConstantRangeTest::Some(APInt(16, 0xa), APInt(16, 0xaaa)); -ConstantRange ConstantRangeTest::Wrap(APInt(16, 0xaaa), APInt(16, 0xa)); - -TEST_F(ConstantRangeTest, Basics) { - EXPECT_TRUE(Full.isFullSet()); - EXPECT_FALSE(Full.isEmptySet()); - EXPECT_FALSE(Full.isWrappedSet()); - EXPECT_TRUE(Full.contains(APInt(16, 0x0))); - EXPECT_TRUE(Full.contains(APInt(16, 0x9))); - EXPECT_TRUE(Full.contains(APInt(16, 0xa))); - EXPECT_TRUE(Full.contains(APInt(16, 0xaa9))); - EXPECT_TRUE(Full.contains(APInt(16, 0xaaa))); - - EXPECT_FALSE(Empty.isFullSet()); - EXPECT_TRUE(Empty.isEmptySet()); - EXPECT_FALSE(Empty.isWrappedSet()); - EXPECT_FALSE(Empty.contains(APInt(16, 0x0))); - EXPECT_FALSE(Empty.contains(APInt(16, 0x9))); - EXPECT_FALSE(Empty.contains(APInt(16, 0xa))); - EXPECT_FALSE(Empty.contains(APInt(16, 0xaa9))); - EXPECT_FALSE(Empty.contains(APInt(16, 0xaaa))); - - EXPECT_FALSE(One.isFullSet()); - EXPECT_FALSE(One.isEmptySet()); - EXPECT_FALSE(One.isWrappedSet()); - EXPECT_FALSE(One.contains(APInt(16, 0x0))); - EXPECT_FALSE(One.contains(APInt(16, 0x9))); - EXPECT_TRUE(One.contains(APInt(16, 0xa))); - EXPECT_FALSE(One.contains(APInt(16, 0xaa9))); - EXPECT_FALSE(One.contains(APInt(16, 0xaaa))); - - EXPECT_FALSE(Some.isFullSet()); - EXPECT_FALSE(Some.isEmptySet()); - EXPECT_FALSE(Some.isWrappedSet()); - EXPECT_FALSE(Some.contains(APInt(16, 0x0))); - EXPECT_FALSE(Some.contains(APInt(16, 0x9))); - EXPECT_TRUE(Some.contains(APInt(16, 0xa))); - EXPECT_TRUE(Some.contains(APInt(16, 0xaa9))); - EXPECT_FALSE(Some.contains(APInt(16, 0xaaa))); - - EXPECT_FALSE(Wrap.isFullSet()); - EXPECT_FALSE(Wrap.isEmptySet()); - EXPECT_TRUE(Wrap.isWrappedSet()); - EXPECT_TRUE(Wrap.contains(APInt(16, 0x0))); - EXPECT_TRUE(Wrap.contains(APInt(16, 0x9))); - EXPECT_FALSE(Wrap.contains(APInt(16, 0xa))); - EXPECT_FALSE(Wrap.contains(APInt(16, 0xaa9))); - EXPECT_TRUE(Wrap.contains(APInt(16, 0xaaa))); -} - -TEST_F(ConstantRangeTest, Equality) { - EXPECT_EQ(Full, Full); - EXPECT_EQ(Empty, Empty); - EXPECT_EQ(One, One); - EXPECT_EQ(Some, Some); - EXPECT_EQ(Wrap, Wrap); - EXPECT_NE(Full, Empty); - EXPECT_NE(Full, One); - EXPECT_NE(Full, Some); - EXPECT_NE(Full, Wrap); - EXPECT_NE(Empty, One); - EXPECT_NE(Empty, Some); - EXPECT_NE(Empty, Wrap); - EXPECT_NE(One, Some); - EXPECT_NE(One, Wrap); - EXPECT_NE(Some, Wrap); -} - -TEST_F(ConstantRangeTest, SingleElement) { - EXPECT_EQ(Full.getSingleElement(), static_cast<APInt *>(NULL)); - EXPECT_EQ(Empty.getSingleElement(), static_cast<APInt *>(NULL)); - EXPECT_EQ(*One.getSingleElement(), APInt(16, 0xa)); - EXPECT_EQ(Some.getSingleElement(), static_cast<APInt *>(NULL)); - EXPECT_EQ(Wrap.getSingleElement(), static_cast<APInt *>(NULL)); - - EXPECT_FALSE(Full.isSingleElement()); - EXPECT_FALSE(Empty.isSingleElement()); - EXPECT_TRUE(One.isSingleElement()); - EXPECT_FALSE(Some.isSingleElement()); - EXPECT_FALSE(Wrap.isSingleElement()); -} - -TEST_F(ConstantRangeTest, GetSetSize) { - EXPECT_EQ(Full.getSetSize(), APInt(16, 0)); - EXPECT_EQ(Empty.getSetSize(), APInt(16, 0)); - EXPECT_EQ(One.getSetSize(), APInt(16, 1)); - EXPECT_EQ(Some.getSetSize(), APInt(16, 0xaa0)); - EXPECT_EQ(Wrap.getSetSize(), APInt(16, 0x10000 - 0xaa0)); -} - -TEST_F(ConstantRangeTest, GetMinsAndMaxes) { - EXPECT_EQ(Full.getUnsignedMax(), APInt(16, UINT16_MAX)); - EXPECT_EQ(One.getUnsignedMax(), APInt(16, 0xa)); - EXPECT_EQ(Some.getUnsignedMax(), APInt(16, 0xaa9)); - EXPECT_EQ(Wrap.getUnsignedMax(), APInt(16, UINT16_MAX)); - - EXPECT_EQ(Full.getUnsignedMin(), APInt(16, 0)); - EXPECT_EQ(One.getUnsignedMin(), APInt(16, 0xa)); - EXPECT_EQ(Some.getUnsignedMin(), APInt(16, 0xa)); - EXPECT_EQ(Wrap.getUnsignedMin(), APInt(16, 0)); - - EXPECT_EQ(Full.getSignedMax(), APInt(16, INT16_MAX)); - EXPECT_EQ(One.getSignedMax(), APInt(16, 0xa)); - EXPECT_EQ(Some.getSignedMax(), APInt(16, 0xaa9)); - EXPECT_EQ(Wrap.getSignedMax(), APInt(16, INT16_MAX)); - - EXPECT_EQ(Full.getSignedMin(), APInt(16, (uint64_t)INT16_MIN)); - EXPECT_EQ(One.getSignedMin(), APInt(16, 0xa)); - EXPECT_EQ(Some.getSignedMin(), APInt(16, 0xa)); - EXPECT_EQ(Wrap.getSignedMin(), APInt(16, (uint64_t)INT16_MIN)); - - // Found by Klee - EXPECT_EQ(ConstantRange(APInt(4, 7), APInt(4, 0)).getSignedMax(), - APInt(4, 7)); -} - -TEST_F(ConstantRangeTest, Trunc) { - ConstantRange TFull = Full.truncate(10); - ConstantRange TEmpty = Empty.truncate(10); - ConstantRange TOne = One.truncate(10); - ConstantRange TSome = Some.truncate(10); - ConstantRange TWrap = Wrap.truncate(10); - EXPECT_TRUE(TFull.isFullSet()); - EXPECT_TRUE(TEmpty.isEmptySet()); - EXPECT_EQ(TOne, ConstantRange(APInt(One.getLower()).trunc(10), - APInt(One.getUpper()).trunc(10))); - EXPECT_TRUE(TSome.isFullSet()); -} - -TEST_F(ConstantRangeTest, ZExt) { - ConstantRange ZFull = Full.zeroExtend(20); - ConstantRange ZEmpty = Empty.zeroExtend(20); - ConstantRange ZOne = One.zeroExtend(20); - ConstantRange ZSome = Some.zeroExtend(20); - ConstantRange ZWrap = Wrap.zeroExtend(20); - EXPECT_EQ(ZFull, ConstantRange(APInt(20, 0), APInt(20, 0x10000))); - EXPECT_TRUE(ZEmpty.isEmptySet()); - EXPECT_EQ(ZOne, ConstantRange(APInt(One.getLower()).zext(20), - APInt(One.getUpper()).zext(20))); - EXPECT_EQ(ZSome, ConstantRange(APInt(Some.getLower()).zext(20), - APInt(Some.getUpper()).zext(20))); - EXPECT_EQ(ZWrap, ConstantRange(APInt(Wrap.getLower()).zext(20), - APInt(Wrap.getUpper()).zext(20))); -} - -TEST_F(ConstantRangeTest, SExt) { - ConstantRange SFull = Full.signExtend(20); - ConstantRange SEmpty = Empty.signExtend(20); - ConstantRange SOne = One.signExtend(20); - ConstantRange SSome = Some.signExtend(20); - ConstantRange SWrap = Wrap.signExtend(20); - EXPECT_EQ(SFull, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true), - APInt(20, INT16_MAX + 1, true))); - EXPECT_TRUE(SEmpty.isEmptySet()); - EXPECT_EQ(SOne, ConstantRange(APInt(One.getLower()).sext(20), - APInt(One.getUpper()).sext(20))); - EXPECT_EQ(SSome, ConstantRange(APInt(Some.getLower()).sext(20), - APInt(Some.getUpper()).sext(20))); - EXPECT_EQ(SWrap, ConstantRange(APInt(Wrap.getLower()).sext(20), - APInt(Wrap.getUpper()).sext(20))); -} - -TEST_F(ConstantRangeTest, IntersectWith) { - EXPECT_EQ(Empty.intersectWith(Full), Empty); - EXPECT_EQ(Empty.intersectWith(Empty), Empty); - EXPECT_EQ(Empty.intersectWith(One), Empty); - EXPECT_EQ(Empty.intersectWith(Some), Empty); - EXPECT_EQ(Empty.intersectWith(Wrap), Empty); - EXPECT_EQ(Full.intersectWith(Full), Full); - EXPECT_EQ(Some.intersectWith(Some), Some); - EXPECT_EQ(Some.intersectWith(One), One); - EXPECT_EQ(Full.intersectWith(One), One); - EXPECT_EQ(Full.intersectWith(Some), Some); - EXPECT_EQ(Some.intersectWith(Wrap), Empty); - EXPECT_EQ(One.intersectWith(Wrap), Empty); - EXPECT_EQ(One.intersectWith(Wrap), Wrap.intersectWith(One)); - - // Klee generated testcase from PR4545. - // The intersection of i16 [4, 2) and [6, 5) is disjoint, looking like - // 01..4.6789ABCDEF where the dots represent values not in the intersection. - ConstantRange LHS(APInt(16, 4), APInt(16, 2)); - ConstantRange RHS(APInt(16, 6), APInt(16, 5)); - EXPECT_TRUE(LHS.intersectWith(RHS) == LHS); -} - -TEST_F(ConstantRangeTest, UnionWith) { - EXPECT_EQ(Wrap.unionWith(One), - ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb))); - EXPECT_EQ(One.unionWith(Wrap), Wrap.unionWith(One)); - EXPECT_EQ(Empty.unionWith(Empty), Empty); - EXPECT_EQ(Full.unionWith(Full), Full); - EXPECT_EQ(Some.unionWith(Wrap), Full); - - // PR4545 - EXPECT_EQ(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith( - ConstantRange(APInt(16, 0), APInt(16, 8))), - ConstantRange(APInt(16, 14), APInt(16, 8))); - EXPECT_EQ(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith( - ConstantRange(APInt(16, 4), APInt(16, 0))), - ConstantRange(16)); - EXPECT_EQ(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith( - ConstantRange(APInt(16, 2), APInt(16, 1))), - ConstantRange(16)); -} - -TEST_F(ConstantRangeTest, SubtractAPInt) { - EXPECT_EQ(Full.subtract(APInt(16, 4)), Full); - EXPECT_EQ(Empty.subtract(APInt(16, 4)), Empty); - EXPECT_EQ(Some.subtract(APInt(16, 4)), - ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6))); - EXPECT_EQ(Wrap.subtract(APInt(16, 4)), - ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6))); - EXPECT_EQ(One.subtract(APInt(16, 4)), - ConstantRange(APInt(16, 0x6))); -} - -TEST_F(ConstantRangeTest, Add) { - EXPECT_EQ(Full.add(APInt(16, 4)), Full); - EXPECT_EQ(Full.add(Full), Full); - EXPECT_EQ(Full.add(Empty), Empty); - EXPECT_EQ(Full.add(One), Full); - EXPECT_EQ(Full.add(Some), Full); - EXPECT_EQ(Full.add(Wrap), Full); - EXPECT_EQ(Empty.add(Empty), Empty); - EXPECT_EQ(Empty.add(One), Empty); - EXPECT_EQ(Empty.add(Some), Empty); - EXPECT_EQ(Empty.add(Wrap), Empty); - EXPECT_EQ(Empty.add(APInt(16, 4)), Empty); - EXPECT_EQ(Some.add(APInt(16, 4)), - ConstantRange(APInt(16, 0xe), APInt(16, 0xaae))); - EXPECT_EQ(Wrap.add(APInt(16, 4)), - ConstantRange(APInt(16, 0xaae), APInt(16, 0xe))); - EXPECT_EQ(One.add(APInt(16, 4)), - ConstantRange(APInt(16, 0xe))); -} - -TEST_F(ConstantRangeTest, Multiply) { - EXPECT_EQ(Full.multiply(Full), Full); - EXPECT_EQ(Full.multiply(Empty), Empty); - EXPECT_EQ(Full.multiply(One), Full); - EXPECT_EQ(Full.multiply(Some), Full); - EXPECT_EQ(Full.multiply(Wrap), Full); - EXPECT_EQ(Empty.multiply(Empty), Empty); - EXPECT_EQ(Empty.multiply(One), Empty); - EXPECT_EQ(Empty.multiply(Some), Empty); - EXPECT_EQ(Empty.multiply(Wrap), Empty); - EXPECT_EQ(One.multiply(One), ConstantRange(APInt(16, 0xa*0xa), - APInt(16, 0xa*0xa + 1))); - EXPECT_EQ(One.multiply(Some), ConstantRange(APInt(16, 0xa*0xa), - APInt(16, 0xa*0xaa9 + 1))); - EXPECT_EQ(One.multiply(Wrap), Full); - EXPECT_EQ(Some.multiply(Some), Full); - EXPECT_EQ(Some.multiply(Wrap), Full); - EXPECT_EQ(Wrap.multiply(Wrap), Full); - - // http://llvm.org/PR4545 - EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply( - ConstantRange(APInt(4, 6), APInt(4, 2))), - ConstantRange(4, /*isFullSet=*/true)); -} - -TEST_F(ConstantRangeTest, UMax) { - EXPECT_EQ(Full.umax(Full), Full); - EXPECT_EQ(Full.umax(Empty), Empty); - EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0))); - EXPECT_EQ(Full.umax(Wrap), Full); - EXPECT_EQ(Full.umax(Some), ConstantRange(APInt(16, 0xa), APInt(16, 0))); - EXPECT_EQ(Empty.umax(Empty), Empty); - EXPECT_EQ(Empty.umax(Some), Empty); - EXPECT_EQ(Empty.umax(Wrap), Empty); - EXPECT_EQ(Empty.umax(One), Empty); - EXPECT_EQ(Some.umax(Some), Some); - EXPECT_EQ(Some.umax(Wrap), ConstantRange(APInt(16, 0xa), APInt(16, 0))); - EXPECT_EQ(Some.umax(One), Some); - // TODO: ConstantRange is currently over-conservative here. - EXPECT_EQ(Wrap.umax(Wrap), Full); - EXPECT_EQ(Wrap.umax(One), ConstantRange(APInt(16, 0xa), APInt(16, 0))); - EXPECT_EQ(One.umax(One), One); -} - -TEST_F(ConstantRangeTest, SMax) { - EXPECT_EQ(Full.smax(Full), Full); - EXPECT_EQ(Full.smax(Empty), Empty); - EXPECT_EQ(Full.smax(Some), ConstantRange(APInt(16, 0xa), - APInt::getSignedMinValue(16))); - EXPECT_EQ(Full.smax(Wrap), Full); - EXPECT_EQ(Full.smax(One), ConstantRange(APInt(16, 0xa), - APInt::getSignedMinValue(16))); - EXPECT_EQ(Empty.smax(Empty), Empty); - EXPECT_EQ(Empty.smax(Some), Empty); - EXPECT_EQ(Empty.smax(Wrap), Empty); - EXPECT_EQ(Empty.smax(One), Empty); - EXPECT_EQ(Some.smax(Some), Some); - EXPECT_EQ(Some.smax(Wrap), ConstantRange(APInt(16, 0xa), - APInt(16, (uint64_t)INT16_MIN))); - EXPECT_EQ(Some.smax(One), Some); - EXPECT_EQ(Wrap.smax(One), ConstantRange(APInt(16, 0xa), - APInt(16, (uint64_t)INT16_MIN))); - EXPECT_EQ(One.smax(One), One); -} - -TEST_F(ConstantRangeTest, UDiv) { - EXPECT_EQ(Full.udiv(Full), Full); - EXPECT_EQ(Full.udiv(Empty), Empty); - EXPECT_EQ(Full.udiv(One), ConstantRange(APInt(16, 0), - APInt(16, 0xffff / 0xa + 1))); - EXPECT_EQ(Full.udiv(Some), ConstantRange(APInt(16, 0), - APInt(16, 0xffff / 0xa + 1))); - EXPECT_EQ(Full.udiv(Wrap), Full); - EXPECT_EQ(Empty.udiv(Empty), Empty); - EXPECT_EQ(Empty.udiv(One), Empty); - EXPECT_EQ(Empty.udiv(Some), Empty); - EXPECT_EQ(Empty.udiv(Wrap), Empty); - EXPECT_EQ(One.udiv(One), ConstantRange(APInt(16, 1))); - EXPECT_EQ(One.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 2))); - EXPECT_EQ(One.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb))); - EXPECT_EQ(Some.udiv(Some), ConstantRange(APInt(16, 0), APInt(16, 0x111))); - EXPECT_EQ(Some.udiv(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa))); - EXPECT_EQ(Wrap.udiv(Wrap), Full); -} - -} // anonymous namespace diff --git a/contrib/llvm/unittests/Support/LeakDetectorTest.cpp b/contrib/llvm/unittests/Support/LeakDetectorTest.cpp deleted file mode 100644 index d198c7a..0000000 --- a/contrib/llvm/unittests/Support/LeakDetectorTest.cpp +++ /dev/null @@ -1,31 +0,0 @@ -//===- llvm/unittest/LeakDetector/LeakDetector.cpp - LeakDetector tests ---===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "gtest/gtest.h" -#include "llvm/Support/LeakDetector.h" - -using namespace llvm; - -namespace { - -#ifdef GTEST_HAS_DEATH_TEST -#ifndef NDEBUG -TEST(LeakDetector, Death1) { - LeakDetector::addGarbageObject((void*) 1); - LeakDetector::addGarbageObject((void*) 2); - - EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 1), - ".*Ts.count\\(o\\) == 0 && \"Object already in set!\""); - EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 2), - "Cache != o && \"Object already in set!\""); -} -#endif -#endif - -} diff --git a/contrib/llvm/unittests/Support/Makefile b/contrib/llvm/unittests/Support/Makefile deleted file mode 100644 index 815bdd2..0000000 --- a/contrib/llvm/unittests/Support/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -##===- unittests/ADT/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 = Support -LINK_COMPONENTS := core support - -include $(LEVEL)/Makefile.config -include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/contrib/llvm/unittests/Support/MathExtrasTest.cpp b/contrib/llvm/unittests/Support/MathExtrasTest.cpp deleted file mode 100644 index 3db1f77..0000000 --- a/contrib/llvm/unittests/Support/MathExtrasTest.cpp +++ /dev/null @@ -1,104 +0,0 @@ -//===- unittests/Support/MathExtrasTest.cpp - math utils tests ------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "gtest/gtest.h" -#include "llvm/Support/MathExtras.h" - -using namespace llvm; - -namespace { - -TEST(MathExtras, isPowerOf2_32) { - EXPECT_TRUE(isPowerOf2_32(1 << 6)); - EXPECT_TRUE(isPowerOf2_32(1 << 12)); - EXPECT_FALSE(isPowerOf2_32((1 << 19) + 3)); - EXPECT_FALSE(isPowerOf2_32(0xABCDEF0)); -} - -TEST(MathExtras, isPowerOf2_64) { - EXPECT_TRUE(isPowerOf2_64(1LL << 46)); - EXPECT_TRUE(isPowerOf2_64(1LL << 12)); - EXPECT_FALSE(isPowerOf2_64((1LL << 53) + 3)); - EXPECT_FALSE(isPowerOf2_64(0xABCDEF0ABCDEF0LL)); -} - -TEST(MathExtras, ByteSwap_32) { - EXPECT_EQ(0x44332211u, ByteSwap_32(0x11223344)); - EXPECT_EQ(0xDDCCBBAAu, ByteSwap_32(0xAABBCCDD)); -} - -TEST(MathExtras, ByteSwap_64) { - EXPECT_EQ(0x8877665544332211ULL, ByteSwap_64(0x1122334455667788LL)); - EXPECT_EQ(0x1100FFEEDDCCBBAAULL, ByteSwap_64(0xAABBCCDDEEFF0011LL)); -} - -TEST(MathExtras, CountLeadingZeros_32) { - EXPECT_EQ(8u, CountLeadingZeros_32(0x00F000FF)); - EXPECT_EQ(8u, CountLeadingZeros_32(0x00F12345)); - for (unsigned i = 0; i <= 30; ++i) { - EXPECT_EQ(31 - i, CountLeadingZeros_32(1 << i)); - } -} - -TEST(MathExtras, CountLeadingZeros_64) { - EXPECT_EQ(8u, CountLeadingZeros_64(0x00F1234500F12345LL)); - EXPECT_EQ(1u, CountLeadingZeros_64(1LL << 62)); - for (unsigned i = 0; i <= 62; ++i) { - EXPECT_EQ(63 - i, CountLeadingZeros_64(1LL << i)); - } -} - -TEST(MathExtras, CountLeadingOnes_32) { - for (int i = 30; i >= 0; --i) { - // Start with all ones and unset some bit. - EXPECT_EQ(31u - i, CountLeadingOnes_32(0xFFFFFFFF ^ (1 << i))); - } -} - -TEST(MathExtras, CountLeadingOnes_64) { - for (int i = 62; i >= 0; --i) { - // Start with all ones and unset some bit. - EXPECT_EQ(63u - i, CountLeadingOnes_64(0xFFFFFFFFFFFFFFFFLL ^ (1LL << i))); - } - for (int i = 30; i >= 0; --i) { - // Start with all ones and unset some bit. - EXPECT_EQ(31u - i, CountLeadingOnes_32(0xFFFFFFFF ^ (1 << i))); - } -} - -TEST(MathExtras, FloatBits) { - static const float kValue = 5632.34; - EXPECT_FLOAT_EQ(kValue, BitsToFloat(FloatToBits(kValue))); -} - -TEST(MathExtras, DoubleBits) { - static const double kValue = 87987234.983498; - EXPECT_FLOAT_EQ(kValue, BitsToDouble(DoubleToBits(kValue))); -} - -TEST(MathExtras, MinAlign) { - EXPECT_EQ(1u, MinAlign(2, 3)); - EXPECT_EQ(2u, MinAlign(2, 4)); - EXPECT_EQ(1u, MinAlign(17, 64)); - EXPECT_EQ(256u, MinAlign(256, 512)); -} - -TEST(MathExtras, NextPowerOf2) { - EXPECT_EQ(4u, NextPowerOf2(3)); - EXPECT_EQ(16u, NextPowerOf2(15)); - EXPECT_EQ(256u, NextPowerOf2(128)); -} - -TEST(MathExtras, RoundUpToAlignment) { - EXPECT_EQ(8u, RoundUpToAlignment(5, 8)); - EXPECT_EQ(24u, RoundUpToAlignment(17, 8)); - EXPECT_EQ(0u, RoundUpToAlignment(~0LL, 8)); -} - -} diff --git a/contrib/llvm/unittests/Support/RegexTest.cpp b/contrib/llvm/unittests/Support/RegexTest.cpp deleted file mode 100644 index 65b66c3..0000000 --- a/contrib/llvm/unittests/Support/RegexTest.cpp +++ /dev/null @@ -1,94 +0,0 @@ -//===- llvm/unittest/Support/RegexTest.cpp - Regex tests --===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "gtest/gtest.h" -#include "llvm/Support/Regex.h" -#include "llvm/ADT/SmallVector.h" -#include <cstring> - -using namespace llvm; -namespace { - -class RegexTest : public ::testing::Test { -}; - -TEST_F(RegexTest, Basics) { - Regex r1("^[0-9]+$"); - EXPECT_TRUE(r1.match("916")); - EXPECT_TRUE(r1.match("9")); - EXPECT_FALSE(r1.match("9a")); - - SmallVector<StringRef, 1> Matches; - Regex r2("[0-9]+"); - EXPECT_TRUE(r2.match("aa216b", &Matches)); - EXPECT_EQ(1u, Matches.size()); - EXPECT_EQ("216", Matches[0].str()); - - Regex r3("[0-9]+([a-f])?:([0-9]+)"); - EXPECT_TRUE(r3.match("9a:513b", &Matches)); - EXPECT_EQ(3u, Matches.size()); - EXPECT_EQ("9a:513", Matches[0].str()); - EXPECT_EQ("a", Matches[1].str()); - EXPECT_EQ("513", Matches[2].str()); - - EXPECT_TRUE(r3.match("9:513b", &Matches)); - EXPECT_EQ(3u, Matches.size()); - EXPECT_EQ("9:513", Matches[0].str()); - EXPECT_EQ("", Matches[1].str()); - EXPECT_EQ("513", Matches[2].str()); - - Regex r4("a[^b]+b"); - std::string String="axxb"; - String[2] = '\0'; - EXPECT_FALSE(r4.match("abb")); - EXPECT_TRUE(r4.match(String, &Matches)); - EXPECT_EQ(1u, Matches.size()); - EXPECT_EQ(String, Matches[0].str()); - - - std::string NulPattern="X[0-9]+X([a-f])?:([0-9]+)"; - String="YX99a:513b"; - NulPattern[7] = '\0'; - Regex r5(NulPattern); - EXPECT_FALSE(r5.match(String)); - EXPECT_FALSE(r5.match("X9")); - String[3]='\0'; - EXPECT_TRUE(r5.match(String)); -} - -TEST_F(RegexTest, Substitution) { - std::string Error; - - EXPECT_EQ("aNUMber", Regex("[0-9]+").sub("NUM", "a1234ber")); - - // Standard Escapes - EXPECT_EQ("a\\ber", Regex("[0-9]+").sub("\\\\", "a1234ber", &Error)); - EXPECT_EQ(Error, ""); - EXPECT_EQ("a\nber", Regex("[0-9]+").sub("\\n", "a1234ber", &Error)); - EXPECT_EQ(Error, ""); - EXPECT_EQ("a\tber", Regex("[0-9]+").sub("\\t", "a1234ber", &Error)); - EXPECT_EQ(Error, ""); - EXPECT_EQ("ajber", Regex("[0-9]+").sub("\\j", "a1234ber", &Error)); - EXPECT_EQ(Error, ""); - - EXPECT_EQ("aber", Regex("[0-9]+").sub("\\", "a1234ber", &Error)); - EXPECT_EQ(Error, "replacement string contained trailing backslash"); - - // Backreferences - EXPECT_EQ("aa1234bber", Regex("a[0-9]+b").sub("a\\0b", "a1234ber", &Error)); - EXPECT_EQ(Error, ""); - - EXPECT_EQ("a1234ber", Regex("a([0-9]+)b").sub("a\\1b", "a1234ber", &Error)); - EXPECT_EQ(Error, ""); - - EXPECT_EQ("aber", Regex("a[0-9]+b").sub("a\\100b", "a1234ber", &Error)); - EXPECT_EQ(Error, "invalid backreference string '100'"); -} - -} diff --git a/contrib/llvm/unittests/Support/System.cpp b/contrib/llvm/unittests/Support/System.cpp deleted file mode 100644 index b3dd17d..0000000 --- a/contrib/llvm/unittests/Support/System.cpp +++ /dev/null @@ -1,16 +0,0 @@ -//===- llvm/unittest/Support/System.cpp - System tests --===// -#include "gtest/gtest.h" -#include "llvm/System/TimeValue.h" -#include <time.h> - -using namespace llvm; -namespace { -class SystemTest : public ::testing::Test { -}; - -TEST_F(SystemTest, TimeValue) { - sys::TimeValue now = sys::TimeValue::now(); - time_t now_t = time(NULL); - EXPECT_TRUE(abs(now_t - now.toEpochTime()) < 2); -} -} diff --git a/contrib/llvm/unittests/Support/TypeBuilderTest.cpp b/contrib/llvm/unittests/Support/TypeBuilderTest.cpp deleted file mode 100644 index e805827..0000000 --- a/contrib/llvm/unittests/Support/TypeBuilderTest.cpp +++ /dev/null @@ -1,253 +0,0 @@ -//===- llvm/unittest/Support/TypeBuilderTest.cpp - TypeBuilder 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/TypeBuilder.h" -#include "llvm/LLVMContext.h" - -#include "gtest/gtest.h" - -using namespace llvm; - -namespace { - -TEST(TypeBuilderTest, Void) { - EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder<void, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder<void, false>::get(getGlobalContext()))); - // Special cases for C compatibility: - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder<void*, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder<const void*, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder<volatile void*, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder<const volatile void*, false>::get( - getGlobalContext()))); -} - -TEST(TypeBuilderTest, HostIntegers) { - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<int8_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<uint8_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder<int16_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder<uint16_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder<int32_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder<uint32_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder<int64_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder<uint64_t, false>::get(getGlobalContext()))); - - EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(size_t) * CHAR_BIT), - (TypeBuilder<size_t, false>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(ptrdiff_t) * CHAR_BIT), - (TypeBuilder<ptrdiff_t, false>::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, CrossCompilableIntegers) { - EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder<types::i<1>, true>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder<types::i<1>, false>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder<types::i<72>, true>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder<types::i<72>, false>::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, Float) { - EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder<float, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder<double, false>::get(getGlobalContext()))); - // long double isn't supported yet. - EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder<types::ieee_float, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder<types::ieee_float, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder<types::ieee_double, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder<types::ieee_double, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder<types::x86_fp80, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder<types::x86_fp80, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder<types::fp128, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder<types::fp128, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder<types::ppc_fp128, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder<types::ppc_fp128, false>::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, Derived) { - EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())), - (TypeBuilder<int8_t**, false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), - (TypeBuilder<int8_t[7], false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), - (TypeBuilder<int8_t[], false>::get(getGlobalContext()))); - - EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())), - (TypeBuilder<types::i<8>**, false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), - (TypeBuilder<types::i<8>[7], false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), - (TypeBuilder<types::i<8>[], false>::get(getGlobalContext()))); - - EXPECT_EQ(PointerType::getUnqual(Type::getInt8PtrTy(getGlobalContext())), - (TypeBuilder<types::i<8>**, true>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), - (TypeBuilder<types::i<8>[7], true>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), - (TypeBuilder<types::i<8>[], true>::get(getGlobalContext()))); - - - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder<const int8_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder<volatile int8_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder<const volatile int8_t, false>::get(getGlobalContext()))); - - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder<const types::i<8>, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder<volatile types::i<8>, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder<const volatile types::i<8>, false>::get(getGlobalContext()))); - - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder<const types::i<8>, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder<volatile types::i<8>, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), - (TypeBuilder<const volatile types::i<8>, true>::get(getGlobalContext()))); - - EXPECT_EQ(Type::getInt8PtrTy(getGlobalContext()), - (TypeBuilder<const volatile int8_t*const volatile, false>::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, Functions) { - std::vector<const Type*> params; - EXPECT_EQ(FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false), - (TypeBuilder<void(), true>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder<int8_t(...), false>::get(getGlobalContext()))); - params.push_back(TypeBuilder<int32_t*, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder<int8_t(const int32_t*), false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder<int8_t(const int32_t*, ...), false>::get(getGlobalContext()))); - params.push_back(TypeBuilder<char*, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder<int8_t(int32_t*, void*), false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder<int8_t(int32_t*, char*, ...), false>::get(getGlobalContext()))); - params.push_back(TypeBuilder<char, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder<int8_t(int32_t*, void*, char), false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder<int8_t(int32_t*, char*, char, ...), false>::get(getGlobalContext()))); - params.push_back(TypeBuilder<char, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder<int8_t(int32_t*, void*, char, char), false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder<int8_t(int32_t*, char*, char, char, ...), - false>::get(getGlobalContext()))); - params.push_back(TypeBuilder<char, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), - (TypeBuilder<int8_t(int32_t*, void*, char, char, char), - false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), - (TypeBuilder<int8_t(int32_t*, char*, char, char, char, ...), - false>::get(getGlobalContext()))); -} - -TEST(TypeBuilderTest, Context) { - // We used to cache TypeBuilder results in static local variables. This - // produced the same type for different contexts, which of course broke - // things. - LLVMContext context1; - EXPECT_EQ(&context1, - &(TypeBuilder<types::i<1>, true>::get(context1))->getContext()); - LLVMContext context2; - EXPECT_EQ(&context2, - &(TypeBuilder<types::i<1>, true>::get(context2))->getContext()); -} - -class MyType { - int a; - int *b; - void *array[1]; -}; - -class MyPortableType { - int32_t a; - int32_t *b; - void *array[1]; -}; - -} // anonymous namespace - -namespace llvm { -template<bool cross> class TypeBuilder<MyType, cross> { -public: - static const StructType *get(LLVMContext &Context) { - // Using the static result variable ensures that the type is - // only looked up once. - std::vector<const Type*> st; - st.push_back(TypeBuilder<int, cross>::get(Context)); - st.push_back(TypeBuilder<int*, cross>::get(Context)); - st.push_back(TypeBuilder<void*[], cross>::get(Context)); - static const StructType *const result = StructType::get(Context, st); - return result; - } - - // You may find this a convenient place to put some constants - // to help with getelementptr. They don't have any effect on - // the operation of TypeBuilder. - enum Fields { - FIELD_A, - FIELD_B, - FIELD_ARRAY - }; -}; - -template<bool cross> class TypeBuilder<MyPortableType, cross> { -public: - static const StructType *get(LLVMContext &Context) { - // Using the static result variable ensures that the type is - // only looked up once. - std::vector<const Type*> st; - st.push_back(TypeBuilder<types::i<32>, cross>::get(Context)); - st.push_back(TypeBuilder<types::i<32>*, cross>::get(Context)); - st.push_back(TypeBuilder<types::i<8>*[], cross>::get(Context)); - static const StructType *const result = StructType::get(Context, st); - return result; - } - - // You may find this a convenient place to put some constants - // to help with getelementptr. They don't have any effect on - // the operation of TypeBuilder. - enum Fields { - FIELD_A, - FIELD_B, - FIELD_ARRAY - }; -}; -} // namespace llvm -namespace { - -TEST(TypeBuilderTest, Extensions) { - EXPECT_EQ(PointerType::getUnqual(StructType::get(getGlobalContext(), - TypeBuilder<int, false>::get(getGlobalContext()), - TypeBuilder<int*, false>::get(getGlobalContext()), - TypeBuilder<void*[], false>::get(getGlobalContext()), - NULL)), - (TypeBuilder<MyType*, false>::get(getGlobalContext()))); - EXPECT_EQ(PointerType::getUnqual(StructType::get(getGlobalContext(), - TypeBuilder<types::i<32>, false>::get(getGlobalContext()), - TypeBuilder<types::i<32>*, false>::get(getGlobalContext()), - TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()), - NULL)), - (TypeBuilder<MyPortableType*, false>::get(getGlobalContext()))); - EXPECT_EQ(PointerType::getUnqual(StructType::get(getGlobalContext(), - TypeBuilder<types::i<32>, false>::get(getGlobalContext()), - TypeBuilder<types::i<32>*, false>::get(getGlobalContext()), - TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()), - NULL)), - (TypeBuilder<MyPortableType*, true>::get(getGlobalContext()))); -} - -} // anonymous namespace diff --git a/contrib/llvm/unittests/Support/ValueHandleTest.cpp b/contrib/llvm/unittests/Support/ValueHandleTest.cpp deleted file mode 100644 index 6a6528f..0000000 --- a/contrib/llvm/unittests/Support/ValueHandleTest.cpp +++ /dev/null @@ -1,412 +0,0 @@ -//===- llvm/unittest/Support/ValueHandleTest.cpp - ValueHandle 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/ValueHandle.h" - -#include "llvm/Constants.h" -#include "llvm/Instructions.h" -#include "llvm/LLVMContext.h" -#include "llvm/ADT/OwningPtr.h" - -#include "gtest/gtest.h" - -#include <memory> - -using namespace llvm; - -namespace { - -class ValueHandle : public testing::Test { -protected: - Constant *ConstantV; - std::auto_ptr<BitCastInst> BitcastV; - - ValueHandle() : - ConstantV(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 0)), - BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(getGlobalContext()))) { - } -}; - -class ConcreteCallbackVH : public CallbackVH { -public: - ConcreteCallbackVH() : CallbackVH() {} - ConcreteCallbackVH(Value *V) : CallbackVH(V) {} -}; - -TEST_F(ValueHandle, WeakVH_BasicOperation) { - WeakVH WVH(BitcastV.get()); - EXPECT_EQ(BitcastV.get(), WVH); - WVH = ConstantV; - EXPECT_EQ(ConstantV, WVH); - - // Make sure I can call a method on the underlying Value. It - // doesn't matter which method. - EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), WVH->getType()); - EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*WVH).getType()); -} - -TEST_F(ValueHandle, WeakVH_Comparisons) { - WeakVH BitcastWVH(BitcastV.get()); - WeakVH ConstantWVH(ConstantV); - - EXPECT_TRUE(BitcastWVH == BitcastWVH); - EXPECT_TRUE(BitcastV.get() == BitcastWVH); - EXPECT_TRUE(BitcastWVH == BitcastV.get()); - EXPECT_FALSE(BitcastWVH == ConstantWVH); - - EXPECT_TRUE(BitcastWVH != ConstantWVH); - EXPECT_TRUE(BitcastV.get() != ConstantWVH); - EXPECT_TRUE(BitcastWVH != ConstantV); - EXPECT_FALSE(BitcastWVH != BitcastWVH); - - // Cast to Value* so comparisons work. - Value *BV = BitcastV.get(); - Value *CV = ConstantV; - EXPECT_EQ(BV < CV, BitcastWVH < ConstantWVH); - EXPECT_EQ(BV <= CV, BitcastWVH <= ConstantWVH); - EXPECT_EQ(BV > CV, BitcastWVH > ConstantWVH); - EXPECT_EQ(BV >= CV, BitcastWVH >= ConstantWVH); - - EXPECT_EQ(BV < CV, BitcastV.get() < ConstantWVH); - EXPECT_EQ(BV <= CV, BitcastV.get() <= ConstantWVH); - EXPECT_EQ(BV > CV, BitcastV.get() > ConstantWVH); - EXPECT_EQ(BV >= CV, BitcastV.get() >= ConstantWVH); - - EXPECT_EQ(BV < CV, BitcastWVH < ConstantV); - EXPECT_EQ(BV <= CV, BitcastWVH <= ConstantV); - EXPECT_EQ(BV > CV, BitcastWVH > ConstantV); - EXPECT_EQ(BV >= CV, BitcastWVH >= ConstantV); -} - -TEST_F(ValueHandle, WeakVH_FollowsRAUW) { - WeakVH WVH(BitcastV.get()); - WeakVH WVH_Copy(WVH); - WeakVH WVH_Recreated(BitcastV.get()); - BitcastV->replaceAllUsesWith(ConstantV); - EXPECT_EQ(ConstantV, WVH); - EXPECT_EQ(ConstantV, WVH_Copy); - EXPECT_EQ(ConstantV, WVH_Recreated); -} - -TEST_F(ValueHandle, WeakVH_NullOnDeletion) { - WeakVH WVH(BitcastV.get()); - WeakVH WVH_Copy(WVH); - WeakVH WVH_Recreated(BitcastV.get()); - BitcastV.reset(); - Value *null_value = NULL; - EXPECT_EQ(null_value, WVH); - EXPECT_EQ(null_value, WVH_Copy); - EXPECT_EQ(null_value, WVH_Recreated); -} - - -TEST_F(ValueHandle, AssertingVH_BasicOperation) { - AssertingVH<CastInst> AVH(BitcastV.get()); - CastInst *implicit_to_exact_type = AVH; - implicit_to_exact_type = implicit_to_exact_type; // Avoid warning. - - AssertingVH<Value> GenericAVH(BitcastV.get()); - EXPECT_EQ(BitcastV.get(), GenericAVH); - GenericAVH = ConstantV; - EXPECT_EQ(ConstantV, GenericAVH); - - // Make sure I can call a method on the underlying CastInst. It - // doesn't matter which method. - EXPECT_FALSE(AVH->mayWriteToMemory()); - EXPECT_FALSE((*AVH).mayWriteToMemory()); -} - -TEST_F(ValueHandle, AssertingVH_Const) { - const CastInst *ConstBitcast = BitcastV.get(); - AssertingVH<const CastInst> AVH(ConstBitcast); - const CastInst *implicit_to_exact_type = AVH; - implicit_to_exact_type = implicit_to_exact_type; // Avoid warning. -} - -TEST_F(ValueHandle, AssertingVH_Comparisons) { - AssertingVH<Value> BitcastAVH(BitcastV.get()); - AssertingVH<Value> ConstantAVH(ConstantV); - - EXPECT_TRUE(BitcastAVH == BitcastAVH); - EXPECT_TRUE(BitcastV.get() == BitcastAVH); - EXPECT_TRUE(BitcastAVH == BitcastV.get()); - EXPECT_FALSE(BitcastAVH == ConstantAVH); - - EXPECT_TRUE(BitcastAVH != ConstantAVH); - EXPECT_TRUE(BitcastV.get() != ConstantAVH); - EXPECT_TRUE(BitcastAVH != ConstantV); - EXPECT_FALSE(BitcastAVH != BitcastAVH); - - // Cast to Value* so comparisons work. - Value *BV = BitcastV.get(); - Value *CV = ConstantV; - EXPECT_EQ(BV < CV, BitcastAVH < ConstantAVH); - EXPECT_EQ(BV <= CV, BitcastAVH <= ConstantAVH); - EXPECT_EQ(BV > CV, BitcastAVH > ConstantAVH); - EXPECT_EQ(BV >= CV, BitcastAVH >= ConstantAVH); - - EXPECT_EQ(BV < CV, BitcastV.get() < ConstantAVH); - EXPECT_EQ(BV <= CV, BitcastV.get() <= ConstantAVH); - EXPECT_EQ(BV > CV, BitcastV.get() > ConstantAVH); - EXPECT_EQ(BV >= CV, BitcastV.get() >= ConstantAVH); - - EXPECT_EQ(BV < CV, BitcastAVH < ConstantV); - EXPECT_EQ(BV <= CV, BitcastAVH <= ConstantV); - EXPECT_EQ(BV > CV, BitcastAVH > ConstantV); - EXPECT_EQ(BV >= CV, BitcastAVH >= ConstantV); -} - -TEST_F(ValueHandle, AssertingVH_DoesNotFollowRAUW) { - AssertingVH<Value> AVH(BitcastV.get()); - BitcastV->replaceAllUsesWith(ConstantV); - EXPECT_EQ(BitcastV.get(), AVH); -} - -#ifdef NDEBUG - -TEST_F(ValueHandle, AssertingVH_ReducesToPointer) { - EXPECT_EQ(sizeof(CastInst *), sizeof(AssertingVH<CastInst>)); -} - -#else // !NDEBUG - -#ifdef GTEST_HAS_DEATH_TEST - -TEST_F(ValueHandle, AssertingVH_Asserts) { - AssertingVH<Value> AVH(BitcastV.get()); - EXPECT_DEATH({BitcastV.reset();}, - "An asserting value handle still pointed to this value!"); - AssertingVH<Value> Copy(AVH); - AVH = NULL; - EXPECT_DEATH({BitcastV.reset();}, - "An asserting value handle still pointed to this value!"); - Copy = NULL; - BitcastV.reset(); -} - -#endif // GTEST_HAS_DEATH_TEST - -#endif // NDEBUG - -TEST_F(ValueHandle, CallbackVH_BasicOperation) { - ConcreteCallbackVH CVH(BitcastV.get()); - EXPECT_EQ(BitcastV.get(), CVH); - CVH = ConstantV; - EXPECT_EQ(ConstantV, CVH); - - // Make sure I can call a method on the underlying Value. It - // doesn't matter which method. - EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), CVH->getType()); - EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*CVH).getType()); -} - -TEST_F(ValueHandle, CallbackVH_Comparisons) { - ConcreteCallbackVH BitcastCVH(BitcastV.get()); - ConcreteCallbackVH ConstantCVH(ConstantV); - - EXPECT_TRUE(BitcastCVH == BitcastCVH); - EXPECT_TRUE(BitcastV.get() == BitcastCVH); - EXPECT_TRUE(BitcastCVH == BitcastV.get()); - EXPECT_FALSE(BitcastCVH == ConstantCVH); - - EXPECT_TRUE(BitcastCVH != ConstantCVH); - EXPECT_TRUE(BitcastV.get() != ConstantCVH); - EXPECT_TRUE(BitcastCVH != ConstantV); - EXPECT_FALSE(BitcastCVH != BitcastCVH); - - // Cast to Value* so comparisons work. - Value *BV = BitcastV.get(); - Value *CV = ConstantV; - EXPECT_EQ(BV < CV, BitcastCVH < ConstantCVH); - EXPECT_EQ(BV <= CV, BitcastCVH <= ConstantCVH); - EXPECT_EQ(BV > CV, BitcastCVH > ConstantCVH); - EXPECT_EQ(BV >= CV, BitcastCVH >= ConstantCVH); - - EXPECT_EQ(BV < CV, BitcastV.get() < ConstantCVH); - EXPECT_EQ(BV <= CV, BitcastV.get() <= ConstantCVH); - EXPECT_EQ(BV > CV, BitcastV.get() > ConstantCVH); - EXPECT_EQ(BV >= CV, BitcastV.get() >= ConstantCVH); - - EXPECT_EQ(BV < CV, BitcastCVH < ConstantV); - EXPECT_EQ(BV <= CV, BitcastCVH <= ConstantV); - EXPECT_EQ(BV > CV, BitcastCVH > ConstantV); - EXPECT_EQ(BV >= CV, BitcastCVH >= ConstantV); -} - -TEST_F(ValueHandle, CallbackVH_CallbackOnDeletion) { - class RecordingVH : public CallbackVH { - public: - int DeletedCalls; - int AURWCalls; - - RecordingVH() : DeletedCalls(0), AURWCalls(0) {} - RecordingVH(Value *V) : CallbackVH(V), DeletedCalls(0), AURWCalls(0) {} - - private: - virtual void deleted() { DeletedCalls++; CallbackVH::deleted(); } - virtual void allUsesReplacedWith(Value *) { AURWCalls++; } - }; - - RecordingVH RVH; - RVH = BitcastV.get(); - EXPECT_EQ(0, RVH.DeletedCalls); - EXPECT_EQ(0, RVH.AURWCalls); - BitcastV.reset(); - EXPECT_EQ(1, RVH.DeletedCalls); - EXPECT_EQ(0, RVH.AURWCalls); -} - -TEST_F(ValueHandle, CallbackVH_CallbackOnRAUW) { - class RecordingVH : public CallbackVH { - public: - int DeletedCalls; - Value *AURWArgument; - - RecordingVH() : DeletedCalls(0), AURWArgument(NULL) {} - RecordingVH(Value *V) - : CallbackVH(V), DeletedCalls(0), AURWArgument(NULL) {} - - private: - virtual void deleted() { DeletedCalls++; CallbackVH::deleted(); } - virtual void allUsesReplacedWith(Value *new_value) { - EXPECT_EQ(NULL, AURWArgument); - AURWArgument = new_value; - } - }; - - RecordingVH RVH; - RVH = BitcastV.get(); - EXPECT_EQ(0, RVH.DeletedCalls); - EXPECT_EQ(NULL, RVH.AURWArgument); - BitcastV->replaceAllUsesWith(ConstantV); - EXPECT_EQ(0, RVH.DeletedCalls); - EXPECT_EQ(ConstantV, RVH.AURWArgument); -} - -TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) { - class RecoveringVH : public CallbackVH { - public: - int DeletedCalls; - Value *AURWArgument; - LLVMContext *Context; - - RecoveringVH() : DeletedCalls(0), AURWArgument(NULL), - Context(&getGlobalContext()) {} - RecoveringVH(Value *V) - : CallbackVH(V), DeletedCalls(0), AURWArgument(NULL), - Context(&getGlobalContext()) {} - - private: - virtual void deleted() { - getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::getInt32Ty(getGlobalContext()))); - setValPtr(NULL); - } - virtual void allUsesReplacedWith(Value *new_value) { - ASSERT_TRUE(NULL != getValPtr()); - EXPECT_EQ(1U, getValPtr()->getNumUses()); - EXPECT_EQ(NULL, AURWArgument); - AURWArgument = new_value; - } - }; - - // Normally, if a value has uses, deleting it will crash. However, we can use - // a CallbackVH to remove the uses before the check for no uses. - RecoveringVH RVH; - RVH = BitcastV.get(); - std::auto_ptr<BinaryOperator> BitcastUser( - BinaryOperator::CreateAdd(RVH, - Constant::getNullValue(Type::getInt32Ty(getGlobalContext())))); - EXPECT_EQ(BitcastV.get(), BitcastUser->getOperand(0)); - BitcastV.reset(); // Would crash without the ValueHandler. - EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())), RVH.AURWArgument); - EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())), - BitcastUser->getOperand(0)); -} - -TEST_F(ValueHandle, DestroyingOtherVHOnSameValueDoesntBreakIteration) { - // When a CallbackVH modifies other ValueHandles in its callbacks, - // that shouldn't interfere with non-modified ValueHandles receiving - // their appropriate callbacks. - // - // We create the active CallbackVH in the middle of a palindromic - // arrangement of other VHs so that the bad behavior would be - // triggered in whichever order callbacks run. - - class DestroyingVH : public CallbackVH { - public: - OwningPtr<WeakVH> ToClear[2]; - DestroyingVH(Value *V) { - ToClear[0].reset(new WeakVH(V)); - setValPtr(V); - ToClear[1].reset(new WeakVH(V)); - } - virtual void deleted() { - ToClear[0].reset(); - ToClear[1].reset(); - CallbackVH::deleted(); - } - virtual void allUsesReplacedWith(Value *) { - ToClear[0].reset(); - ToClear[1].reset(); - } - }; - - { - WeakVH ShouldBeVisited1(BitcastV.get()); - DestroyingVH C(BitcastV.get()); - WeakVH ShouldBeVisited2(BitcastV.get()); - - BitcastV->replaceAllUsesWith(ConstantV); - EXPECT_EQ(ConstantV, static_cast<Value*>(ShouldBeVisited1)); - EXPECT_EQ(ConstantV, static_cast<Value*>(ShouldBeVisited2)); - } - - { - WeakVH ShouldBeVisited1(BitcastV.get()); - DestroyingVH C(BitcastV.get()); - WeakVH ShouldBeVisited2(BitcastV.get()); - - BitcastV.reset(); - EXPECT_EQ(NULL, static_cast<Value*>(ShouldBeVisited1)); - EXPECT_EQ(NULL, static_cast<Value*>(ShouldBeVisited2)); - } -} - -TEST_F(ValueHandle, AssertingVHCheckedLast) { - // If a CallbackVH exists to clear out a group of AssertingVHs on - // Value deletion, the CallbackVH should get a chance to do so - // before the AssertingVHs assert. - - class ClearingVH : public CallbackVH { - public: - AssertingVH<Value> *ToClear[2]; - ClearingVH(Value *V, - AssertingVH<Value> &A0, AssertingVH<Value> &A1) - : CallbackVH(V) { - ToClear[0] = &A0; - ToClear[1] = &A1; - } - - virtual void deleted() { - *ToClear[0] = 0; - *ToClear[1] = 0; - CallbackVH::deleted(); - } - }; - - AssertingVH<Value> A1, A2; - A1 = BitcastV.get(); - ClearingVH C(BitcastV.get(), A1, A2); - A2 = BitcastV.get(); - // C.deleted() should run first, clearing the two AssertingVHs, - // which should prevent them from asserting. - BitcastV.reset(); -} - -} diff --git a/contrib/llvm/unittests/Support/raw_ostream_test.cpp b/contrib/llvm/unittests/Support/raw_ostream_test.cpp deleted file mode 100644 index 2b797b4..0000000 --- a/contrib/llvm/unittests/Support/raw_ostream_test.cpp +++ /dev/null @@ -1,146 +0,0 @@ -//===- llvm/unittest/Support/raw_ostream_test.cpp - raw_ostream tests -----===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "gtest/gtest.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/Support/Format.h" -#include "llvm/Support/raw_ostream.h" - -using namespace llvm; - -namespace { - -template<typename T> std::string printToString(const T &Value) { - std::string res; - llvm::raw_string_ostream(res) << Value; - return res; -} - -/// printToString - Print the given value to a stream which only has \arg -/// BytesLeftInBuffer bytes left in the buffer. This is useful for testing edge -/// cases in the buffer handling logic. -template<typename T> std::string printToString(const T &Value, - unsigned BytesLeftInBuffer) { - // FIXME: This is relying on internal knowledge of how raw_ostream works to - // get the buffer position right. - SmallString<256> SVec; - assert(BytesLeftInBuffer < 256 && "Invalid buffer count!"); - llvm::raw_svector_ostream OS(SVec); - unsigned StartIndex = 256 - BytesLeftInBuffer; - for (unsigned i = 0; i != StartIndex; ++i) - OS << '?'; - OS << Value; - return OS.str().substr(StartIndex); -} - -template<typename T> std::string printToStringUnbuffered(const T &Value) { - std::string res; - llvm::raw_string_ostream OS(res); - OS.SetUnbuffered(); - OS << Value; - return res; -} - -TEST(raw_ostreamTest, Types_Buffered) { - // Char - EXPECT_EQ("c", printToString('c')); - - // String - EXPECT_EQ("hello", printToString("hello")); - EXPECT_EQ("hello", printToString(std::string("hello"))); - - // Int - EXPECT_EQ("0", printToString(0)); - EXPECT_EQ("2425", printToString(2425)); - EXPECT_EQ("-2425", printToString(-2425)); - - // Long long - EXPECT_EQ("0", printToString(0LL)); - EXPECT_EQ("257257257235709", printToString(257257257235709LL)); - EXPECT_EQ("-257257257235709", printToString(-257257257235709LL)); - - // Double - EXPECT_EQ("1.100000e+00", printToString(1.1)); - - // void* - EXPECT_EQ("0x0", printToString((void*) 0)); - EXPECT_EQ("0xbeef", printToString((void*) 0xbeef)); - EXPECT_EQ("0xdeadbeef", printToString((void*) 0xdeadbeef)); - - // Min and max. - EXPECT_EQ("18446744073709551615", printToString(UINT64_MAX)); - EXPECT_EQ("-9223372036854775808", printToString(INT64_MIN)); -} - -TEST(raw_ostreamTest, Types_Unbuffered) { - // Char - EXPECT_EQ("c", printToStringUnbuffered('c')); - - // String - EXPECT_EQ("hello", printToStringUnbuffered("hello")); - EXPECT_EQ("hello", printToStringUnbuffered(std::string("hello"))); - - // Int - EXPECT_EQ("0", printToStringUnbuffered(0)); - EXPECT_EQ("2425", printToStringUnbuffered(2425)); - EXPECT_EQ("-2425", printToStringUnbuffered(-2425)); - - // Long long - EXPECT_EQ("0", printToStringUnbuffered(0LL)); - EXPECT_EQ("257257257235709", printToStringUnbuffered(257257257235709LL)); - EXPECT_EQ("-257257257235709", printToStringUnbuffered(-257257257235709LL)); - - // Double - EXPECT_EQ("1.100000e+00", printToStringUnbuffered(1.1)); - - // void* - EXPECT_EQ("0x0", printToStringUnbuffered((void*) 0)); - EXPECT_EQ("0xbeef", printToStringUnbuffered((void*) 0xbeef)); - EXPECT_EQ("0xdeadbeef", printToStringUnbuffered((void*) 0xdeadbeef)); - - // Min and max. - EXPECT_EQ("18446744073709551615", printToStringUnbuffered(UINT64_MAX)); - EXPECT_EQ("-9223372036854775808", printToStringUnbuffered(INT64_MIN)); -} - -TEST(raw_ostreamTest, BufferEdge) { - EXPECT_EQ("1.20", printToString(format("%.2f", 1.2), 1)); - EXPECT_EQ("1.20", printToString(format("%.2f", 1.2), 2)); - EXPECT_EQ("1.20", printToString(format("%.2f", 1.2), 3)); - EXPECT_EQ("1.20", printToString(format("%.2f", 1.2), 4)); - EXPECT_EQ("1.20", printToString(format("%.2f", 1.2), 10)); -} - -TEST(raw_ostreamTest, TinyBuffer) { - std::string Str; - raw_string_ostream OS(Str); - OS.SetBufferSize(1); - OS << "hello"; - OS << 1; - OS << 'w' << 'o' << 'r' << 'l' << 'd'; - EXPECT_EQ("hello1world", OS.str()); -} - -TEST(raw_ostreamTest, WriteEscaped) { - std::string Str; - - Str = ""; - raw_string_ostream(Str).write_escaped("hi"); - EXPECT_EQ("hi", Str); - - Str = ""; - raw_string_ostream(Str).write_escaped("\\\t\n\""); - EXPECT_EQ("\\\\\\t\\n\\\"", Str); - - Str = ""; - raw_string_ostream(Str).write_escaped("\1\10\200"); - EXPECT_EQ("\\001\\010\\200", Str); -} - -} |