[cfe-commits] r39723 - /cfe/cfe/trunk/Sema/SemaExpr.cpp

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


Author: snaroff
Date: Wed Jul 11 11:47:33 2007
New Revision: 39723

URL: http://llvm.org/viewvc/llvm-project?rev=39723&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Support the following...

1. Type checking and codegen support for V[i] on vectors. Hacked
Sema::ParseArraySubscriptExpr().

2. Unary bitwise complement ("~") on vectors. Hacked Sema::ParseUnaryOp().

Modified:
    cfe/cfe/trunk/Sema/SemaExpr.cpp

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:47:33 2007
@@ -294,7 +294,7 @@
   
   Expr *baseExpr, *indexExpr;
   QualType baseType, indexType;
-  if (isa<PointerType>(canonT1)) {
+  if (isa<PointerType>(canonT1) || isa<VectorType>(canonT1)) {
     baseType = canonT1;
     indexType = canonT2;
     baseExpr = static_cast<Expr *>(Base);
@@ -314,16 +314,20 @@
     return Diag(indexExpr->getLocStart(), diag::err_typecheck_subscript,
                 indexExpr->getSourceRange());
   }
-  // FIXME: need to deal with const...
-  PointerType *ary = cast<PointerType>(baseType);
-  QualType resultType = ary->getPointeeType();
-  // in practice, the following check catches trying to index a pointer
-  // to a function (e.g. void (*)(int)). Functions are not objects in c99.
-  if (!resultType->isObjectType()) {
-    return Diag(baseExpr->getLocStart(), 
-                diag::err_typecheck_subscript_not_object,
-                baseType.getAsString(), baseExpr->getSourceRange());
-  }
+  QualType resultType;
+  if (PointerType *ary = dyn_cast<PointerType>(baseType)) {
+    // FIXME: need to deal with const...
+    resultType = ary->getPointeeType();
+    // in practice, the following check catches trying to index a pointer
+    // to a function (e.g. void (*)(int)). Functions are not objects in c99.
+    if (!resultType->isObjectType()) {
+      return Diag(baseExpr->getLocStart(), 
+                  diag::err_typecheck_subscript_not_object,
+                  baseType.getAsString(), baseExpr->getSourceRange());
+    }
+  } else if (VectorType *vec = dyn_cast<VectorType>(baseType))
+    resultType = vec->getElementType();
+
   return new ArraySubscriptExpr((Expr*)Base, (Expr*)Idx, resultType, RLoc);
 }
 
@@ -1306,10 +1310,14 @@
                   resultType.getAsString());
     break;
   case UnaryOperator::Not: // bitwise complement
-    resultType = UsualUnaryConversions(Input->getType());
-    if (!resultType->isIntegerType())  // C99 6.5.3.3p1
-      return Diag(OpLoc, diag::err_typecheck_unary_expr,
-                  resultType.getAsString());
+    if (Input->getType()->isVectorType())
+      resultType = Input->getType();
+    else {
+      resultType = UsualUnaryConversions(Input->getType());
+      if (!resultType->isIntegerType())  // C99 6.5.3.3p1
+        return Diag(OpLoc, diag::err_typecheck_unary_expr,
+                    resultType.getAsString());
+    }
     break;
   case UnaryOperator::LNot: // logical negation
     // Unlike +/-/~, integer promotions aren't done here (C99 6.5.3.3p5).





More information about the cfe-commits mailing list