[PATCH] Fix ptr vector inconsistency in CreatePointerCast

Eli Friedman eli.friedman at gmail.com
Tue Jul 30 17:04:57 PDT 2013


LGTM.

-Eli

On Tue, Jul 30, 2013 at 5:02 PM, Matt Arsenault
<Matthew.Arsenault at amd.com> wrote:
> 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.
>
> http://llvm-reviews.chandlerc.com/D1240
>
> Files:
>   lib/IR/Instructions.cpp
>   unittests/IR/InstructionsTest.cpp
>
> Index: lib/IR/Instructions.cpp
> ===================================================================
> --- lib/IR/Instructions.cpp
> +++ lib/IR/Instructions.cpp
> @@ -2415,22 +2415,30 @@
>  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);
>  }
>
>  /// @brief Create a BitCast or a PtrToInt cast instruction
> -CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty,
> -                                      const Twine &Name,
> +CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty,
> +                                      const Twine &Name,
>                                        Instruction *InsertBefore) {
>    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);
> Index: unittests/IR/InstructionsTest.cpp
> ===================================================================
> --- unittests/IR/InstructionsTest.cpp
> +++ unittests/IR/InstructionsTest.cpp
> @@ -197,6 +197,17 @@
>    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) {
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



More information about the llvm-commits mailing list