Assert that VectorType::getTruncatedElementVectorType is not used with
authorBob Wilson <bob.wilson@apple.com>
Wed, 7 Jan 2009 23:44:27 +0000 (23:44 +0000)
committerBob Wilson <bob.wilson@apple.com>
Wed, 7 Jan 2009 23:44:27 +0000 (23:44 +0000)
odd bit-width vector elements.  Add a check in the verifier for this also.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61899 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DerivedTypes.h
lib/VMCore/Verifier.cpp

index 3bc00e9bb25aa9821b9dba52e33c7c9c5cc47ead..24681a51f8403189680d2578d20357b56b5fcf40 100644 (file)
@@ -385,6 +385,8 @@ public:
   ///
   static VectorType *getTruncatedElementVectorType(const VectorType *VTy) {
     unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
+    assert((EltBits & 1) == 0 &&
+           "Cannot truncate vector element with odd bit-width");
     const Type *EltTy = IntegerType::get(EltBits / 2);
     return VectorType::get(EltTy, VTy->getNumElements());
   }
index 4a7915430eec9383efe9ec3d758e58ca14d56dd3..f9ad41b2c42131325efb2e374ff6744b00c75a89 100644 (file)
@@ -1395,16 +1395,22 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
     // type.
     if ((Match & (ExtendedElementVectorType |
                   TruncatedElementVectorType)) != 0) {
-      if (!VTy) {
+      const IntegerType *IEltTy = dyn_cast<IntegerType>(EltTy);
+      if (!VTy || !IEltTy) {
         CheckFailed("Intrinsic parameter #" + utostr(ArgNo - 1) + " is not "
-                    "a vector type.", F);
+                    "an integral vector type.", F);
         return false;
       }
       // Adjust the current Ty (in the opposite direction) rather than
       // the type being matched against.
-      if ((Match & ExtendedElementVectorType) != 0)
+      if ((Match & ExtendedElementVectorType) != 0) {
+        if ((IEltTy->getBitWidth() & 1) != 0) {
+          CheckFailed("Intrinsic parameter #" + utostr(ArgNo - 1) + " vector "
+                      "element bit-width is odd.", F);
+          return false;
+        }
         Ty = VectorType::getTruncatedElementVectorType(VTy);
-      else
+      else
         Ty = VectorType::getExtendedElementVectorType(VTy);
       Match &= ~(ExtendedElementVectorType | TruncatedElementVectorType);
     }