llvm.org GIT mirror llvm / 655578f
Allow vectors in CreatePointerCast of constants. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172615 91177308-0d34-0410-b5e6-96231b3b80d8 Evgeniy Stepanov 6 years ago
2 changed file(s) with 35 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
14641464 }
14651465
14661466 Constant *ConstantExpr::getPointerCast(Constant *S, Type *Ty) {
1467 assert(S->getType()->isPointerTy() && "Invalid cast");
1468 assert((Ty->isIntegerTy() || Ty->isPointerTy()) && "Invalid cast");
1469
1470 if (Ty->isIntegerTy())
1467 assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
1468 assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
1469 "Invalid cast");
1470
1471 if (Ty->isIntOrIntVectorTy())
14711472 return getPtrToInt(S, Ty);
14721473 return getBitCast(S, Ty);
14731474 }
118118 Constant *Zero128 = Constant::getNullValue(Int128Ty);
119119 Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty);
120120 EXPECT_TRUE(isa(X));
121 }
122
123 TEST(ConstantsTest, PointerCast) {
124 LLVMContext &C(getGlobalContext());
125 Type *Int8PtrTy = Type::getInt8PtrTy(C);
126 Type *Int32PtrTy = Type::getInt32PtrTy(C);
127 Type *Int64Ty = Type::getInt64Ty(C);
128 VectorType *Int8PtrVecTy = VectorType::get(Int8PtrTy, 4);
129 VectorType *Int32PtrVecTy = VectorType::get(Int32PtrTy, 4);
130 VectorType *Int64VecTy = VectorType::get(Int64Ty, 4);
131
132 // ptrtoint i8* to i64
133 EXPECT_EQ(Constant::getNullValue(Int64Ty),
134 ConstantExpr::getPointerCast(
135 Constant::getNullValue(Int8PtrTy), Int64Ty));
136
137 // bitcast i8* to i32*
138 EXPECT_EQ(Constant::getNullValue(Int32PtrTy),
139 ConstantExpr::getPointerCast(
140 Constant::getNullValue(Int8PtrTy), Int32PtrTy));
141
142 // ptrtoint <4 x i8*> to <4 x i64>
143 EXPECT_EQ(Constant::getNullValue(Int64VecTy),
144 ConstantExpr::getPointerCast(
145 Constant::getNullValue(Int8PtrVecTy), Int64VecTy));
146
147 // bitcast <4 x i8*> to <4 x i32*>
148 EXPECT_EQ(Constant::getNullValue(Int32PtrVecTy),
149 ConstantExpr::getPointerCast(
150 Constant::getNullValue(Int8PtrVecTy), Int32PtrVecTy));
121151 }
122152
123153 #define CHECK(x, y) { \