[cfe-commits] r84245 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Sema/Sema.h lib/Sema/SemaExpr.cpp

Anders Carlsson andersca at mac.com
Thu Oct 15 22:23:41 PDT 2009


Author: andersca
Date: Fri Oct 16 00:23:41 2009
New Revision: 84245

URL: http://llvm.org/viewvc/llvm-project?rev=84245&view=rev
Log:
Add CK_VectorSplat and use it for casting non-pointer scalars to ExtVectors.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=84245&r1=84244&r2=84245&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Oct 16 00:23:41 2009
@@ -1402,7 +1402,12 @@
     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:

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=84245&r1=84244&r2=84245&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Oct 16 00:23:41 2009
@@ -428,6 +428,8 @@
     return "PointerToIntegral";
   case CastExpr::CK_ToVoid:
     return "ToVoid";
+  case CastExpr::CK_VectorSplat:
+    return "VectorSplat";
   }
 
   assert(0 && "Unhandled cast kind!");

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=84245&r1=84244&r2=84245&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Oct 16 00:23:41 2009
@@ -3669,7 +3669,8 @@
   // 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.

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=84245&r1=84244&r2=84245&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Oct 16 00:23:41 2009
@@ -3205,11 +3205,9 @@
       << 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 @@
   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 @@
                   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 @@
   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 @@
     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;
 }
 





More information about the cfe-commits mailing list