Skip to content

Commit fb691fc

Browse files
committed
[clang] Check (and disallow) "sizeless" vector types in CheckVectorOperands
Fixes #170279
1 parent f83f6f5 commit fb691fc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10363,6 +10363,11 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
1036310363
QualType LHSType = LHS.get()->getType().getUnqualifiedType();
1036410364
QualType RHSType = RHS.get()->getType().getUnqualifiedType();
1036510365

10366+
// Bail out if either vector is "sizeless". This is only supported in
10367+
// CheckSizelessVectorOperands.
10368+
if (LHSType->isSizelessVectorType() || RHSType->isSizelessVectorType())
10369+
return InvalidOperands(Loc, LHS, RHS);
10370+
1036610371
const VectorType *LHSVecType = LHSType->getAs<VectorType>();
1036710372
const VectorType *RHSVecType = RHSType->getAs<VectorType>();
1036810373
assert(LHSVecType || RHSVecType);

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)