Bug 18228 - Fix accepting bitcasts between vectors of pointers with a

different number of elements.

Bitcasts were passing with vectors of pointers with different number of
elements since the number of elements was checking
SrcTy->getVectorNumElements() == SrcTy->getVectorNumElements() which
isn't helpful. The addrspacecast was also wrong, but that case at least
is caught by the verifier. Refactor bitcast and addrspacecast handling
in castIsValid to be more readable and fix this problem.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199821 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matt Arsenault
2014-01-22 19:21:33 +00:00
parent 148c7f286c
commit 79e3fb53d6
3 changed files with 63 additions and 15 deletions

View File

@ -145,6 +145,7 @@ TEST(InstructionsTest, CastInst) {
Type *V2Int64PtrTy = VectorType::get(Int64PtrTy, 2);
Type *V2Int32PtrTy = VectorType::get(Int32PtrTy, 2);
Type *V4Int32PtrTy = VectorType::get(Int32PtrTy, 4);
const Constant* c8 = Constant::getNullValue(V8x8Ty);
const Constant* c64 = Constant::getNullValue(V8x64Ty);
@ -205,6 +206,21 @@ TEST(InstructionsTest, CastInst) {
EXPECT_FALSE(CastInst::isBitCastable(V2Int64Ty, V2Int32Ty));
EXPECT_FALSE(CastInst::castIsValid(Instruction::BitCast,
Constant::getNullValue(V4Int32PtrTy),
V2Int32PtrTy));
EXPECT_FALSE(CastInst::castIsValid(Instruction::BitCast,
Constant::getNullValue(V2Int32PtrTy),
V4Int32PtrTy));
EXPECT_FALSE(CastInst::castIsValid(Instruction::AddrSpaceCast,
Constant::getNullValue(V4Int32PtrAS1Ty),
V2Int32PtrTy));
EXPECT_FALSE(CastInst::castIsValid(Instruction::AddrSpaceCast,
Constant::getNullValue(V2Int32PtrTy),
V4Int32PtrAS1Ty));
// Check that assertion is not hit when creating a cast with a vector of
// pointers
// First form