Skip to content

Commit 8ce5d85

Browse files
authored
[clang] Only use CheckVectorOperands for fixed-length vector operands (#170485)
Fixes #170279
1 parent 2317347 commit 8ce5d85

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8672,7 +8672,7 @@ def err_conditional_vector_has_void : Error<
86728672
def err_conditional_vector_operand_type
86738673
: Error<"enumeration type %0 is not allowed in a vector conditional">;
86748674
def err_conditional_vector_cond_result_mismatch
8675-
: Error<"cannot mix vectors and extended vectors in a vector conditional">;
8675+
: Error<"cannot mix vectors and %select{sizeless|extended}0 vectors in a vector conditional">;
86768676
def err_conditional_vector_mismatched
86778677
: Error<"vector operands to the vector conditional must be the same type "
86788678
"%diff{($ and $)|}0,1}">;

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5689,8 +5689,10 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
56895689
QualType LHSType = LHS.get()->getType();
56905690
QualType RHSType = RHS.get()->getType();
56915691

5692-
bool LHSIsVector = LHSType->isVectorType() || LHSType->isSizelessVectorType();
5693-
bool RHSIsVector = RHSType->isVectorType() || RHSType->isSizelessVectorType();
5692+
bool LHSSizelessVector = LHSType->isSizelessVectorType();
5693+
bool RHSSizelessVector = RHSType->isSizelessVectorType();
5694+
bool LHSIsVector = LHSType->isVectorType() || LHSSizelessVector;
5695+
bool RHSIsVector = RHSType->isVectorType() || RHSSizelessVector;
56945696

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

@@ -5720,7 +5722,13 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
57205722
}
57215723
ResultType = Context.getCommonSugaredType(LHSType, RHSType);
57225724
} else if (LHSIsVector || RHSIsVector) {
5723-
if (CondType->isSizelessVectorType())
5725+
bool ResultSizeless = LHSSizelessVector || RHSSizelessVector;
5726+
if (ResultSizeless != CondType->isSizelessVectorType()) {
5727+
Diag(QuestionLoc, diag::err_conditional_vector_cond_result_mismatch)
5728+
<< /*isExtVectorNotSizeless=*/0;
5729+
return {};
5730+
}
5731+
if (ResultSizeless)
57245732
ResultType = CheckSizelessVectorOperands(LHS, RHS, QuestionLoc,
57255733
/*IsCompAssign*/ false,
57265734
ArithConvKind::Conditional);

clang/test/Sema/AArch64/sve-vector-conditional-op.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ auto error_sve_vector_result_matched_element_count(__SVBool_t svbool, __SVUint32
2222
return svbool ? a : b;
2323
}
2424

25+
auto error_fixed_cond_mixed_scalar_and_vector_operands(fixed_vector cond, unsigned char a, __SVUint8_t b) {
26+
// expected-error@+1 {{cannot mix vectors and sizeless vectors in a vector conditional}}
27+
return cond ? a : b;
28+
}
29+
30+
auto error_scalable_cond_mixed_scalar_and_vector_operands(__SVBool_t svbool, unsigned char a, fixed_vector b) {
31+
// expected-error@+1 {{cannot mix vectors and sizeless vectors in a vector conditional}}
32+
return svbool ? a : b;
33+
}
34+
2535
// The following cases should be supported:
2636

2737
__SVBool_t cond_svbool(__SVBool_t a, __SVBool_t b) {

0 commit comments

Comments
 (0)