diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-04-14 21:59:01 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-04-14 21:59:01 +0000 |
commit | 03b42e41bf4bdd9ab05ea4c6905bae5d19971960 (patch) | |
tree | d4249845a564b11af673299653e7c4e876d8c4f2 /llvm/unittests/IR/InstructionsTest.cpp | |
parent | 3d1c1deb04efe0022f11ebc18bb43d7341ba0c75 (diff) | |
download | bcm5719-llvm-03b42e41bf4bdd9ab05ea4c6905bae5d19971960.tar.gz bcm5719-llvm-03b42e41bf4bdd9ab05ea4c6905bae5d19971960.zip |
Remove every uses of getGlobalContext() in LLVM (but the C API)
At the same time, fixes InstructionsTest::CastInst unittest: yes
you can leave the IR in an invalid state and exit when you don't
destroy the context (like the global one), no longer now.
This is the first part of http://reviews.llvm.org/D19094
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266379
Diffstat (limited to 'llvm/unittests/IR/InstructionsTest.cpp')
-rw-r--r-- | llvm/unittests/IR/InstructionsTest.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp index cfc55b05ab9..0dac7c1bcfb 100644 --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/unittests/IR/InstructionsTest.cpp @@ -27,7 +27,7 @@ namespace llvm { namespace { TEST(InstructionsTest, ReturnInst) { - LLVMContext &C(getGlobalContext()); + LLVMContext C; // test for PR6589 const ReturnInst* r0 = ReturnInst::Create(C); @@ -103,7 +103,7 @@ TEST_F(ModuleWithFunctionTest, InvokeInst) { } TEST(InstructionsTest, BranchInst) { - LLVMContext &C(getGlobalContext()); + LLVMContext C; // Make a BasicBlocks BasicBlock* bb0 = BasicBlock::Create(C); @@ -169,7 +169,7 @@ TEST(InstructionsTest, BranchInst) { } TEST(InstructionsTest, CastInst) { - LLVMContext &C(getGlobalContext()); + LLVMContext C; Type *Int8Ty = Type::getInt8Ty(C); Type *Int16Ty = Type::getInt16Ty(C); @@ -281,14 +281,18 @@ TEST(InstructionsTest, CastInst) { // First form BasicBlock *BB = BasicBlock::Create(C); Constant *NullV2I32Ptr = Constant::getNullValue(V2Int32PtrTy); - CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty, "foo", BB); + auto Inst1 = CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty, "foo", BB); // Second form - CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty); + auto Inst2 = CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty); + + delete Inst2; + Inst1->eraseFromParent(); + delete BB; } TEST(InstructionsTest, VectorGep) { - LLVMContext &C(getGlobalContext()); + LLVMContext C; // Type Definitions Type *I8Ty = IntegerType::get(C, 8); @@ -391,7 +395,7 @@ TEST(InstructionsTest, VectorGep) { } TEST(InstructionsTest, FPMathOperator) { - LLVMContext &Context = getGlobalContext(); + LLVMContext Context; IRBuilder<> Builder(Context); MDBuilder MDHelper(Context); Instruction *I = Builder.CreatePHI(Builder.getDoubleTy(), 0); @@ -406,7 +410,7 @@ TEST(InstructionsTest, FPMathOperator) { TEST(InstructionsTest, isEliminableCastPair) { - LLVMContext &C(getGlobalContext()); + LLVMContext C; Type* Int16Ty = Type::getInt16Ty(C); Type* Int32Ty = Type::getInt32Ty(C); @@ -486,7 +490,7 @@ TEST(InstructionsTest, isEliminableCastPair) { } TEST(InstructionsTest, CloneCall) { - LLVMContext &C(getGlobalContext()); + LLVMContext C; Type *Int32Ty = Type::getInt32Ty(C); Type *ArgTys[] = {Int32Ty, Int32Ty, Int32Ty}; Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false); @@ -519,7 +523,7 @@ TEST(InstructionsTest, CloneCall) { } TEST(InstructionsTest, AlterCallBundles) { - LLVMContext &C(getGlobalContext()); + LLVMContext C; Type *Int32Ty = Type::getInt32Ty(C); Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false); Value *Callee = Constant::getNullValue(FnTy->getPointerTo()); @@ -546,7 +550,7 @@ TEST(InstructionsTest, AlterCallBundles) { } TEST(InstructionsTest, AlterInvokeBundles) { - LLVMContext &C(getGlobalContext()); + LLVMContext C; Type *Int32Ty = Type::getInt32Ty(C); Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false); Value *Callee = Constant::getNullValue(FnTy->getPointerTo()); |