Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -8671,7 +8671,7 @@ def err_conditional_vector_has_void : Error<
def err_conditional_vector_operand_type
: Error<"enumeration type %0 is not allowed in a vector conditional">;
def err_conditional_vector_cond_result_mismatch
: Error<"cannot mix vectors and extended vectors in a vector conditional">;
: Error<"cannot mix vectors and %select{sizeless|extended}0 vectors in a vector conditional">;
def err_conditional_vector_mismatched
: Error<"vector operands to the vector conditional must be the same type "
"%diff{($ and $)|}0,1}">;
Expand Down
16 changes: 12 additions & 4 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5689,8 +5689,10 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
QualType LHSType = LHS.get()->getType();
QualType RHSType = RHS.get()->getType();

bool LHSIsVector = LHSType->isVectorType() || LHSType->isSizelessVectorType();
bool RHSIsVector = RHSType->isVectorType() || RHSType->isSizelessVectorType();
bool LHSSizelessVector = LHSType->isSizelessVectorType();
bool RHSSizelessVector = RHSType->isSizelessVectorType();
bool LHSIsVector = LHSType->isVectorType() || LHSSizelessVector;
bool RHSIsVector = RHSType->isVectorType() || RHSSizelessVector;

auto GetVectorInfo =
[&](QualType Type) -> std::pair<QualType, llvm::ElementCount> {
Expand All @@ -5708,7 +5710,7 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
if (LHSIsVector && RHSIsVector) {
if (CondType->isExtVectorType() != LHSType->isExtVectorType()) {
Diag(QuestionLoc, diag::err_conditional_vector_cond_result_mismatch)
<< /*isExtVector*/ CondType->isExtVectorType();
<< /*isExtVectorNotSizeless=*/1;
return {};
}

Expand All @@ -5720,7 +5722,13 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
}
ResultType = Context.getCommonSugaredType(LHSType, RHSType);
} else if (LHSIsVector || RHSIsVector) {
if (CondType->isSizelessVectorType())
bool ResultSizeless = LHSSizelessVector || RHSSizelessVector;
if (ResultSizeless != CondType->isSizelessVectorType()) {
Diag(QuestionLoc, diag::err_conditional_vector_cond_result_mismatch)
<< /*isExtVectorNotSizeless=*/0;
return {};
}
if (ResultSizeless)
ResultType = CheckSizelessVectorOperands(LHS, RHS, QuestionLoc,
/*IsCompAssign*/ false,
ArithConvKind::Conditional);
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Sema/AArch64/sve-vector-conditional-op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ auto error_sve_vector_result_matched_element_count(__SVBool_t svbool, __SVUint32
return svbool ? a : b;
}

auto error_fixed_cond_mixed_scalar_and_vector_operands(fixed_vector cond, unsigned char a, __SVUint8_t b) {
// expected-error@+1 {{cannot mix vectors and sizeless vectors in a vector conditional}}
return cond ? a : b;
}

auto error_scalable_cond_mixed_scalar_and_vector_operands(__SVBool_t svbool, unsigned char a, fixed_vector b) {
// expected-error@+1 {{cannot mix vectors and sizeless vectors in a vector conditional}}
return svbool ? a : b;
}

// The following cases should be supported:

__SVBool_t cond_svbool(__SVBool_t a, __SVBool_t b) {
Expand Down
Loading