summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-11-15 09:34:33 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-11-15 09:34:33 +0000
commit4da02d43b1981f8be6f3b64ae42161fb3f918a8d (patch)
treeda8f52643263c110073cb17b1763076b70d1e6e3 /unittests
parent868e74bdce7a2c49d60e2ef56a077b0aa7f2ba08 (diff)
downloadexternal_llvm-4da02d43b1981f8be6f3b64ae42161fb3f918a8d.zip
external_llvm-4da02d43b1981f8be6f3b64ae42161fb3f918a8d.tar.gz
external_llvm-4da02d43b1981f8be6f3b64ae42161fb3f918a8d.tar.bz2
Give unit test its own LLVMContext so MDNodes aren't leaked even if we never call llvm_shutdown.
Found by valgrind. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194797 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/IR/IRBuilderTest.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp
index c01d49c..2f390f7 100644
--- a/unittests/IR/IRBuilderTest.cpp
+++ b/unittests/IR/IRBuilderTest.cpp
@@ -25,12 +25,12 @@ namespace {
class IRBuilderTest : public testing::Test {
protected:
virtual void SetUp() {
- M.reset(new Module("MyModule", getGlobalContext()));
- FunctionType *FTy = FunctionType::get(Type::getVoidTy(getGlobalContext()),
+ M.reset(new Module("MyModule", Ctx));
+ FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
/*isVarArg=*/false);
F = Function::Create(FTy, Function::ExternalLinkage, "", M.get());
- BB = BasicBlock::Create(getGlobalContext(), "", F);
- GV = new GlobalVariable(*M, Type::getFloatTy(getGlobalContext()), true,
+ BB = BasicBlock::Create(Ctx, "", F);
+ GV = new GlobalVariable(*M, Type::getFloatTy(Ctx), true,
GlobalValue::ExternalLinkage, 0);
}
@@ -39,6 +39,7 @@ protected:
M.reset();
}
+ LLVMContext Ctx;
OwningPtr<Module> M;
Function *F;
BasicBlock *BB;
@@ -78,8 +79,8 @@ TEST_F(IRBuilderTest, Lifetime) {
TEST_F(IRBuilderTest, CreateCondBr) {
IRBuilder<> Builder(BB);
- BasicBlock *TBB = BasicBlock::Create(getGlobalContext(), "", F);
- BasicBlock *FBB = BasicBlock::Create(getGlobalContext(), "", F);
+ BasicBlock *TBB = BasicBlock::Create(Ctx, "", F);
+ BasicBlock *FBB = BasicBlock::Create(Ctx, "", F);
BranchInst *BI = Builder.CreateCondBr(Builder.getTrue(), TBB, FBB);
TerminatorInst *TI = BB->getTerminator();
@@ -89,7 +90,7 @@ TEST_F(IRBuilderTest, CreateCondBr) {
EXPECT_EQ(FBB, TI->getSuccessor(1));
BI->eraseFromParent();
- MDNode *Weights = MDBuilder(getGlobalContext()).createBranchWeights(42, 13);
+ MDNode *Weights = MDBuilder(Ctx).createBranchWeights(42, 13);
BI = Builder.CreateCondBr(Builder.getTrue(), TBB, FBB, Weights);
TI = BB->getTerminator();
EXPECT_EQ(BI, TI);
@@ -109,12 +110,12 @@ TEST_F(IRBuilderTest, LandingPadName) {
TEST_F(IRBuilderTest, GetIntTy) {
IRBuilder<> Builder(BB);
IntegerType *Ty1 = Builder.getInt1Ty();
- EXPECT_EQ(Ty1, IntegerType::get(getGlobalContext(), 1));
+ EXPECT_EQ(Ty1, IntegerType::get(Ctx, 1));
DataLayout* DL = new DataLayout(M.get());
IntegerType *IntPtrTy = Builder.getIntPtrTy(DL);
unsigned IntPtrBitSize = DL->getPointerSizeInBits(0);
- EXPECT_EQ(IntPtrTy, IntegerType::get(getGlobalContext(), IntPtrBitSize));
+ EXPECT_EQ(IntPtrTy, IntegerType::get(Ctx, IntPtrBitSize));
delete DL;
}