summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2012-10-30 16:03:32 +0000
committerDuncan Sands <baldrick@free.fr>2012-10-30 16:03:32 +0000
commit446cf94cdbbc1f8e22452fc46664ac73d810c6a2 (patch)
tree81ecaa52ec11d25214b1ee28cfafa3543fddc94e /unittests
parent92b469971e6125e1aae90c43e0f00a5cb1e88b47 (diff)
downloadllvm-446cf94cdbbc1f8e22452fc46664ac73d810c6a2.tar.gz
llvm-446cf94cdbbc1f8e22452fc46664ac73d810c6a2.tar.bz2
llvm-446cf94cdbbc1f8e22452fc46664ac73d810c6a2.tar.xz
Fix isEliminableCastPair to work correctly in the presence of pointers
with different sizes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167018 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/VMCore/InstructionsTest.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp
index 4cadc36f8f..a3b13ce92d 100644
--- a/unittests/VMCore/InstructionsTest.cpp
+++ b/unittests/VMCore/InstructionsTest.cpp
@@ -243,5 +243,42 @@ TEST(InstructionsTest, FPMathOperator) {
delete I;
}
+
+TEST(InstructionsTest, isEliminableCastPair) {
+ LLVMContext &C(getGlobalContext());
+
+ Type* Int32Ty = Type::getInt32Ty(C);
+ Type* Int64Ty = Type::getInt64Ty(C);
+ Type* Int64PtrTy = Type::getInt64PtrTy(C);
+
+ // Source and destination pointers have same size -> bitcast.
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::PtrToInt,
+ CastInst::IntToPtr,
+ Int64PtrTy, Int64Ty, Int64PtrTy,
+ Int32Ty, 0, Int32Ty),
+ CastInst::BitCast);
+
+ // Source and destination pointers have different sizes -> fail.
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::PtrToInt,
+ CastInst::IntToPtr,
+ Int64PtrTy, Int64Ty, Int64PtrTy,
+ Int32Ty, 0, Int64Ty),
+ 0U);
+
+ // Middle pointer big enough -> bitcast.
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
+ CastInst::PtrToInt,
+ Int64Ty, Int64PtrTy, Int64Ty,
+ 0, Int64Ty, 0),
+ CastInst::BitCast);
+
+ // Middle pointer too small -> fail.
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
+ CastInst::PtrToInt,
+ Int64Ty, Int64PtrTy, Int64Ty,
+ 0, Int32Ty, 0),
+ 0U);
+}
+
} // end anonymous namespace
} // end namespace llvm