forked from OSchip/llvm-project
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 } llvm-svn: 39728
This commit is contained in:
parent
c14236b8ae
commit
e728ba3504
|
@ -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()))
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue