Author: Benjamin Maxwell Date: 2025-12-05T10:16:32Z New Revision: 8ce5d8545d2e79e8bac5e6c6c39ef2d0f8c54181
URL: https://github.com/llvm/llvm-project/commit/8ce5d8545d2e79e8bac5e6c6c39ef2d0f8c54181 DIFF: https://github.com/llvm/llvm-project/commit/8ce5d8545d2e79e8bac5e6c6c39ef2d0f8c54181.diff LOG: [clang] Only use CheckVectorOperands for fixed-length vector operands (#170485) Fixes #170279 Added: Modified: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Sema/SemaExprCXX.cpp clang/test/Sema/AArch64/sve-vector-conditional-op.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4fbdb9dd6cc15..e931de0b32352 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -8672,7 +8672,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}">; diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 69719ebd1fc8c..a117947bb7a75 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -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> { @@ -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 {}; } @@ -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); diff --git a/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp b/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp index 0ca55e6268658..7fa4ce872036b 100644 --- a/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp +++ b/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp @@ -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) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
