#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
#include "gtest/gtest.h"
namespace llvm {
namespace {
TEST(ConstantsTest, Integer_i1) {
- const IntegerType* Int1 = IntegerType::get(1);
+ IntegerType* Int1 = IntegerType::get(getGlobalContext(), 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);
+ EXPECT_EQ(NegOne, ConstantInt::getSigned(Int1, -1));
Constant* Undef = UndefValue::get(Int1);
// Input: @b = constant i1 add(i1 1 , i1 1)
EXPECT_EQ(Zero, ConstantExpr::getSRem(One, NegOne));
}
+TEST(ConstantsTest, IntSigns) {
+ IntegerType* Int8Ty = Type::getInt8Ty(getGlobalContext());
+ 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());
+
+ // Overflow is handled by truncation.
+ EXPECT_EQ(0x3b, ConstantInt::get(Int8Ty, 0x13b)->getSExtValue());
+}
+
+TEST(ConstantsTest, FP128Test) {
+ Type *FP128Ty = Type::getFP128Ty(getGlobalContext());
+
+ IntegerType *Int128Ty = Type::getIntNTy(getGlobalContext(), 128);
+ Constant *Zero128 = Constant::getNullValue(Int128Ty);
+ Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty);
+ EXPECT_TRUE(isa<ConstantFP>(X));
+}
+
} // end anonymous namespace
} // end namespace llvm