From 6084326c3c39e65f1ce42099296571334d653c88 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 14 Jul 2009 01:26:26 +0000 Subject: Port this unittest to use LLVMContext. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75583 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/VMCore/ConstantsTest.cpp | 63 ++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/unittests/VMCore/ConstantsTest.cpp b/unittests/VMCore/ConstantsTest.cpp index 519d928eac..aaf3d2703e 100644 --- a/unittests/VMCore/ConstantsTest.cpp +++ b/unittests/VMCore/ConstantsTest.cpp @@ -9,6 +9,7 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "gtest/gtest.h" namespace llvm { @@ -16,96 +17,98 @@ namespace { TEST(ConstantsTest, Integer_i1) { const IntegerType* Int1 = IntegerType::get(1); - Constant* One = ConstantInt::get(Int1, 1, true); - Constant* Zero = ConstantInt::get(Int1, 0); - Constant* NegOne = ConstantInt::get(Int1, static_cast(-1), true); - EXPECT_EQ(NegOne, ConstantInt::getSigned(Int1, -1)); - Constant* Undef = UndefValue::get(Int1); + Constant* One = getGlobalContext().getConstantInt(Int1, 1, true); + Constant* Zero = getGlobalContext().getConstantInt(Int1, 0); + Constant* NegOne = + getGlobalContext().getConstantInt(Int1, static_cast(-1), true); + EXPECT_EQ(NegOne, getGlobalContext().getConstantIntSigned(Int1, -1)); + Constant* Undef = getGlobalContext().getUndef(Int1); // Input: @b = constant i1 add(i1 1 , i1 1) // Output: @b = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getAdd(One, One)); + EXPECT_EQ(Zero, getGlobalContext().getConstantExprAdd(One, One)); // @c = constant i1 add(i1 -1, i1 1) // @c = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, One)); + EXPECT_EQ(Zero, getGlobalContext().getConstantExprAdd(NegOne, One)); // @d = constant i1 add(i1 -1, i1 -1) // @d = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, NegOne)); + EXPECT_EQ(Zero, getGlobalContext().getConstantExprAdd(NegOne, NegOne)); // @e = constant i1 sub(i1 -1, i1 1) // @e = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSub(NegOne, One)); + EXPECT_EQ(Zero, getGlobalContext().getConstantExprSub(NegOne, One)); // @f = constant i1 sub(i1 1 , i1 -1) // @f = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSub(One, NegOne)); + EXPECT_EQ(Zero, getGlobalContext().getConstantExprSub(One, NegOne)); // @g = constant i1 sub(i1 1 , i1 1) // @g = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSub(One, One)); + EXPECT_EQ(Zero, getGlobalContext().getConstantExprSub(One, One)); // @h = constant i1 shl(i1 1 , i1 1) ; undefined // @h = constant i1 undef - EXPECT_EQ(Undef, ConstantExpr::getShl(One, One)); + EXPECT_EQ(Undef, getGlobalContext().getConstantExprShl(One, One)); // @i = constant i1 shl(i1 1 , i1 0) // @i = constant i1 true - EXPECT_EQ(One, ConstantExpr::getShl(One, Zero)); + EXPECT_EQ(One, getGlobalContext().getConstantExprShl(One, Zero)); // @j = constant i1 lshr(i1 1, i1 1) ; undefined // @j = constant i1 undef - EXPECT_EQ(Undef, ConstantExpr::getLShr(One, One)); + EXPECT_EQ(Undef, getGlobalContext().getConstantExprLShr(One, One)); // @m = constant i1 ashr(i1 1, i1 1) ; undefined // @m = constant i1 undef - EXPECT_EQ(Undef, ConstantExpr::getAShr(One, One)); + EXPECT_EQ(Undef, getGlobalContext().getConstantExprAShr(One, One)); // @n = constant i1 mul(i1 -1, i1 1) // @n = constant i1 true - EXPECT_EQ(One, ConstantExpr::getMul(NegOne, One)); + EXPECT_EQ(One, getGlobalContext().getConstantExprMul(NegOne, One)); // @o = constant i1 sdiv(i1 -1, i1 1) ; overflow // @o = constant i1 true - EXPECT_EQ(One, ConstantExpr::getSDiv(NegOne, One)); + EXPECT_EQ(One, getGlobalContext().getConstantExprSDiv(NegOne, One)); // @p = constant i1 sdiv(i1 1 , i1 -1); overflow // @p = constant i1 true - EXPECT_EQ(One, ConstantExpr::getSDiv(One, NegOne)); + EXPECT_EQ(One, getGlobalContext().getConstantExprSDiv(One, NegOne)); // @q = constant i1 udiv(i1 -1, i1 1) // @q = constant i1 true - EXPECT_EQ(One, ConstantExpr::getUDiv(NegOne, One)); + EXPECT_EQ(One, getGlobalContext().getConstantExprUDiv(NegOne, One)); // @r = constant i1 udiv(i1 1, i1 -1) // @r = constant i1 true - EXPECT_EQ(One, ConstantExpr::getUDiv(One, NegOne)); + EXPECT_EQ(One, getGlobalContext().getConstantExprUDiv(One, NegOne)); // @s = constant i1 srem(i1 -1, i1 1) ; overflow // @s = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSRem(NegOne, One)); + EXPECT_EQ(Zero, getGlobalContext().getConstantExprSRem(NegOne, One)); // @t = constant i1 urem(i1 -1, i1 1) // @t = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getURem(NegOne, One)); + EXPECT_EQ(Zero, getGlobalContext().getConstantExprURem(NegOne, One)); // @u = constant i1 srem(i1 1, i1 -1) ; overflow // @u = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSRem(One, NegOne)); + EXPECT_EQ(Zero, getGlobalContext().getConstantExprSRem(One, NegOne)); } TEST(ConstantsTest, IntSigns) { const IntegerType* Int8Ty = Type::Int8Ty; - 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()); - EXPECT_EQ(-50, ConstantInt::get(Int8Ty, 206)->getSExtValue()); - EXPECT_EQ(-50, ConstantInt::getSigned(Int8Ty, -50)->getSExtValue()); - EXPECT_EQ(206U, ConstantInt::getSigned(Int8Ty, -50)->getZExtValue()); + LLVMContext &Context = getGlobalContext(); + EXPECT_EQ(100, Context.getConstantInt(Int8Ty, 100, false)->getSExtValue()); + EXPECT_EQ(100, Context.getConstantInt(Int8Ty, 100, true)->getSExtValue()); + EXPECT_EQ(100, Context.getConstantIntSigned(Int8Ty, 100)->getSExtValue()); + EXPECT_EQ(-50, Context.getConstantInt(Int8Ty, 206)->getSExtValue()); + EXPECT_EQ(-50, Context.getConstantIntSigned(Int8Ty, -50)->getSExtValue()); + EXPECT_EQ(206U, Context.getConstantIntSigned(Int8Ty, -50)->getZExtValue()); // Overflow is handled by truncation. - EXPECT_EQ(0x3b, ConstantInt::get(Int8Ty, 0x13b)->getSExtValue()); + EXPECT_EQ(0x3b, Context.getConstantInt(Int8Ty, 0x13b)->getSExtValue()); } } // end anonymous namespace -- cgit v1.2.3