diff options
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/APFloatTest.cpp | 49 | ||||
-rw-r--r-- | unittests/ADT/APIntTest.cpp | 46 | ||||
-rw-r--r-- | unittests/ADT/PackedVectorTest.cpp | 115 | ||||
-rw-r--r-- | unittests/ADT/SmallVectorTest.cpp | 48 | ||||
-rw-r--r-- | unittests/ADT/StringMapTest.cpp | 6 | ||||
-rw-r--r-- | unittests/Analysis/ScalarEvolutionTest.cpp | 2 | ||||
-rw-r--r-- | unittests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp | 3 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITTest.cpp | 4 | ||||
-rw-r--r-- | unittests/Support/ConstantRangeTest.cpp | 2 | ||||
-rw-r--r-- | unittests/Support/TypeBuilderTest.cpp | 13 | ||||
-rw-r--r-- | unittests/VMCore/DerivedTypesTest.cpp | 88 | ||||
-rw-r--r-- | unittests/VMCore/PassManagerTest.cpp | 4 |
13 files changed, 257 insertions, 125 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp index 5f05b86..08ac2a0 100644 --- a/unittests/ADT/APFloatTest.cpp +++ b/unittests/ADT/APFloatTest.cpp @@ -12,6 +12,7 @@ #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" #include "llvm/ADT/APFloat.h" +#include "llvm/ADT/APSInt.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -344,6 +345,54 @@ TEST(APFloatTest, toString) { ASSERT_EQ("8.731834E+2", convertToString(873.1834, 0, 0)); } +TEST(APFloatTest, toInteger) { + bool isExact = false; + APSInt result(5, /*isUnsigned=*/true); + + EXPECT_EQ(APFloat::opOK, + APFloat(APFloat::IEEEdouble, "10") + .convertToInteger(result, APFloat::rmTowardZero, &isExact)); + EXPECT_TRUE(isExact); + EXPECT_EQ(APSInt(APInt(5, 10), true), result); + + EXPECT_EQ(APFloat::opInvalidOp, + APFloat(APFloat::IEEEdouble, "-10") + .convertToInteger(result, APFloat::rmTowardZero, &isExact)); + EXPECT_FALSE(isExact); + EXPECT_EQ(APSInt::getMinValue(5, true), result); + + EXPECT_EQ(APFloat::opInvalidOp, + APFloat(APFloat::IEEEdouble, "32") + .convertToInteger(result, APFloat::rmTowardZero, &isExact)); + EXPECT_FALSE(isExact); + EXPECT_EQ(APSInt::getMaxValue(5, true), result); + + EXPECT_EQ(APFloat::opInexact, + APFloat(APFloat::IEEEdouble, "7.9") + .convertToInteger(result, APFloat::rmTowardZero, &isExact)); + EXPECT_FALSE(isExact); + EXPECT_EQ(APSInt(APInt(5, 7), true), result); + + result.setIsUnsigned(false); + EXPECT_EQ(APFloat::opOK, + APFloat(APFloat::IEEEdouble, "-10") + .convertToInteger(result, APFloat::rmTowardZero, &isExact)); + EXPECT_TRUE(isExact); + EXPECT_EQ(APSInt(APInt(5, -10, true), false), result); + + EXPECT_EQ(APFloat::opInvalidOp, + APFloat(APFloat::IEEEdouble, "-17") + .convertToInteger(result, APFloat::rmTowardZero, &isExact)); + EXPECT_FALSE(isExact); + EXPECT_EQ(APSInt::getMinValue(5, false), result); + + EXPECT_EQ(APFloat::opInvalidOp, + APFloat(APFloat::IEEEdouble, "16") + .convertToInteger(result, APFloat::rmTowardZero, &isExact)); + EXPECT_FALSE(isExact); + EXPECT_EQ(APSInt::getMaxValue(5, false), result); +} + static APInt nanbits(const fltSemantics &Sem, bool SNaN, bool Negative, uint64_t fill) { APInt apfill(64, fill); diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp index dbd0cb7..1f78cd3 100644 --- a/unittests/ADT/APIntTest.cpp +++ b/unittests/ADT/APIntTest.cpp @@ -320,6 +320,52 @@ TEST(APIntTest, StringBitsNeeded16) { EXPECT_EQ(9U, APInt::getBitsNeeded("-20", 16)); } +TEST(APIntTest, toString) { + SmallString<16> S; + bool isSigned; + + APInt(8, 0).toString(S, 2, true, true); + EXPECT_EQ(S.str().str(), "0b0"); + S.clear(); + APInt(8, 0).toString(S, 8, true, true); + EXPECT_EQ(S.str().str(), "00"); + S.clear(); + APInt(8, 0).toString(S, 10, true, true); + EXPECT_EQ(S.str().str(), "0"); + S.clear(); + APInt(8, 0).toString(S, 16, true, true); + EXPECT_EQ(S.str().str(), "0x0"); + S.clear(); + + isSigned = false; + APInt(8, 255, isSigned).toString(S, 2, isSigned, true); + EXPECT_EQ(S.str().str(), "0b11111111"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 8, isSigned, true); + EXPECT_EQ(S.str().str(), "0377"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 10, isSigned, true); + EXPECT_EQ(S.str().str(), "255"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 16, isSigned, true); + EXPECT_EQ(S.str().str(), "0xFF"); + S.clear(); + + isSigned = true; + APInt(8, 255, isSigned).toString(S, 2, isSigned, true); + EXPECT_EQ(S.str().str(), "-0b1"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 8, isSigned, true); + EXPECT_EQ(S.str().str(), "-01"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 10, isSigned, true); + EXPECT_EQ(S.str().str(), "-1"); + S.clear(); + APInt(8, 255, isSigned).toString(S, 16, isSigned, true); + EXPECT_EQ(S.str().str(), "-0x1"); + S.clear(); +} + TEST(APIntTest, Log2) { EXPECT_EQ(APInt(15, 7).logBase2(), 2U); EXPECT_EQ(APInt(15, 7).ceilLogBase2(), 3U); diff --git a/unittests/ADT/PackedVectorTest.cpp b/unittests/ADT/PackedVectorTest.cpp new file mode 100644 index 0000000..55b5d8d --- /dev/null +++ b/unittests/ADT/PackedVectorTest.cpp @@ -0,0 +1,115 @@ +//===- llvm/unittest/ADT/PackedVectorTest.cpp - PackedVector tests --------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// BitVectorTest tests fail on PowerPC for unknown reasons, so disable this +// as well since it depends on a BitVector. +#ifndef __ppc__ + +#include "llvm/ADT/PackedVector.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +TEST(PackedVectorTest, Operation) { + PackedVector<unsigned, 2> Vec; + EXPECT_EQ(0U, Vec.size()); + EXPECT_TRUE(Vec.empty()); + + Vec.resize(5); + EXPECT_EQ(5U, Vec.size()); + EXPECT_FALSE(Vec.empty()); + + Vec.resize(11); + EXPECT_EQ(11U, Vec.size()); + EXPECT_FALSE(Vec.empty()); + + PackedVector<unsigned, 2> Vec2(3); + EXPECT_EQ(3U, Vec2.size()); + EXPECT_FALSE(Vec2.empty()); + + Vec.clear(); + EXPECT_EQ(0U, Vec.size()); + EXPECT_TRUE(Vec.empty()); + + Vec.push_back(2); + Vec.push_back(0); + Vec.push_back(1); + Vec.push_back(3); + + EXPECT_EQ(2U, Vec[0]); + EXPECT_EQ(0U, Vec[1]); + EXPECT_EQ(1U, Vec[2]); + EXPECT_EQ(3U, Vec[3]); + + EXPECT_FALSE(Vec == Vec2); + EXPECT_TRUE(Vec != Vec2); + + Vec2.swap(Vec); + EXPECT_EQ(3U, Vec.size()); + EXPECT_FALSE(Vec.empty()); + EXPECT_EQ(0U, Vec[0]); + EXPECT_EQ(0U, Vec[1]); + EXPECT_EQ(0U, Vec[2]); + + EXPECT_EQ(2U, Vec2[0]); + EXPECT_EQ(0U, Vec2[1]); + EXPECT_EQ(1U, Vec2[2]); + EXPECT_EQ(3U, Vec2[3]); + + Vec = Vec2; + EXPECT_TRUE(Vec == Vec2); + EXPECT_FALSE(Vec != Vec2); + + Vec[1] = 1; + Vec2[1] = 2; + Vec |= Vec2; + EXPECT_EQ(3U, Vec[1]); +} + +#ifdef EXPECT_DEBUG_DEATH + +TEST(PackedVectorTest, UnsignedValues) { + PackedVector<unsigned, 2> Vec(1); + Vec[0] = 0; + Vec[0] = 1; + Vec[0] = 2; + Vec[0] = 3; + EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big"); + EXPECT_DEBUG_DEATH(Vec[0] = -1, "value is too big"); + EXPECT_DEBUG_DEATH(Vec[0] = 0x100, "value is too big"); + + PackedVector<unsigned, 3> Vec2(1); + Vec2[0] = 0; + Vec2[0] = 7; + EXPECT_DEBUG_DEATH(Vec[0] = 8, "value is too big"); +} + +TEST(PackedVectorTest, SignedValues) { + PackedVector<signed, 2> Vec(1); + Vec[0] = -2; + Vec[0] = -1; + Vec[0] = 0; + Vec[0] = 1; + EXPECT_DEBUG_DEATH(Vec[0] = -3, "value is too big"); + EXPECT_DEBUG_DEATH(Vec[0] = 2, "value is too big"); + + PackedVector<signed, 3> Vec2(1); + Vec2[0] = -4; + Vec2[0] = 3; + EXPECT_DEBUG_DEATH(Vec[0] = -5, "value is too big"); + EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big"); +} + +#endif + +} + +#endif diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp index f4da54d..0d3535d 100644 --- a/unittests/ADT/SmallVectorTest.cpp +++ b/unittests/ADT/SmallVectorTest.cpp @@ -35,26 +35,26 @@ public: Constructable() : value(0) { ++numConstructorCalls; } - + Constructable(int val) : value(val) { ++numConstructorCalls; } - + Constructable(const Constructable & src) { value = src.value; ++numConstructorCalls; } - + ~Constructable() { ++numDestructorCalls; } - + Constructable & operator=(const Constructable & src) { value = src.value; ++numAssignmentCalls; return *this; } - + int getValue() const { return abs(value); } @@ -64,7 +64,7 @@ public: numDestructorCalls = 0; numAssignmentCalls = 0; } - + static int getNumConstructorCalls() { return numConstructorCalls; } @@ -91,10 +91,10 @@ int Constructable::numAssignmentCalls; class SmallVectorTest : public testing::Test { protected: typedef SmallVector<Constructable, 4> VectorType; - + VectorType theVector; VectorType otherVector; - + void SetUp() { Constructable::reset(); } @@ -111,7 +111,7 @@ protected: // Assert that theVector contains the specified values, in order. void assertValuesInOrder(VectorType & v, size_t size, ...) { EXPECT_EQ(size, v.size()); - + va_list ap; va_start(ap, size); for (size_t i = 0; i < size; ++i) { @@ -121,7 +121,7 @@ protected: va_end(ap); } - + // Generate a sequence of values to initialize the vector. void makeSequence(VectorType & v, int start, int end) { for (int i = start; i <= end; ++i) { @@ -155,18 +155,24 @@ TEST_F(SmallVectorTest, PushPopTest) { theVector.push_back(Constructable(2)); assertValuesInOrder(theVector, 2u, 1, 2); + // Insert at beginning + theVector.insert(theVector.begin(), theVector[1]); + assertValuesInOrder(theVector, 3u, 2, 1, 2); + // Pop one element theVector.pop_back(); - assertValuesInOrder(theVector, 1u, 1); + assertValuesInOrder(theVector, 2u, 2, 1); - // Pop another element + // Pop remaining elements + theVector.pop_back(); theVector.pop_back(); assertEmpty(theVector); - + // Check number of constructor calls. Should be 2 for each list element, - // one for the argument to push_back, and one for the list element itself. - EXPECT_EQ(4, Constructable::getNumConstructorCalls()); - EXPECT_EQ(4, Constructable::getNumDestructorCalls()); + // one for the argument to push_back, one for the argument to insert, + // and one for the list element itself. + EXPECT_EQ(5, Constructable::getNumConstructorCalls()); + EXPECT_EQ(5, Constructable::getNumDestructorCalls()); } // Clear test. @@ -198,7 +204,7 @@ TEST_F(SmallVectorTest, ResizeGrowTest) { SCOPED_TRACE("ResizeGrowTest"); 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()); @@ -226,10 +232,10 @@ TEST_F(SmallVectorTest, OverflowTest) { for (int i = 0; i < 10; ++i) { EXPECT_EQ(i+1, theVector[i].getValue()); } - + // Now resize back to fixed size. theVector.resize(1); - + assertValuesInOrder(theVector, 1u, 1); } @@ -364,13 +370,13 @@ TEST_F(SmallVectorTest, ComparisonTest) { makeSequence(theVector, 1, 3); makeSequence(otherVector, 1, 3); - + EXPECT_TRUE(theVector == otherVector); EXPECT_FALSE(theVector != otherVector); otherVector.clear(); makeSequence(otherVector, 2, 4); - + EXPECT_FALSE(theVector == otherVector); EXPECT_TRUE(theVector != otherVector); } diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp index ea91348..2ae5820 100644 --- a/unittests/ADT/StringMapTest.cpp +++ b/unittests/ADT/StringMapTest.cpp @@ -51,7 +51,7 @@ protected: // Iterator tests StringMap<uint32_t>::iterator it = testMap.begin(); - EXPECT_STREQ(testKey, it->first()); + EXPECT_STREQ(testKey, it->first().data()); EXPECT_EQ(testValue, it->second); ++it; EXPECT_TRUE(it == testMap.end()); @@ -157,7 +157,7 @@ TEST_F(StringMapTest, IterationTest) { it != testMap.end(); ++it) { std::stringstream ss; ss << "key_" << it->second; - ASSERT_STREQ(ss.str().c_str(), it->first()); + ASSERT_STREQ(ss.str().c_str(), it->first().data()); visited[it->second] = true; } @@ -189,7 +189,7 @@ TEST_F(StringMapTest, StringMapEntryTest) { StringMap<uint32_t>::value_type* entry = StringMap<uint32_t>::value_type::Create( testKeyFirst, testKeyFirst + testKeyLength, 1u); - EXPECT_STREQ(testKey, entry->first()); + EXPECT_STREQ(testKey, entry->first().data()); EXPECT_EQ(1u, entry->second); free(entry); } diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp index b734160..39ced2a 100644 --- a/unittests/Analysis/ScalarEvolutionTest.cpp +++ b/unittests/Analysis/ScalarEvolutionTest.cpp @@ -23,7 +23,7 @@ TEST(ScalarEvolutionsTest, SCEVUnknownRAUW) { Module M("world", Context); const FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), - std::vector<const Type *>(), false); + std::vector<Type *>(), false); Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); ReturnInst::Create(Context, 0, BB); diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index fcf6109..81d7029 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -64,6 +64,7 @@ add_llvm_unittest(ADT ADT/ImmutableSetTest.cpp ADT/IntEqClassesTest.cpp ADT/IntervalMapTest.cpp + ADT/PackedVectorTest.cpp ADT/SmallBitVectorTest.cpp ADT/SmallStringTest.cpp ADT/SmallVectorTest.cpp @@ -105,7 +106,6 @@ add_llvm_unittest(Transforms/Utils set(VMCoreSources VMCore/ConstantsTest.cpp - VMCore/DerivedTypesTest.cpp VMCore/InstructionsTest.cpp VMCore/MetadataTest.cpp VMCore/PassManagerTest.cpp diff --git a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp index ff5af3b..039b5e0 100644 --- a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp @@ -14,13 +14,14 @@ #include "llvm/Function.h" #include "llvm/GlobalValue.h" #include "llvm/LLVMContext.h" +#include "llvm/ADT/ArrayRef.h" using namespace llvm; namespace { Function *makeFakeFunction() { - std::vector<const Type*> params; + std::vector<Type*> params; const FunctionType *FTy = FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false); return Function::Create(FTy, GlobalValue::ExternalLinkage); diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index ceacbbe..9c001c4 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -37,7 +37,7 @@ using namespace llvm; namespace { Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) { - std::vector<const Type*> params; + std::vector<Type*> params; const FunctionType *FTy = FunctionType::get(G->getType()->getElementType(), params, false); Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage, Name, M); @@ -322,7 +322,7 @@ TEST_F(JITTest, NonLazyCompilationStillNeedsStubs) { const FunctionType *Func1Ty = cast<FunctionType>(TypeBuilder<void(void), false>::get(Context)); - std::vector<const Type*> arg_types; + std::vector<Type*> arg_types; arg_types.push_back(Type::getInt1Ty(Context)); const FunctionType *FuncTy = FunctionType::get( Type::getVoidTy(Context), arg_types, false); diff --git a/unittests/Support/ConstantRangeTest.cpp b/unittests/Support/ConstantRangeTest.cpp index 161e2cf..742bcb4 100644 --- a/unittests/Support/ConstantRangeTest.cpp +++ b/unittests/Support/ConstantRangeTest.cpp @@ -299,6 +299,8 @@ TEST_F(ConstantRangeTest, Sub) { EXPECT_EQ(Empty.sub(APInt(16, 4)), Empty); EXPECT_EQ(Some.sub(APInt(16, 4)), ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6))); + EXPECT_EQ(Some.sub(Some), + ConstantRange(APInt(16, 0xf561), APInt(16, 0xaa0))); EXPECT_EQ(Wrap.sub(APInt(16, 4)), ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6))); EXPECT_EQ(One.sub(APInt(16, 4)), diff --git a/unittests/Support/TypeBuilderTest.cpp b/unittests/Support/TypeBuilderTest.cpp index e805827..0609178 100644 --- a/unittests/Support/TypeBuilderTest.cpp +++ b/unittests/Support/TypeBuilderTest.cpp @@ -9,6 +9,7 @@ #include "llvm/Support/TypeBuilder.h" #include "llvm/LLVMContext.h" +#include "llvm/ADT/ArrayRef.h" #include "gtest/gtest.h" @@ -119,7 +120,7 @@ TEST(TypeBuilderTest, Derived) { } TEST(TypeBuilderTest, Functions) { - std::vector<const Type*> params; + std::vector<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), @@ -186,7 +187,7 @@ 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; + std::vector<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)); @@ -209,7 +210,7 @@ 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; + std::vector<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)); @@ -230,19 +231,19 @@ public: namespace { TEST(TypeBuilderTest, Extensions) { - EXPECT_EQ(PointerType::getUnqual(StructType::get(getGlobalContext(), + EXPECT_EQ(PointerType::getUnqual(StructType::get( 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(), + 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()), NULL)), (TypeBuilder<MyPortableType*, false>::get(getGlobalContext()))); - EXPECT_EQ(PointerType::getUnqual(StructType::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()), diff --git a/unittests/VMCore/DerivedTypesTest.cpp b/unittests/VMCore/DerivedTypesTest.cpp deleted file mode 100644 index 9562157..0000000 --- a/unittests/VMCore/DerivedTypesTest.cpp +++ /dev/null @@ -1,88 +0,0 @@ -//===- llvm/unittest/VMCore/DerivedTypesTest.cpp - Types unit tests -------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "gtest/gtest.h" -#include "../lib/VMCore/LLVMContextImpl.h" -#include "llvm/DerivedTypes.h" -#include "llvm/LLVMContext.h" -#include "llvm/Constants.h" -#include "llvm/Support/ValueHandle.h" -using namespace llvm; - -namespace { - -static void PR7658() { - LLVMContext ctx; - - WeakVH NullPtr; - PATypeHolder h1; - { - OpaqueType *o1 = OpaqueType::get(ctx); - PointerType *p1 = PointerType::get(o1, 0); - - std::vector<const Type *> t1; - t1.push_back(IntegerType::get(ctx, 32)); - t1.push_back(p1); - NullPtr = ConstantPointerNull::get(p1); - OpaqueType *o2 = OpaqueType::get (ctx); - PointerType *p2 = PointerType::get (o2, 0); - t1.push_back(p2); - - - StructType *s1 = StructType::get(ctx, t1); - h1 = s1; - o1->refineAbstractTypeTo(s1); - o2->refineAbstractTypeTo(h1.get()); // h1 = { i32, \2*, \2* } - } - - - OpaqueType *o3 = OpaqueType::get(ctx); - PointerType *p3 = PointerType::get(o3, 0); // p3 = opaque* - - std::vector<const Type *> t2; - t2.push_back(IntegerType::get(ctx, 32)); - t2.push_back(p3); - - std::vector<Constant *> v2; - v2.push_back(ConstantInt::get(IntegerType::get(ctx, 32), 14)); - v2.push_back(ConstantPointerNull::get(p3)); - - OpaqueType *o4 = OpaqueType::get(ctx); - { - PointerType *p4 = PointerType::get(o4, 0); - t2.push_back(p4); - v2.push_back(ConstantPointerNull::get(p4)); - } - - WeakVH CS = ConstantStruct::get(ctx, v2, false); // { i32 14, opaque* null, opaque* null} - - StructType *s2 = StructType::get(ctx, t2); - PATypeHolder h2(s2); - o3->refineAbstractTypeTo(s2); - o4->refineAbstractTypeTo(h2.get()); -} - - -TEST(OpaqueTypeTest, RegisterWithContext) { - LLVMContext C; - LLVMContextImpl *pImpl = C.pImpl; - - // 1 refers to the AlwaysOpaqueTy allocated in the Context's constructor and - // destroyed in the destructor. - EXPECT_EQ(1u, pImpl->OpaqueTypes.size()); - { - PATypeHolder Type = OpaqueType::get(C); - EXPECT_EQ(2u, pImpl->OpaqueTypes.size()); - } - EXPECT_EQ(1u, pImpl->OpaqueTypes.size()); - - PR7658(); -} - -} // namespace diff --git a/unittests/VMCore/PassManagerTest.cpp b/unittests/VMCore/PassManagerTest.cpp index 2f2a200..af845b0 100644 --- a/unittests/VMCore/PassManagerTest.cpp +++ b/unittests/VMCore/PassManagerTest.cpp @@ -405,13 +405,13 @@ namespace llvm { mod->setTargetTriple("x86_64-unknown-linux-gnu"); // Type Definitions - std::vector<const Type*>FuncTy_0_args; + std::vector<Type*>FuncTy_0_args; FunctionType* FuncTy_0 = FunctionType::get( /*Result=*/IntegerType::get(getGlobalContext(), 32), /*Params=*/FuncTy_0_args, /*isVarArg=*/false); - std::vector<const Type*>FuncTy_2_args; + std::vector<Type*>FuncTy_2_args; FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1)); FunctionType* FuncTy_2 = FunctionType::get( /*Result=*/Type::getVoidTy(getGlobalContext()), |