[IR Verifier] Do not allow bitcast of pointer to vector of pointers and vice versa.
LangRef for BitCast requires that
"The bit sizes of value and the destination type, ty2, must be identical".
Currently verifier allows BitCast of pointer to vector of pointers so that
the sizes are different.
This change fixes that.
Reviewers: arsenm
Reviewed By: arsenm
Subscribers: llvm-commits, wdng
Differential Revision: https://reviews.llvm.org/D50886
llvm-svn: 340249
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 32db918..d8470ac 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -2978,12 +2978,14 @@
return false;
// A vector of pointers must have the same number of elements.
- if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
- if (VectorType *DstVecTy = dyn_cast<VectorType>(DstTy))
- return (SrcVecTy->getNumElements() == DstVecTy->getNumElements());
-
- return false;
- }
+ VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy);
+ VectorType *DstVecTy = dyn_cast<VectorType>(DstTy);
+ if (SrcVecTy && DstVecTy)
+ return (SrcVecTy->getNumElements() == DstVecTy->getNumElements());
+ if (SrcVecTy)
+ return SrcVecTy->getNumElements() == 1;
+ if (DstVecTy)
+ return DstVecTy->getNumElements() == 1;
return true;
}