diff options
Diffstat (limited to 'gnu/llvm/unittests/IR/ConstantsTest.cpp')
-rw-r--r-- | gnu/llvm/unittests/IR/ConstantsTest.cpp | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/gnu/llvm/unittests/IR/ConstantsTest.cpp b/gnu/llvm/unittests/IR/ConstantsTest.cpp index 7471584097d..6959ac85e49 100644 --- a/gnu/llvm/unittests/IR/ConstantsTest.cpp +++ b/gnu/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); @@ -152,6 +155,27 @@ TEST(ConstantsTest, PointerCast) { EXPECT_EQ(Constant::getNullValue(Int32PtrVecTy), ConstantExpr::getPointerCast( Constant::getNullValue(Int8PtrVecTy), Int32PtrVecTy)); + + Type *Int32Ptr1Ty = Type::getInt32PtrTy(C, 1); + ConstantInt *K = ConstantInt::get(Type::getInt64Ty(C), 1234); + + // Make sure that addrspacecast of inttoptr is not folded away. + EXPECT_NE(K, + ConstantExpr::getAddrSpaceCast( + ConstantExpr::getIntToPtr(K, Int32PtrTy), Int32Ptr1Ty)); + EXPECT_NE(K, + ConstantExpr::getAddrSpaceCast( + ConstantExpr::getIntToPtr(K, Int32Ptr1Ty), Int32PtrTy)); + + Constant *NullInt32Ptr0 = Constant::getNullValue(Int32PtrTy); + Constant *NullInt32Ptr1 = Constant::getNullValue(Int32Ptr1Ty); + + // Make sure that addrspacecast of null is not folded away. + EXPECT_NE(Constant::getNullValue(Int32PtrTy), + ConstantExpr::getAddrSpaceCast(NullInt32Ptr0, Int32Ptr1Ty)); + + EXPECT_NE(Constant::getNullValue(Int32Ptr1Ty), + ConstantExpr::getAddrSpaceCast(NullInt32Ptr1, Int32PtrTy)); } #define CHECK(x, y) { \ @@ -165,14 +189,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 +214,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 +302,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 = |