summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2016-05-21 00:14:04 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2016-05-21 00:14:04 +0000
commit2907e51246a8cf0a440fa1767f94dc10eda195eb (patch)
tree2d881318e120ee033cd3c1b26d0bbbdeba5afee4 /llvm/unittests/IR
parentbe8e2e0fa8076d6d6c9e1c4f84a1edd2949192dd (diff)
downloadbcm5719-llvm-2907e51246a8cf0a440fa1767f94dc10eda195eb.tar.gz
bcm5719-llvm-2907e51246a8cf0a440fa1767f94dc10eda195eb.zip
Fix constant folding of addrspacecast of null
This should not be making assumptions on the value of the casted pointer. llvm-svn: 270293
Diffstat (limited to 'llvm/unittests/IR')
-rw-r--r--llvm/unittests/IR/ConstantsTest.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp
index 39ae18ca5e0..6959ac85e49 100644
--- a/llvm/unittests/IR/ConstantsTest.cpp
+++ b/llvm/unittests/IR/ConstantsTest.cpp
@@ -155,6 +155,27 @@ TEST(ConstantsTest, PointerCast) {
EXPECT_EQ(Constant::getNullValue(Int32PtrVecTy),
ConstantExpr::getPointerCast(
Constant::getNullValue(Int8PtrVecTy), Int32PtrVecTy));
+
+ Type *Int32Ptr1Ty = Type::getInt32PtrTy(C, 1);
+ ConstantInt *K = ConstantInt::get(Type::getInt64Ty(C), 1234);
+
+ // Make sure that addrspacecast of inttoptr is not folded away.
+ EXPECT_NE(K,
+ ConstantExpr::getAddrSpaceCast(
+ ConstantExpr::getIntToPtr(K, Int32PtrTy), Int32Ptr1Ty));
+ EXPECT_NE(K,
+ ConstantExpr::getAddrSpaceCast(
+ ConstantExpr::getIntToPtr(K, Int32Ptr1Ty), Int32PtrTy));
+
+ Constant *NullInt32Ptr0 = Constant::getNullValue(Int32PtrTy);
+ Constant *NullInt32Ptr1 = Constant::getNullValue(Int32Ptr1Ty);
+
+ // Make sure that addrspacecast of null is not folded away.
+ EXPECT_NE(Constant::getNullValue(Int32PtrTy),
+ ConstantExpr::getAddrSpaceCast(NullInt32Ptr0, Int32Ptr1Ty));
+
+ EXPECT_NE(Constant::getNullValue(Int32Ptr1Ty),
+ ConstantExpr::getAddrSpaceCast(NullInt32Ptr1, Int32PtrTy));
}
#define CHECK(x, y) { \
OpenPOWER on IntegriCloud