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/ConstantsTest.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/ConstantsTest.cpp')
-rw-r--r-- | llvm/unittests/IR/ConstantsTest.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp index 7471584097d..39ae18ca5e0 100644 --- a/llvm/unittests/IR/ConstantsTest.cpp +++ b/llvm/unittests/IR/ConstantsTest.cpp @@ -22,7 +22,8 @@ namespace llvm { namespace { TEST(ConstantsTest, Integer_i1) { - IntegerType* Int1 = IntegerType::get(getGlobalContext(), 1); + LLVMContext Context; + IntegerType *Int1 = IntegerType::get(Context, 1); Constant* One = ConstantInt::get(Int1, 1, true); Constant* Zero = ConstantInt::get(Int1, 0); Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true); @@ -103,7 +104,8 @@ TEST(ConstantsTest, Integer_i1) { } TEST(ConstantsTest, IntSigns) { - IntegerType* Int8Ty = Type::getInt8Ty(getGlobalContext()); + LLVMContext Context; + IntegerType *Int8Ty = Type::getInt8Ty(Context); EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, false)->getSExtValue()); EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, true)->getSExtValue()); EXPECT_EQ(100, ConstantInt::getSigned(Int8Ty, 100)->getSExtValue()); @@ -116,16 +118,17 @@ TEST(ConstantsTest, IntSigns) { } TEST(ConstantsTest, FP128Test) { - Type *FP128Ty = Type::getFP128Ty(getGlobalContext()); + LLVMContext Context; + Type *FP128Ty = Type::getFP128Ty(Context); - IntegerType *Int128Ty = Type::getIntNTy(getGlobalContext(), 128); + IntegerType *Int128Ty = Type::getIntNTy(Context, 128); Constant *Zero128 = Constant::getNullValue(Int128Ty); Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty); EXPECT_TRUE(isa<ConstantFP>(X)); } TEST(ConstantsTest, PointerCast) { - LLVMContext &C(getGlobalContext()); + LLVMContext C; Type *Int8PtrTy = Type::getInt8PtrTy(C); Type *Int32PtrTy = Type::getInt32PtrTy(C); Type *Int64Ty = Type::getInt64Ty(C); @@ -165,14 +168,15 @@ TEST(ConstantsTest, PointerCast) { } TEST(ConstantsTest, AsInstructionsTest) { - std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext())); + LLVMContext Context; + std::unique_ptr<Module> M(new Module("MyModule", Context)); - Type *Int64Ty = Type::getInt64Ty(getGlobalContext()); - Type *Int32Ty = Type::getInt32Ty(getGlobalContext()); - Type *Int16Ty = Type::getInt16Ty(getGlobalContext()); - Type *Int1Ty = Type::getInt1Ty(getGlobalContext()); - Type *FloatTy = Type::getFloatTy(getGlobalContext()); - Type *DoubleTy = Type::getDoubleTy(getGlobalContext()); + Type *Int64Ty = Type::getInt64Ty(Context); + Type *Int32Ty = Type::getInt32Ty(Context); + Type *Int16Ty = Type::getInt16Ty(Context); + Type *Int1Ty = Type::getInt1Ty(Context); + Type *FloatTy = Type::getFloatTy(Context); + Type *DoubleTy = Type::getDoubleTy(Context); Constant *Global = M->getOrInsertGlobal("dummy", PointerType::getUnqual(Int32Ty)); @@ -189,8 +193,7 @@ TEST(ConstantsTest, AsInstructionsTest) { Constant *One = ConstantInt::get(Int32Ty, 1); Constant *Two = ConstantInt::get(Int64Ty, 2); - Constant *Big = ConstantInt::get(getGlobalContext(), - APInt{256, uint64_t(-1), true}); + Constant *Big = ConstantInt::get(Context, APInt{256, uint64_t(-1), true}); Constant *Elt = ConstantInt::get(Int16Ty, 2015); Constant *Undef16 = UndefValue::get(Int16Ty); Constant *Undef64 = UndefValue::get(Int64Ty); @@ -278,9 +281,10 @@ TEST(ConstantsTest, AsInstructionsTest) { #ifdef GTEST_HAS_DEATH_TEST #ifndef NDEBUG TEST(ConstantsTest, ReplaceWithConstantTest) { - std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext())); + LLVMContext Context; + std::unique_ptr<Module> M(new Module("MyModule", Context)); - Type *Int32Ty = Type::getInt32Ty(getGlobalContext()); + Type *Int32Ty = Type::getInt32Ty(Context); Constant *One = ConstantInt::get(Int32Ty, 1); Constant *Global = |