]> granicus.if.org Git - clang/commitdiff
Add CK_VectorSplat and use it for casting non-pointer scalars to ExtVectors.
authorAnders Carlsson <andersca@mac.com>
Fri, 16 Oct 2009 05:23:41 +0000 (05:23 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 16 Oct 2009 05:23:41 +0000 (05:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84245 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/AST/Expr.cpp
lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp

index 67f493c47cc95d75623439b926e1116597552ae7..fb87ed631acb9c1ed40b2de9873a3a68d6af897d 100644 (file)
@@ -1402,7 +1402,12 @@ public:
     CK_PointerToIntegral,
     
     /// CK_ToVoid - Cast to void.
-    CK_ToVoid
+    CK_ToVoid,
+    
+    /// CK_VectorSplat - Casting from an integer/floating type to an extended
+    /// vector type with the same element type as the src type. Splats the 
+    /// src expression into the destionation expression.
+    CK_VectorSplat
   };
 
 private:
index fa999ffe35d36e14b5e17c3da1ef3a923da06e88..547854bb616fe1bd73683e4cf78fd8be3ba91fe3 100644 (file)
@@ -428,6 +428,8 @@ const char *CastExpr::getCastKindName() const {
     return "PointerToIntegral";
   case CastExpr::CK_ToVoid:
     return "ToVoid";
+  case CastExpr::CK_VectorSplat:
+    return "VectorSplat";
   }
 
   assert(0 && "Unhandled cast kind!");
index 8de4bec6bd9120ec030b8c7f1e5c5324b9386c76..398b413e265ad1421226913e37bc3b86ff3df5b6 100644 (file)
@@ -3669,7 +3669,8 @@ public:
   // We allow casting between vectors and integer datatypes of the same size,
   // or vectors and the element type of that vector.
   // returns true if the cast is invalid
-  bool CheckExtVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
+  bool CheckExtVectorCast(SourceRange R, QualType VectorTy, Expr *&CastExpr,
+                          CastExpr::CastKind &Kind);
 
   /// CXXCheckCStyleCast - Check constraints of a C-style or function-style
   /// cast under C++ semantics.
index b9983853984e330376a5c97266a3d9ca7ddad077..67058860d6de2c86e9f6d50a1e53640a0a4efcfd 100644 (file)
@@ -3205,11 +3205,9 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr,
       << castExpr->getType() << castExpr->getSourceRange();
   }
   
-  if (castType->isExtVectorType()) {
-    // FIXME: Set the cast kind.
-    return CheckExtVectorCast(TyR, castType, castExpr->getType());
-  }
-
+  if (castType->isExtVectorType()) 
+    return CheckExtVectorCast(TyR, castType, castExpr, Kind);
+  
   if (castType->isVectorType())
     return CheckVectorCast(TyR, castType, castExpr->getType(), Kind);
   if (castExpr->getType()->isVectorType())
@@ -3218,6 +3216,9 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr,
   if (getLangOptions().ObjC1 && isa<ObjCSuperExpr>(castExpr))
     return Diag(castExpr->getLocStart(), diag::err_illegal_super_cast) << TyR;
   
+  if (isa<ObjCSelectorExpr>(castExpr))
+    return Diag(castExpr->getLocStart(), diag::err_cast_selector_expr);
+  
   if (!castType->isArithmeticType()) {
     QualType castExprType = castExpr->getType();
     if (!castExprType->isIntegralType() && castExprType->isArithmeticType())
@@ -3230,8 +3231,7 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr,
                   diag::err_cast_pointer_to_non_pointer_int)
         << castType << castExpr->getSourceRange();
   }
-  if (isa<ObjCSelectorExpr>(castExpr))
-    return Diag(castExpr->getLocStart(), diag::err_cast_selector_expr);
+  
   return false;
 }
 
@@ -3255,15 +3255,19 @@ bool Sema::CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty,
   return false;
 }
 
-bool Sema::CheckExtVectorCast(SourceRange R, QualType DestTy, QualType SrcTy) {
+bool Sema::CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *&CastExpr, 
+                              CastExpr::CastKind &Kind) {
   assert(DestTy->isExtVectorType() && "Not an extended vector type!");
-
+  
+  QualType SrcTy = CastExpr->getType();
+  
   // If SrcTy is a VectorType, the total size must match to explicitly cast to
   // an ExtVectorType.
   if (SrcTy->isVectorType()) {
     if (Context.getTypeSize(DestTy) != Context.getTypeSize(SrcTy))
       return Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
         << DestTy << SrcTy << R;
+    Kind = CastExpr::CK_BitCast;
     return false;
   }
 
@@ -3274,6 +3278,11 @@ bool Sema::CheckExtVectorCast(SourceRange R, QualType DestTy, QualType SrcTy) {
     return Diag(R.getBegin(),
                 diag::err_invalid_conversion_between_vector_and_scalar)
       << DestTy << SrcTy << R;
+  
+  // FIXME: Pass a cast kind to the implicit cast expr.
+  ImpCastExprToType(CastExpr, DestTy->getAs<ExtVectorType>()->getElementType());
+  
+  Kind = CastExpr::CK_VectorSplat;
   return false;
 }