Skip to content

Commit 133a5f2

Browse files
committed
[clang][AArch64][SVE] Improve diagnostics for SVE operators
This patch corrects some diagnostics for the SVE sizeless vector operators, including correctly diagnosing when the vectors are different sizes. Differential Revision: https://reviews.llvm.org/D126377
1 parent 1fd0bea commit 133a5f2

File tree

5 files changed

+1436
-1656
lines changed

5 files changed

+1436
-1656
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10578,10 +10578,13 @@ QualType Sema::CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS,
1057810578
QualType LHSType = LHS.get()->getType().getUnqualifiedType();
1057910579
QualType RHSType = RHS.get()->getType().getUnqualifiedType();
1058010580

10581+
const BuiltinType *LHSBuiltinTy = LHSType->getAs<BuiltinType>();
10582+
const BuiltinType *RHSBuiltinTy = RHSType->getAs<BuiltinType>();
10583+
1058110584
unsigned DiagID = diag::err_typecheck_invalid_operands;
1058210585
if ((OperationKind == ACK_Arithmetic) &&
10583-
(LHSType->castAs<BuiltinType>()->isSVEBool() ||
10584-
RHSType->castAs<BuiltinType>()->isSVEBool())) {
10586+
((LHSBuiltinTy && LHSBuiltinTy->isSVEBool()) ||
10587+
(RHSBuiltinTy && RHSBuiltinTy->isSVEBool()))) {
1058510588
Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange()
1058610589
<< RHS.get()->getSourceRange();
1058710590
return QualType();
@@ -10610,12 +10613,33 @@ QualType Sema::CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS,
1061010613
return DestType;
1061110614
}
1061210615

10613-
if (RHSType->isVLSTBuiltinType() && !LHSType->isVLSTBuiltinType()) {
10614-
auto DestType = tryScalableVectorConvert((IsCompAssign ? nullptr : &LHS),
10615-
LHSType, RHSType);
10616-
if (DestType == QualType())
10617-
return InvalidOperands(Loc, LHS, RHS);
10618-
return DestType;
10616+
if ((!LHSType->isVLSTBuiltinType() && !LHSType->isRealType()) ||
10617+
(!RHSType->isVLSTBuiltinType() && !RHSType->isRealType())) {
10618+
Diag(Loc, diag::err_typecheck_vector_not_convertable_non_scalar)
10619+
<< LHSType << RHSType << LHS.get()->getSourceRange()
10620+
<< RHS.get()->getSourceRange();
10621+
return QualType();
10622+
}
10623+
10624+
if (LHSType->isVLSTBuiltinType() && RHSType->isVLSTBuiltinType() &&
10625+
Context.getBuiltinVectorTypeInfo(LHSBuiltinTy).EC !=
10626+
Context.getBuiltinVectorTypeInfo(RHSBuiltinTy).EC) {
10627+
Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
10628+
<< LHSType << RHSType << LHS.get()->getSourceRange()
10629+
<< RHS.get()->getSourceRange();
10630+
return QualType();
10631+
}
10632+
10633+
if (LHSType->isVLSTBuiltinType() || RHSType->isVLSTBuiltinType()) {
10634+
QualType Scalar = LHSType->isVLSTBuiltinType() ? RHSType : LHSType;
10635+
QualType Vector = LHSType->isVLSTBuiltinType() ? LHSType : RHSType;
10636+
bool ScalarOrVector =
10637+
LHSType->isVLSTBuiltinType() && RHSType->isVLSTBuiltinType();
10638+
10639+
Diag(Loc, diag::err_typecheck_vector_not_convertable_implict_truncation)
10640+
<< ScalarOrVector << Scalar << Vector;
10641+
10642+
return QualType();
1061910643
}
1062010644

1062110645
Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange()

0 commit comments

Comments
 (0)