diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-24 05:30:14 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-24 05:30:14 +0000 |
commit | f3b0aac1902d6e01ed9a633f4a93c26317b43835 (patch) | |
tree | 4ed9c157cdca2d8727cbd7171e89b85caebbc02f /unittests | |
parent | b706d29f9c5ed3ed9acc82f7ab46205ba56b92dc (diff) | |
download | external_llvm-f3b0aac1902d6e01ed9a633f4a93c26317b43835.zip external_llvm-f3b0aac1902d6e01ed9a633f4a93c26317b43835.tar.gz external_llvm-f3b0aac1902d6e01ed9a633f4a93c26317b43835.tar.bz2 |
"I got annoyed at the compiler warnings from ConstantInt::get(Ty, -1,
true), and casts make me nervous and are verbose anyway, so here's a
ConstantInt::getSigned(Ty, int64_t) method. Just overloading
ConstantInt::get() to take an int64_t too would cause ambiguous
overload errors."
Patch by Jeffrey Yasskin!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69958 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/VMCore/ConstantsTest.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/unittests/VMCore/ConstantsTest.cpp b/unittests/VMCore/ConstantsTest.cpp index c40dc7e..519d928 100644 --- a/unittests/VMCore/ConstantsTest.cpp +++ b/unittests/VMCore/ConstantsTest.cpp @@ -19,6 +19,7 @@ TEST(ConstantsTest, Integer_i1) { 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) @@ -94,5 +95,18 @@ TEST(ConstantsTest, Integer_i1) { EXPECT_EQ(Zero, ConstantExpr::getSRem(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()); + + // Overflow is handled by truncation. + EXPECT_EQ(0x3b, ConstantInt::get(Int8Ty, 0x13b)->getSExtValue()); +} + } // end anonymous namespace } // end namespace llvm |