diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2011-05-21 23:14:36 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2011-05-21 23:14:36 +0000 |
commit | 0cf51561eddd659a7b427f40144e22363fd95a57 (patch) | |
tree | a66609b096578e6bd62f2c9cc5e6e292bcdcb8bc /unittests/Support | |
parent | d22920aae81ec318404f7c5235c634954d966cf6 (diff) |
Add CreateLifetimeStart and CreateLifetimeEnd to the IRBuilder, with plans to
use these soon.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131812 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Support')
-rw-r--r-- | unittests/Support/IRBuilderTest.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/unittests/Support/IRBuilderTest.cpp b/unittests/Support/IRBuilderTest.cpp new file mode 100644 index 0000000000..5d635ae361 --- /dev/null +++ b/unittests/Support/IRBuilderTest.cpp @@ -0,0 +1,70 @@ +//===- 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/Support/IRBuilder.h" +#include "llvm/BasicBlock.h" +#include "llvm/Function.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; + +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<Module> 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<IntrinsicInst>(Start1); + IntrinsicInst *II_End1 = dyn_cast<IntrinsicInst>(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); +} |