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
}

llvm-svn: 39728
This commit is contained in:
Steve Naroff 2007-07-10 22:20:04 +00:00
parent c14236b8ae
commit e728ba3504
2 changed files with 9 additions and 3 deletions

View File

@ -195,13 +195,17 @@ Expr::isLvalueResult Expr::isLvalue() {
// 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()))

View File

@ -709,8 +709,10 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
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())