[cfe-commits] r39717 - in /cfe/cfe/trunk: AST/Type.cpp Sema/Sema.h Sema/SemaExpr.cpp include/clang/AST/Type.h include/clang/Basic/DiagnosticKinds.def

Steve Naroff snaroff at apple.com
Wed Jul 11 09:47:29 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:47:29 2007
New Revision: 39717

URL: http://llvm.org/viewvc/llvm-project?rev=39717&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Typechecking support for vectors...

- Added CheckVectorOperands(). Called from CheckAdditionOperands,
CheckMultiplyDivideOperands, CheckSubstractionOperands, and CheckBitwiseOperands.
- Added diagnostic for converting vector values of different size.
- Modified Type::isArithmeticType to include vectors.

Sould be ready for Chris to add code generation. I will continue testing/refining.

Modified:
    cfe/cfe/trunk/AST/Type.cpp
    cfe/cfe/trunk/Sema/Sema.h
    cfe/cfe/trunk/Sema/SemaExpr.cpp
    cfe/cfe/trunk/include/clang/AST/Type.h
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

Modified: cfe/cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Type.cpp?rev=39717&r1=39716&r2=39717&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Type.cpp (original)
+++ cfe/cfe/trunk/AST/Type.cpp Wed Jul 11 11:47:29 2007
@@ -279,13 +279,17 @@
   return isa<ComplexType>(CanonicalType);
 }
 
+bool Type::isVectorType() const {
+  return isa<VectorType>(CanonicalType);
+}
+
 bool Type::isArithmeticType() const {
   if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
     return BT->getKind() != BuiltinType::Void;
   if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
     if (TT->getDecl()->getKind() == Decl::Enum)
       return true;
-  return isa<ComplexType>(CanonicalType);
+  return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType);
 }
 
 bool Type::isScalarType() const {

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

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:47:29 2007
@@ -303,6 +303,7 @@
     
   /// type checking binary operators (subroutines of ParseBinOp).
   inline void InvalidOperands(SourceLocation l, Expr *lex, Expr *rex);
+  inline QualType CheckVectorOperands(SourceLocation l, Expr *lex, Expr *rex);
   inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
     Expr *lex, Expr *rex, SourceLocation OpLoc); 
   inline QualType CheckRemainderOperands( // C99 6.5.5

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:47:29 2007
@@ -703,9 +703,11 @@
   // expressions that surpress this implicit conversion (&, sizeof).
   rhsType = DefaultFunctionArrayConversion(rhsType);
     
-  if (lhsType->isArithmeticType() && rhsType->isArithmeticType())
+  if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) {
+    if (lhsType->isVectorType() || rhsType->isVectorType())
+      return lhsType == rhsType ? Compatible : Incompatible;
     return Compatible;
-  else if (lhsType->isPointerType()) {
+  } else if (lhsType->isPointerType()) {
     if (rhsType->isIntegerType())
       return PointerFromInt;
       
@@ -734,10 +736,27 @@
        lex->getSourceRange(), rex->getSourceRange());
 }
 
+inline QualType Sema::CheckVectorOperands(SourceLocation loc, Expr *lex, 
+                                                              Expr *rex) {
+  QualType lhsType = lex->getType(), rhsType = rex->getType();
+  
+  // make sure the vector types are identical. 
+  if (lhsType == rhsType)
+    return lhsType;
+  // You cannot convert between vector values of different size.
+  Diag(loc, diag::err_typecheck_vector_not_convertable, 
+       lex->getType().getAsString(), rex->getType().getAsString(),
+       lex->getSourceRange(), rex->getSourceRange());
+  return QualType();
+}    
+
 inline QualType Sema::CheckMultiplyDivideOperands(
   Expr *lex, Expr *rex, SourceLocation loc) 
 {
   QualType lhsType = lex->getType(), rhsType = rex->getType();
+  
+  if (lhsType->isVectorType() || rhsType->isVectorType())
+    return CheckVectorOperands(loc, lex, rex);
   QualType resType = UsualArithmeticConversions(lhsType, rhsType);
   
   if (resType->isArithmeticType())
@@ -762,6 +781,9 @@
   Expr *lex, Expr *rex, SourceLocation loc) 
 {
   QualType lhsType = lex->getType(), rhsType = rex->getType();
+
+  if (lhsType->isVectorType() || rhsType->isVectorType())
+    return CheckVectorOperands(loc, lex, rex);    
   QualType resType = UsualArithmeticConversions(lhsType, rhsType);
 
   // handle the common case first (both operands are arithmetic).
@@ -779,6 +801,9 @@
   Expr *lex, Expr *rex, SourceLocation loc) 
 {
   QualType lhsType = lex->getType(), rhsType = rex->getType();
+
+  if (lhsType->isVectorType() || rhsType->isVectorType())
+    return CheckVectorOperands(loc, lex, rex);
   QualType resType = UsualArithmeticConversions(lhsType, rhsType);
   
   // handle the common case first (both operands are arithmetic).
@@ -869,6 +894,9 @@
   Expr *lex, Expr *rex, SourceLocation loc) 
 {
   QualType lhsType = lex->getType(), rhsType = rex->getType();
+  
+  if (lhsType->isVectorType() || rhsType->isVectorType())
+    return CheckVectorOperands(loc, lex, rex);
   QualType resType = UsualArithmeticConversions(lhsType, rhsType);
   
   if (resType->isIntegerType())

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

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Type.h Wed Jul 11 11:47:29 2007
@@ -227,6 +227,9 @@
   bool isRealType() const;         // C99 6.2.5p17 (real floating + integer)
   bool isArithmeticType() const;   // C99 6.2.5p18 (integer + floating)
   
+  /// Vector types
+  bool isVectorType() const;       // GCC vector type.
+  
   /// Derived types (C99 6.2.5p20). isFunctionType() is also a derived type.
   bool isDerivedType() const;
   bool isPointerType() const;

Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39717&r1=39716&r2=39717&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:47:29 2007
@@ -439,6 +439,8 @@
      "vector size not an integral multiple of component size")
 DIAG(err_attribute_zero_size, ERROR,
      "zero vector size")
+DIAG(err_typecheck_vector_not_convertable, ERROR,
+     "can't convert between vector values of different size ('%0' and '%1')")
 
 // Function Parameter Semantic Analysis.
 DIAG(err_void_param_with_identifier, ERROR,





More information about the cfe-commits mailing list