Fix ptr vector inconsistency in CreatePointerCast

One form would accept a vector of pointers, and the other did not.
Make both accept vectors of pointers, and add an assertion
for the number of elements.

llvm-svn: 187464
This commit is contained in:
Matt Arsenault 2013-07-31 00:17:33 +00:00
parent 107b74c6c3
commit 065ced9bed
2 changed files with 24 additions and 5 deletions

View File

@ -2415,11 +2415,15 @@ CastInst *CastInst::CreateTruncOrBitCast(Value *S, Type *Ty,
CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty,
const Twine &Name,
BasicBlock *InsertAtEnd) {
assert(S->getType()->isPointerTy() && "Invalid cast");
assert((Ty->isIntegerTy() || Ty->isPointerTy()) &&
assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
"Invalid cast");
assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast");
assert(!Ty->isVectorTy() ||
Ty->getVectorNumElements() == S->getType()->getVectorNumElements() &&
"Invalid cast");
if (Ty->isIntegerTy())
if (Ty->isIntOrIntVectorTy())
return Create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
}
@ -2431,6 +2435,10 @@ CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty,
assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
"Invalid cast");
assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast");
assert(!Ty->isVectorTy() ||
Ty->getVectorNumElements() == S->getType()->getVectorNumElements() &&
"Invalid cast");
if (Ty->isIntOrIntVectorTy())
return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);

View File

@ -197,6 +197,17 @@ TEST(InstructionsTest, CastInst) {
EXPECT_TRUE(CastInst::isBitCastable(V2Int32PtrTy, V2Int64PtrTy));
EXPECT_FALSE(CastInst::isBitCastable(V2Int32Ty, V2Int64Ty));
EXPECT_FALSE(CastInst::isBitCastable(V2Int64Ty, V2Int32Ty));
// Check that assertion is not hit when creating a cast with a vector of
// pointers
// First form
BasicBlock *BB = BasicBlock::Create(C);
Constant *NullV2I32Ptr = Constant::getNullValue(V2Int32PtrTy);
CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty, "foo", BB);
// Second form
CastInst::CreatePointerCast(NullV2I32Ptr, V2Int32Ty);
}
TEST(InstructionsTest, VectorGep) {