Skip to content

Commit 3e55858

Browse files
committed
[clang] Only use CheckVectorOperands for fixed-length vector operands
Fixes #170279
1 parent f83f6f5 commit 3e55858

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5724,12 +5724,14 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
57245724
ResultType = CheckSizelessVectorOperands(LHS, RHS, QuestionLoc,
57255725
/*IsCompAssign*/ false,
57265726
ArithConvKind::Conditional);
5727-
else
5727+
else if (LHSType->isVectorType() || LHSType->isVectorType())
57285728
ResultType = CheckVectorOperands(
57295729
LHS, RHS, QuestionLoc, /*isCompAssign*/ false, /*AllowBothBool*/ true,
57305730
/*AllowBoolConversions*/ false,
57315731
/*AllowBoolOperation*/ true,
57325732
/*ReportInvalid*/ true);
5733+
else
5734+
return InvalidOperands(QuestionLoc, LHS, RHS);
57335735
if (ResultType.isNull())
57345736
return {};
57355737
} else {

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 {{invalid operands to binary expression ('unsigned char' and '__SVUint8_t')}}
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 convert between vector and non-scalar values ('unsigned char' and 'fixed_vector' (vector of 1 'int' value))}}
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)