summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/VMCore/InstructionsTest.cpp
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
commite2395dc27b1a1be758f6ff881257617c67d0d7ae (patch)
tree4d6babbb449f4300da63dc06b6046a45d25357a4 /llvm/unittests/VMCore/InstructionsTest.cpp
parent6fc3433b155f127c43f089f22b44461f91cb444a (diff)
downloadbcm5719-llvm-e2395dc27b1a1be758f6ff881257617c67d0d7ae.tar.gz
bcm5719-llvm-e2395dc27b1a1be758f6ff881257617c67d0d7ae.zip
Fix isEliminableCastPair to work correctly in the presence of pointers
with different sizes. llvm-svn: 167018
Diffstat (limited to 'llvm/unittests/VMCore/InstructionsTest.cpp')
-rw-r--r--llvm/unittests/VMCore/InstructionsTest.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/unittests/VMCore/InstructionsTest.cpp b/llvm/unittests/VMCore/InstructionsTest.cpp
index 4cadc36f8f0..a3b13ce92d1 100644
--- a/llvm/unittests/VMCore/InstructionsTest.cpp
+++ b/llvm/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
OpenPOWER on IntegriCloud