[cfe-commits] r39728 - in /cfe/cfe/trunk: AST/Expr.cpp Sema/SemaExpr.cpp

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


Author: snaroff
Date: Wed Jul 11 11:47:36 2007
New Revision: 39728

URL: http://llvm.org/viewvc/llvm-project?rev=39728&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Two vector fixes:

- Sema::CheckAssignmentConstraints() needs to compare the canonical type.
- Expr::isLvalue() needs to disallow subscripting into a vector returned by a function. This
follows the rules for struct returns (in C, at least...C++ is another story:-)

Here is an example...

float4 float4_return()
{
    float4 xx;

    return xx;
}
void add_float4_void_return(float4 *a, float4 *b, float4 *result)
{
    float f;
    float4_return()[1] = f; // now illegal
}

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

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

==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:47:36 2007
@@ -195,13 +195,17 @@
   // first, check the type (C99 6.3.2.1)
   if (isa<FunctionType>(TR.getCanonicalType())) // from isObjectType()
     return LV_NotObjectType;
+
   if (TR->isIncompleteType() && TR->isVoidType())
     return LV_IncompleteVoidType;
-  
+    
   // the type looks fine, now check the expression
   switch (getStmtClass()) {
   case StringLiteralClass: // C99 6.5.1p4
   case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2))))
+    // For vectors, make sure base is an lvalue (i.e. not a function call).
+    if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType())
+      return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue();
     return LV_Valid;
   case DeclRefExprClass: // C99 6.5.1p2
     if (isa<VarDecl>(cast<DeclRefExpr>(this)->getDecl()))

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

==============================================================================
--- cfe/cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaExpr.cpp Wed Jul 11 11:47:36 2007
@@ -709,8 +709,10 @@
   rhsType = DefaultFunctionArrayConversion(rhsType);
     
   if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) {
-    if (lhsType->isVectorType() || rhsType->isVectorType())
-      return lhsType == rhsType ? Compatible : Incompatible;
+    if (lhsType->isVectorType() || rhsType->isVectorType()) {
+      if (lhsType.getCanonicalType() != rhsType.getCanonicalType())
+        return Incompatible;
+    }
     return Compatible;
   } else if (lhsType->isPointerType()) {
     if (rhsType->isIntegerType())





More information about the cfe-commits mailing list