diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-02-16 09:30:23 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-02-16 09:30:23 +0000 |
commit | 6fe5c7aa327e188b7176daa5595bbf075a6b94df (patch) | |
tree | 4cfca640904d1896e25032757a61f8959c066919 /unittests | |
parent | 989df958a10f0beb90b89ccadd8351cbe51d90b1 (diff) |
Notes
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/APFloatTest.cpp | 2 | ||||
-rw-r--r-- | unittests/ADT/BitVectorTest.cpp | 42 | ||||
-rw-r--r-- | unittests/ADT/Makefile | 8 | ||||
-rw-r--r-- | unittests/ADT/SmallBitVectorTest.cpp | 39 | ||||
-rw-r--r-- | unittests/ADT/StringMapTest.cpp | 1 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp | 3 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITTest.cpp | 88 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/MultiJITTest.cpp | 164 | ||||
-rw-r--r-- | unittests/Makefile.unittest | 6 | ||||
-rw-r--r-- | unittests/Support/TypeBuilderTest.cpp | 9 | ||||
-rw-r--r-- | unittests/VMCore/DerivedTypesTest.cpp | 10 | ||||
-rw-r--r-- | unittests/VMCore/PassManagerTest.cpp | 5 | ||||
-rw-r--r-- | unittests/VMCore/VerifierTest.cpp | 44 |
13 files changed, 372 insertions, 49 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp index 76cdafcf3fe1..b02cc3e31722 100644 --- a/unittests/ADT/APFloatTest.cpp +++ b/unittests/ADT/APFloatTest.cpp @@ -333,6 +333,8 @@ TEST(APFloatTest, toString) { ASSERT_EQ("1.01E-2", convertToString(1.01E-2, 5, 1)); ASSERT_EQ("0.7853981633974483", convertToString(0.78539816339744830961, 0, 3)); ASSERT_EQ("4.940656458412465E-324", convertToString(4.9406564584124654e-324, 0, 3)); + ASSERT_EQ("873.1834", convertToString(873.1834, 0, 1)); + ASSERT_EQ("8.731834E+2", convertToString(873.1834, 0, 0)); } #ifdef GTEST_HAS_DEATH_TEST diff --git a/unittests/ADT/BitVectorTest.cpp b/unittests/ADT/BitVectorTest.cpp index 534828192c0b..4fe11c1d17ab 100644 --- a/unittests/ADT/BitVectorTest.cpp +++ b/unittests/ADT/BitVectorTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#ifndef XFAIL #include "llvm/ADT/BitVector.h" #include "gtest/gtest.h" @@ -137,4 +138,45 @@ TEST(BitVectorTest, TrivialOperation) { EXPECT_TRUE(Vec.empty()); } +TEST(BitVectorTest, CompoundAssignment) { + BitVector A; + A.resize(10); + A.set(4); + A.set(7); + + BitVector B; + B.resize(50); + B.set(5); + B.set(18); + + A |= B; + EXPECT_TRUE(A.test(4)); + EXPECT_TRUE(A.test(5)); + EXPECT_TRUE(A.test(7)); + EXPECT_TRUE(A.test(18)); + EXPECT_EQ(4U, A.count()); + EXPECT_EQ(50U, A.size()); + + B.resize(10); + B.set(); + B.reset(2); + B.reset(7); + A &= B; + EXPECT_FALSE(A.test(2)); + EXPECT_FALSE(A.test(7)); + EXPECT_EQ(2U, A.count()); + EXPECT_EQ(50U, A.size()); + + B.resize(100); + B.set(); + + A ^= B; + EXPECT_TRUE(A.test(2)); + EXPECT_TRUE(A.test(7)); + EXPECT_EQ(98U, A.count()); + EXPECT_EQ(100U, A.size()); } + +} + +#endif diff --git a/unittests/ADT/Makefile b/unittests/ADT/Makefile index c56b95170490..fe0832894d32 100644 --- a/unittests/ADT/Makefile +++ b/unittests/ADT/Makefile @@ -12,4 +12,12 @@ TESTNAME = ADT LINK_COMPONENTS := core support include $(LEVEL)/Makefile.config + +# Xfail BitVectorTest for now on PPC Darwin. 7598360. +ifeq ($(ARCH),PowerPC) +ifeq ($(TARGET_OS),Darwin) +CPP.Flags += -DXFAIL +endif +endif + include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/unittests/ADT/SmallBitVectorTest.cpp b/unittests/ADT/SmallBitVectorTest.cpp index a5c60dec9ba2..a2cc652ca1d4 100644 --- a/unittests/ADT/SmallBitVectorTest.cpp +++ b/unittests/ADT/SmallBitVectorTest.cpp @@ -137,4 +137,43 @@ TEST(SmallBitVectorTest, TrivialOperation) { EXPECT_TRUE(Vec.empty()); } +TEST(SmallBitVectorTest, CompoundAssignment) { + SmallBitVector A; + A.resize(10); + A.set(4); + A.set(7); + + SmallBitVector B; + B.resize(50); + B.set(5); + B.set(18); + + A |= B; + EXPECT_TRUE(A.test(4)); + EXPECT_TRUE(A.test(5)); + EXPECT_TRUE(A.test(7)); + EXPECT_TRUE(A.test(18)); + EXPECT_EQ(4U, A.count()); + EXPECT_EQ(50U, A.size()); + + B.resize(10); + B.set(); + B.reset(2); + B.reset(7); + A &= B; + EXPECT_FALSE(A.test(2)); + EXPECT_FALSE(A.test(7)); + EXPECT_EQ(2U, A.count()); + EXPECT_EQ(50U, A.size()); + + B.resize(100); + B.set(); + + A ^= B; + EXPECT_TRUE(A.test(2)); + EXPECT_TRUE(A.test(7)); + EXPECT_EQ(98U, A.count()); + EXPECT_EQ(100U, A.size()); +} + } diff --git a/unittests/ADT/StringMapTest.cpp b/unittests/ADT/StringMapTest.cpp index 3dcdc39b904d..413f068d4906 100644 --- a/unittests/ADT/StringMapTest.cpp +++ b/unittests/ADT/StringMapTest.cpp @@ -191,6 +191,7 @@ TEST_F(StringMapTest, StringMapEntryTest) { testKeyFirst, testKeyFirst + testKeyLength, 1u); EXPECT_STREQ(testKey, entry->first()); EXPECT_EQ(1u, entry->second); + free(entry); } // Test insert() method. diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp index a58a0872a4ec..a36ec3bf2a1b 100644 --- a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp @@ -12,7 +12,6 @@ #include "llvm/LLVMContext.h" #include "llvm/Instructions.h" #include "llvm/Module.h" -#include "llvm/ModuleProvider.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/CodeGen/MachineCodeInfo.h" #include "llvm/ExecutionEngine/JIT.h" @@ -25,7 +24,6 @@ using namespace llvm; int dummy; -#if 0 namespace { struct FunctionEmittedEvent { @@ -238,4 +236,3 @@ testing::Environment* const jit_env = testing::AddGlobalTestEnvironment(new JITEnvironment); } // anonymous namespace -#endif diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index bed2d22f1cfa..84ee0e3075d6 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -23,7 +23,6 @@ #include "llvm/GlobalVariable.h" #include "llvm/LLVMContext.h" #include "llvm/Module.h" -#include "llvm/ModuleProvider.h" #include "llvm/Support/IRBuilder.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" @@ -58,7 +57,6 @@ std::string DumpFunction(const Function *F) { return Result; } -#if 0 class RecordingJITMemoryManager : public JITMemoryManager { const OwningPtr<JITMemoryManager> Base; public: @@ -179,7 +177,6 @@ public: return Base->endExceptionTable(F, TableStart, TableEnd, FrameRegister); } }; -#endif bool LoadAssemblyInto(Module *M, const char *assembly) { SMDiagnostic Error; @@ -196,16 +193,11 @@ class JITTest : public testing::Test { protected: virtual void SetUp() { M = new Module("<main>", Context); - MP = new ExistingModuleProvider(M); -#if 0 RJMM = new RecordingJITMemoryManager; RJMM->setPoisonMemory(true); -#endif std::string Error; - TheJIT.reset(EngineBuilder(MP).setEngineKind(EngineKind::JIT) -#if 0 + TheJIT.reset(EngineBuilder(M).setEngineKind(EngineKind::JIT) .setJITMemoryManager(RJMM) -#endif .setErrorStr(&Error).create()); ASSERT_TRUE(TheJIT.get() != NULL) << Error; } @@ -215,11 +207,8 @@ class JITTest : public testing::Test { } LLVMContext Context; - Module *M; // Owned by MP. - ModuleProvider *MP; // Owned by ExecutionEngine. -#if 0 + Module *M; // Owned by ExecutionEngine. RecordingJITMemoryManager *RJMM; -#endif OwningPtr<ExecutionEngine> TheJIT; }; @@ -231,14 +220,13 @@ class JITTest : public testing::Test { TEST(JIT, GlobalInFunction) { LLVMContext context; Module *M = new Module("<main>", context); - ExistingModuleProvider *MP = new ExistingModuleProvider(M); JITMemoryManager *MemMgr = JITMemoryManager::CreateDefaultMemManager(); // Tell the memory manager to poison freed memory so that accessing freed // memory is more easily tested. MemMgr->setPoisonMemory(true); std::string Error; - OwningPtr<ExecutionEngine> JIT(EngineBuilder(MP) + OwningPtr<ExecutionEngine> JIT(EngineBuilder(M) .setEngineKind(EngineKind::JIT) .setErrorStr(&Error) .setJITMemoryManager(MemMgr) @@ -436,9 +424,9 @@ TEST_F(JITTest, ModuleDeletion) { "} "); Function *func = M->getFunction("main"); TheJIT->getPointerToFunction(func); - TheJIT->deleteModuleProvider(MP); + TheJIT->removeModule(M); + delete M; -#if 0 SmallPtrSet<const void*, 2> FunctionsDeallocated; for (unsigned i = 0, e = RJMM->deallocateFunctionBodyCalls.size(); i != e; ++i) { @@ -472,7 +460,6 @@ TEST_F(JITTest, ModuleDeletion) { } EXPECT_EQ(RJMM->startExceptionTableCalls.size(), NumTablesDeallocated); -#endif } // ARM and PPC still emit stubs for calls since the target may be too far away @@ -507,18 +494,14 @@ TEST_F(JITTest, NoStubs) { // We should now allocate no more stubs, we have the code to foo // and the existing stub for bar. -#if 0 int stubsBefore = RJMM->stubsAllocated; -#endif Function *func = M->getFunction("main"); TheJIT->getPointerToFunction(func); Function *bar = M->getFunction("bar"); TheJIT->getPointerToFunction(bar); -#if 0 ASSERT_EQ(stubsBefore, RJMM->stubsAllocated); -#endif } #endif // !ARM && !PPC @@ -661,36 +644,70 @@ std::string AssembleToBitcode(LLVMContext &Context, const char *Assembly) { } // Returns a newly-created ExecutionEngine that reads the bitcode in 'Bitcode' -// lazily. The associated ModuleProvider (owned by the ExecutionEngine) is -// returned in MP. Both will be NULL on an error. Bitcode must live at least -// as long as the ExecutionEngine. +// lazily. The associated Module (owned by the ExecutionEngine) is returned in +// M. Both will be NULL on an error. Bitcode must live at least as long as the +// ExecutionEngine. ExecutionEngine *getJITFromBitcode( - LLVMContext &Context, const std::string &Bitcode, ModuleProvider *&MP) { + LLVMContext &Context, const std::string &Bitcode, Module *&M) { // c_str() is null-terminated like MemoryBuffer::getMemBuffer requires. MemoryBuffer *BitcodeBuffer = MemoryBuffer::getMemBuffer(Bitcode.c_str(), Bitcode.c_str() + Bitcode.size(), "Bitcode for test"); std::string errMsg; - MP = getBitcodeModuleProvider(BitcodeBuffer, Context, &errMsg); - if (MP == NULL) { + M = getLazyBitcodeModule(BitcodeBuffer, Context, &errMsg); + if (M == NULL) { ADD_FAILURE() << errMsg; delete BitcodeBuffer; return NULL; } - ExecutionEngine *TheJIT = EngineBuilder(MP) + ExecutionEngine *TheJIT = EngineBuilder(M) .setEngineKind(EngineKind::JIT) .setErrorStr(&errMsg) .create(); if (TheJIT == NULL) { ADD_FAILURE() << errMsg; - delete MP; - MP = NULL; + delete M; + M = NULL; return NULL; } return TheJIT; } +TEST(LazyLoadedJITTest, MaterializableAvailableExternallyFunctionIsntCompiled) { + LLVMContext Context; + const std::string Bitcode = + AssembleToBitcode(Context, + "define available_externally i32 " + " @JITTest_AvailableExternallyFunction() { " + " ret i32 7 " + "} " + " " + "define i32 @func() { " + " %result = tail call i32 " + " @JITTest_AvailableExternallyFunction() " + " ret i32 %result " + "} "); + ASSERT_FALSE(Bitcode.empty()) << "Assembling failed"; + Module *M; + OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, M)); + ASSERT_TRUE(TheJIT.get()) << "Failed to create JIT."; + TheJIT->DisableLazyCompilation(true); + + Function *funcIR = M->getFunction("func"); + Function *availableFunctionIR = + M->getFunction("JITTest_AvailableExternallyFunction"); + + // Double-check that the available_externally function is still unmaterialized + // when getPointerToFunction needs to find out if it's available_externally. + EXPECT_TRUE(availableFunctionIR->isMaterializable()); + + int32_t (*func)() = reinterpret_cast<int32_t(*)()>( + (intptr_t)TheJIT->getPointerToFunction(funcIR)); + EXPECT_EQ(42, func()) << "func should return 42 from the static version," + << " not 7 from the IR version."; +} + TEST(LazyLoadedJITTest, EagerCompiledRecursionThroughGhost) { LLVMContext Context; const std::string Bitcode = @@ -711,16 +728,15 @@ TEST(LazyLoadedJITTest, EagerCompiledRecursionThroughGhost) { " ret i32 %result " "} "); ASSERT_FALSE(Bitcode.empty()) << "Assembling failed"; - ModuleProvider *MP; - OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, MP)); + Module *M; + OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, M)); ASSERT_TRUE(TheJIT.get()) << "Failed to create JIT."; TheJIT->DisableLazyCompilation(true); - Module *M = MP->getModule(); Function *recur1IR = M->getFunction("recur1"); Function *recur2IR = M->getFunction("recur2"); - EXPECT_TRUE(recur1IR->hasNotBeenReadFromBitcode()); - EXPECT_TRUE(recur2IR->hasNotBeenReadFromBitcode()); + EXPECT_TRUE(recur1IR->isMaterializable()); + EXPECT_TRUE(recur2IR->isMaterializable()); int32_t (*recur1)(int32_t) = reinterpret_cast<int32_t(*)(int32_t)>( (intptr_t)TheJIT->getPointerToFunction(recur1IR)); diff --git a/unittests/ExecutionEngine/JIT/MultiJITTest.cpp b/unittests/ExecutionEngine/JIT/MultiJITTest.cpp new file mode 100644 index 000000000000..8997d39836c9 --- /dev/null +++ b/unittests/ExecutionEngine/JIT/MultiJITTest.cpp @@ -0,0 +1,164 @@ +//===- MultiJITTest.cpp - Unit tests for instantiating multiple JITs ------===// +// +// 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/LLVMContext.h" +#include "llvm/Module.h" +#include "llvm/Assembly/Parser.h" +#include "llvm/ExecutionEngine/GenericValue.h" +#include "llvm/ExecutionEngine/JIT.h" +#include "llvm/Support/SourceMgr.h" +#include <vector> + +using namespace llvm; + +namespace { + +bool LoadAssemblyInto(Module *M, const char *assembly) { + SMDiagnostic Error; + bool success = + NULL != ParseAssemblyString(assembly, M, Error, M->getContext()); + std::string errMsg; + raw_string_ostream os(errMsg); + Error.Print("", os); + EXPECT_TRUE(success) << os.str(); + return success; +} + +void createModule1(LLVMContext &Context1, Module *&M1, Function *&FooF1) { + M1 = new Module("test1", Context1); + LoadAssemblyInto(M1, + "define i32 @add1(i32 %ArgX1) { " + "entry: " + " %addresult = add i32 1, %ArgX1 " + " ret i32 %addresult " + "} " + " " + "define i32 @foo1() { " + "entry: " + " %add1 = call i32 @add1(i32 10) " + " ret i32 %add1 " + "} "); + FooF1 = M1->getFunction("foo1"); +} + +void createModule2(LLVMContext &Context2, Module *&M2, Function *&FooF2) { + M2 = new Module("test2", Context2); + LoadAssemblyInto(M2, + "define i32 @add2(i32 %ArgX2) { " + "entry: " + " %addresult = add i32 2, %ArgX2 " + " ret i32 %addresult " + "} " + " " + "define i32 @foo2() { " + "entry: " + " %add2 = call i32 @add2(i32 10) " + " ret i32 %add2 " + "} "); + FooF2 = M2->getFunction("foo2"); +} + +TEST(MultiJitTest, EagerMode) { + LLVMContext Context1; + Module *M1 = 0; + Function *FooF1 = 0; + createModule1(Context1, M1, FooF1); + + LLVMContext Context2; + Module *M2 = 0; + Function *FooF2 = 0; + createModule2(Context2, M2, FooF2); + + // Now we create the JIT in eager mode + OwningPtr<ExecutionEngine> EE1(EngineBuilder(M1).create()); + EE1->DisableLazyCompilation(true); + OwningPtr<ExecutionEngine> EE2(EngineBuilder(M2).create()); + EE2->DisableLazyCompilation(true); + + // Call the `foo' function with no arguments: + std::vector<GenericValue> noargs; + GenericValue gv1 = EE1->runFunction(FooF1, noargs); + GenericValue gv2 = EE2->runFunction(FooF2, noargs); + + // Import result of execution: + EXPECT_EQ(gv1.IntVal, 11); + EXPECT_EQ(gv2.IntVal, 12); + + EE1->freeMachineCodeForFunction(FooF1); + EE2->freeMachineCodeForFunction(FooF2); +} + +TEST(MultiJitTest, LazyMode) { + LLVMContext Context1; + Module *M1 = 0; + Function *FooF1 = 0; + createModule1(Context1, M1, FooF1); + + LLVMContext Context2; + Module *M2 = 0; + Function *FooF2 = 0; + createModule2(Context2, M2, FooF2); + + // Now we create the JIT in lazy mode + OwningPtr<ExecutionEngine> EE1(EngineBuilder(M1).create()); + EE1->DisableLazyCompilation(false); + OwningPtr<ExecutionEngine> EE2(EngineBuilder(M2).create()); + EE2->DisableLazyCompilation(false); + + // Call the `foo' function with no arguments: + std::vector<GenericValue> noargs; + GenericValue gv1 = EE1->runFunction(FooF1, noargs); + GenericValue gv2 = EE2->runFunction(FooF2, noargs); + + // Import result of execution: + EXPECT_EQ(gv1.IntVal, 11); + EXPECT_EQ(gv2.IntVal, 12); + + EE1->freeMachineCodeForFunction(FooF1); + EE2->freeMachineCodeForFunction(FooF2); +} + +extern "C" { + extern void *getPointerToNamedFunction(const char *Name); +} + +TEST(MultiJitTest, JitPool) { + LLVMContext Context1; + Module *M1 = 0; + Function *FooF1 = 0; + createModule1(Context1, M1, FooF1); + + LLVMContext Context2; + Module *M2 = 0; + Function *FooF2 = 0; + createModule2(Context2, M2, FooF2); + + // Now we create two JITs + OwningPtr<ExecutionEngine> EE1(EngineBuilder(M1).create()); + OwningPtr<ExecutionEngine> EE2(EngineBuilder(M2).create()); + + Function *F1 = EE1->FindFunctionNamed("foo1"); + void *foo1 = EE1->getPointerToFunction(F1); + + Function *F2 = EE2->FindFunctionNamed("foo2"); + void *foo2 = EE2->getPointerToFunction(F2); + + // Function in M1 + EXPECT_EQ(getPointerToNamedFunction("foo1"), foo1); + + // Function in M2 + EXPECT_EQ(getPointerToNamedFunction("foo2"), foo2); + + // Symbol search + EXPECT_EQ((intptr_t)getPointerToNamedFunction("getPointerToNamedFunction"), + (intptr_t)&getPointerToNamedFunction); +} + +} // anonymous namespace diff --git a/unittests/Makefile.unittest b/unittests/Makefile.unittest index e4174355ed75..6fbef54691db 100644 --- a/unittests/Makefile.unittest +++ b/unittests/Makefile.unittest @@ -14,6 +14,12 @@ # Set up variables for building a unit test. ifdef TESTNAME +CPP.Flags += -DGTEST_HAS_RTTI=0 +# gcc's TR1 <tuple> header depends on RTTI, so force googletest to use +# its own tuple implementation. When we import googletest >=1.4.0, we +# can drop this line. +CPP.Flags += -DGTEST_HAS_TR1_TUPLE=0 + include $(LEVEL)/Makefile.common LLVMUnitTestExe = $(BuildMode)/$(TESTNAME)Tests$(EXEEXT) diff --git a/unittests/Support/TypeBuilderTest.cpp b/unittests/Support/TypeBuilderTest.cpp index a5c5e67129a3..e805827ae224 100644 --- a/unittests/Support/TypeBuilderTest.cpp +++ b/unittests/Support/TypeBuilderTest.cpp @@ -19,9 +19,16 @@ 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 case for C compatibility: + // 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) { diff --git a/unittests/VMCore/DerivedTypesTest.cpp b/unittests/VMCore/DerivedTypesTest.cpp index 11b4dffb5f47..2e0450d6e5ce 100644 --- a/unittests/VMCore/DerivedTypesTest.cpp +++ b/unittests/VMCore/DerivedTypesTest.cpp @@ -18,14 +18,16 @@ namespace { TEST(OpaqueTypeTest, RegisterWithContext) { LLVMContext C; - LLVMContextImpl *pImpl = C.pImpl; + LLVMContextImpl *pImpl = C.pImpl; - EXPECT_EQ(0u, pImpl->OpaqueTypes.size()); + // 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(1u, pImpl->OpaqueTypes.size()); + EXPECT_EQ(2u, pImpl->OpaqueTypes.size()); } - EXPECT_EQ(0u, pImpl->OpaqueTypes.size()); + EXPECT_EQ(1u, pImpl->OpaqueTypes.size()); } } // namespace diff --git a/unittests/VMCore/PassManagerTest.cpp b/unittests/VMCore/PassManagerTest.cpp index 092ce3d928b2..cb8f9ebb939b 100644 --- a/unittests/VMCore/PassManagerTest.cpp +++ b/unittests/VMCore/PassManagerTest.cpp @@ -32,10 +32,6 @@ #include "llvm/Assembly/PrintModulePass.h" #include "gtest/gtest.h" -int dummy; - -#if 0 - namespace llvm { namespace { // ND = no deps @@ -529,4 +525,3 @@ namespace llvm { } } -#endif diff --git a/unittests/VMCore/VerifierTest.cpp b/unittests/VMCore/VerifierTest.cpp new file mode 100644 index 000000000000..c8838c5276db --- /dev/null +++ b/unittests/VMCore/VerifierTest.cpp @@ -0,0 +1,44 @@ +//===- llvm/unittest/VMCore/VerifierTest.cpp - Verifier 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/Constants.h" +#include "llvm/DerivedTypes.h" +#include "llvm/Function.h" +#include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" +#include "llvm/Analysis/Verifier.h" +#include "gtest/gtest.h" + +namespace llvm { +namespace { + +TEST(VerifierTest, Branch_i1) { + LLVMContext &C = getGlobalContext(); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false); + Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage); + BasicBlock *Entry = BasicBlock::Create(C, "entry", F); + BasicBlock *Exit = BasicBlock::Create(C, "exit", F); + ReturnInst::Create(C, Exit); + + // To avoid triggering an assertion in BranchInst::Create, we first create + // a branch with an 'i1' condition ... + + Constant *False = ConstantInt::getFalse(C); + BranchInst *BI = BranchInst::Create(Exit, Exit, False, Entry); + + // ... then use setOperand to redirect it to a value of different type. + + Constant *Zero32 = ConstantInt::get(IntegerType::get(C, 32), 0); + BI->setOperand(0, Zero32); + + EXPECT_TRUE(verifyFunction(*F, ReturnStatusAction)); +} + +} +} |