From 411afbe321a7a3705a390d405e9e71ab21f71657 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 16 Jul 2012 07:44:45 +0000 Subject: Move the IRBuilder unittest from Support to VMCore. This got missed in the original move of IRBuilder. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160249 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Support/CMakeLists.txt | 1 - unittests/Support/IRBuilderTest.cpp | 74 ------------------------------------- unittests/VMCore/CMakeLists.txt | 1 + unittests/VMCore/IRBuilderTest.cpp | 74 +++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 75 deletions(-) delete mode 100644 unittests/Support/IRBuilderTest.cpp create mode 100644 unittests/VMCore/IRBuilderTest.cpp (limited to 'unittests') diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt index ad16e62..8859678 100644 --- a/unittests/Support/CMakeLists.txt +++ b/unittests/Support/CMakeLists.txt @@ -13,7 +13,6 @@ add_llvm_unittest(SupportTests DataExtractorTest.cpp EndianTest.cpp IntegersSubsetTest.cpp - IRBuilderTest.cpp LeakDetectorTest.cpp ManagedStatic.cpp MathExtrasTest.cpp diff --git a/unittests/Support/IRBuilderTest.cpp b/unittests/Support/IRBuilderTest.cpp deleted file mode 100644 index 56b9f15..0000000 --- a/unittests/Support/IRBuilderTest.cpp +++ /dev/null @@ -1,74 +0,0 @@ -//===- llvm/unittest/Support/IRBuilderTest.cpp - IRBuilder tests ----------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/BasicBlock.h" -#include "llvm/Function.h" -#include "llvm/IRBuilder.h" -#include "llvm/IntrinsicInst.h" -#include "llvm/LLVMContext.h" -#include "llvm/Module.h" -#include "llvm/ADT/OwningPtr.h" - -#include "gtest/gtest.h" - -using namespace llvm; - -namespace { - -class IRBuilderTest : public testing::Test { -protected: - virtual void SetUp() { - M.reset(new Module("MyModule", getGlobalContext())); - FunctionType *FTy = FunctionType::get(Type::getVoidTy(getGlobalContext()), - /*isVarArg=*/false); - Function *F = Function::Create(FTy, Function::ExternalLinkage, "", M.get()); - BB = BasicBlock::Create(getGlobalContext(), "", F); - } - - virtual void TearDown() { - BB = 0; - M.reset(); - } - - OwningPtr M; - BasicBlock *BB; -}; - -TEST_F(IRBuilderTest, Lifetime) { - IRBuilder<> Builder(BB); - AllocaInst *Var1 = Builder.CreateAlloca(Builder.getInt8Ty()); - AllocaInst *Var2 = Builder.CreateAlloca(Builder.getInt32Ty()); - AllocaInst *Var3 = Builder.CreateAlloca(Builder.getInt8Ty(), - Builder.getInt32(123)); - - CallInst *Start1 = Builder.CreateLifetimeStart(Var1); - CallInst *Start2 = Builder.CreateLifetimeStart(Var2); - CallInst *Start3 = Builder.CreateLifetimeStart(Var3, Builder.getInt64(100)); - - EXPECT_EQ(Start1->getArgOperand(0), Builder.getInt64(-1)); - EXPECT_EQ(Start2->getArgOperand(0), Builder.getInt64(-1)); - EXPECT_EQ(Start3->getArgOperand(0), Builder.getInt64(100)); - - EXPECT_EQ(Start1->getArgOperand(1), Var1); - EXPECT_NE(Start2->getArgOperand(1), Var2); - EXPECT_EQ(Start3->getArgOperand(1), Var3); - - Value *End1 = Builder.CreateLifetimeEnd(Var1); - Builder.CreateLifetimeEnd(Var2); - Builder.CreateLifetimeEnd(Var3); - - IntrinsicInst *II_Start1 = dyn_cast(Start1); - IntrinsicInst *II_End1 = dyn_cast(End1); - ASSERT_TRUE(II_Start1 != NULL); - EXPECT_EQ(II_Start1->getIntrinsicID(), Intrinsic::lifetime_start); - ASSERT_TRUE(II_End1 != NULL); - EXPECT_EQ(II_End1->getIntrinsicID(), Intrinsic::lifetime_end); -} - -} diff --git a/unittests/VMCore/CMakeLists.txt b/unittests/VMCore/CMakeLists.txt index b902930..632eab5 100644 --- a/unittests/VMCore/CMakeLists.txt +++ b/unittests/VMCore/CMakeLists.txt @@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS set(VMCoreSources ConstantsTest.cpp DominatorTreeTest.cpp + IRBuilderTest.cpp InstructionsTest.cpp MDBuilderTest.cpp MetadataTest.cpp diff --git a/unittests/VMCore/IRBuilderTest.cpp b/unittests/VMCore/IRBuilderTest.cpp new file mode 100644 index 0000000..9be3ab9 --- /dev/null +++ b/unittests/VMCore/IRBuilderTest.cpp @@ -0,0 +1,74 @@ +//===- llvm/unittest/VMCore/IRBuilderTest.cpp - IRBuilder tests -----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/BasicBlock.h" +#include "llvm/Function.h" +#include "llvm/IRBuilder.h" +#include "llvm/IntrinsicInst.h" +#include "llvm/LLVMContext.h" +#include "llvm/Module.h" +#include "llvm/ADT/OwningPtr.h" + +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +class IRBuilderTest : public testing::Test { +protected: + virtual void SetUp() { + M.reset(new Module("MyModule", getGlobalContext())); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(getGlobalContext()), + /*isVarArg=*/false); + Function *F = Function::Create(FTy, Function::ExternalLinkage, "", M.get()); + BB = BasicBlock::Create(getGlobalContext(), "", F); + } + + virtual void TearDown() { + BB = 0; + M.reset(); + } + + OwningPtr M; + BasicBlock *BB; +}; + +TEST_F(IRBuilderTest, Lifetime) { + IRBuilder<> Builder(BB); + AllocaInst *Var1 = Builder.CreateAlloca(Builder.getInt8Ty()); + AllocaInst *Var2 = Builder.CreateAlloca(Builder.getInt32Ty()); + AllocaInst *Var3 = Builder.CreateAlloca(Builder.getInt8Ty(), + Builder.getInt32(123)); + + CallInst *Start1 = Builder.CreateLifetimeStart(Var1); + CallInst *Start2 = Builder.CreateLifetimeStart(Var2); + CallInst *Start3 = Builder.CreateLifetimeStart(Var3, Builder.getInt64(100)); + + EXPECT_EQ(Start1->getArgOperand(0), Builder.getInt64(-1)); + EXPECT_EQ(Start2->getArgOperand(0), Builder.getInt64(-1)); + EXPECT_EQ(Start3->getArgOperand(0), Builder.getInt64(100)); + + EXPECT_EQ(Start1->getArgOperand(1), Var1); + EXPECT_NE(Start2->getArgOperand(1), Var2); + EXPECT_EQ(Start3->getArgOperand(1), Var3); + + Value *End1 = Builder.CreateLifetimeEnd(Var1); + Builder.CreateLifetimeEnd(Var2); + Builder.CreateLifetimeEnd(Var3); + + IntrinsicInst *II_Start1 = dyn_cast(Start1); + IntrinsicInst *II_End1 = dyn_cast(End1); + ASSERT_TRUE(II_Start1 != NULL); + EXPECT_EQ(II_Start1->getIntrinsicID(), Intrinsic::lifetime_start); + ASSERT_TRUE(II_End1 != NULL); + EXPECT_EQ(II_End1->getIntrinsicID(), Intrinsic::lifetime_end); +} + +} -- cgit v1.1