https://github.com/MacDue updated 
https://github.com/llvm/llvm-project/pull/170485

>From 3e55858c79df00e3e2890279fc9673cd33931f29 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <[email protected]>
Date: Wed, 3 Dec 2025 14:28:16 +0000
Subject: [PATCH 1/3] [clang] Only use CheckVectorOperands for fixed-length
 vector operands

Fixes #170279
---
 clang/lib/Sema/SemaExprCXX.cpp                        |  4 +++-
 clang/test/Sema/AArch64/sve-vector-conditional-op.cpp | 10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 69719ebd1fc8c..b5adc52a8450e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5724,12 +5724,14 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult 
&Cond, ExprResult &LHS,
       ResultType = CheckSizelessVectorOperands(LHS, RHS, QuestionLoc,
                                                /*IsCompAssign*/ false,
                                                ArithConvKind::Conditional);
-    else
+    else if (LHSType->isVectorType() || LHSType->isVectorType())
       ResultType = CheckVectorOperands(
           LHS, RHS, QuestionLoc, /*isCompAssign*/ false, /*AllowBothBool*/ 
true,
           /*AllowBoolConversions*/ false,
           /*AllowBoolOperation*/ true,
           /*ReportInvalid*/ true);
+    else
+      return InvalidOperands(QuestionLoc, LHS, RHS);
     if (ResultType.isNull())
       return {};
   } else {
diff --git a/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp 
b/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp
index 0ca55e6268658..cda995ece744c 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 {{invalid operands to binary expression ('unsigned 
char' and '__SVUint8_t')}}
+  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 convert between vector and non-scalar values 
('unsigned char' and 'fixed_vector' (vector of 1 'int' value))}}
+  return svbool ? a : b;
+}
+
 // The following cases should be supported:
 
 __SVBool_t cond_svbool(__SVBool_t a, __SVBool_t b) {

>From 5a25ee29730105e8593e4df5095de1764a3d0d91 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <[email protected]>
Date: Wed, 3 Dec 2025 16:29:42 +0000
Subject: [PATCH 2/3] Fix condition check for vector types in SemaExprCXX

---
 clang/lib/Sema/SemaExprCXX.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index b5adc52a8450e..ae59903ddc00e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5724,7 +5724,7 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult 
&Cond, ExprResult &LHS,
       ResultType = CheckSizelessVectorOperands(LHS, RHS, QuestionLoc,
                                                /*IsCompAssign*/ false,
                                                ArithConvKind::Conditional);
-    else if (LHSType->isVectorType() || LHSType->isVectorType())
+    else if (LHSType->isVectorType() || RHSType->isVectorType())
       ResultType = CheckVectorOperands(
           LHS, RHS, QuestionLoc, /*isCompAssign*/ false, /*AllowBothBool*/ 
true,
           /*AllowBoolConversions*/ false,

>From 77ce01f2fe5a633d09196342e7debd826282b546 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell <[email protected]>
Date: Thu, 4 Dec 2025 10:41:51 +0000
Subject: [PATCH 3/3] Rework error

---
 .../clang/Basic/DiagnosticSemaKinds.td        |  2 +-
 clang/lib/Sema/SemaExprCXX.cpp                | 20 ++++++++++++-------
 .../AArch64/sve-vector-conditional-op.cpp     |  4 ++--
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6b75976e9c38d..3ec218712f732 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -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}">;
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index ae59903ddc00e..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,18 +5722,22 @@ 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);
-    else if (LHSType->isVectorType() || RHSType->isVectorType())
+    else
       ResultType = CheckVectorOperands(
           LHS, RHS, QuestionLoc, /*isCompAssign*/ false, /*AllowBothBool*/ 
true,
           /*AllowBoolConversions*/ false,
           /*AllowBoolOperation*/ true,
           /*ReportInvalid*/ true);
-    else
-      return InvalidOperands(QuestionLoc, LHS, RHS);
     if (ResultType.isNull())
       return {};
   } else {
diff --git a/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp 
b/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp
index cda995ece744c..7fa4ce872036b 100644
--- a/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp
+++ b/clang/test/Sema/AArch64/sve-vector-conditional-op.cpp
@@ -23,12 +23,12 @@ auto 
error_sve_vector_result_matched_element_count(__SVBool_t svbool, __SVUint32
 }
 
 auto error_fixed_cond_mixed_scalar_and_vector_operands(fixed_vector cond, 
unsigned char a, __SVUint8_t b) {
-  // expected-error@+1 {{invalid operands to binary expression ('unsigned 
char' and '__SVUint8_t')}}
+  // 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 convert between vector and non-scalar values 
('unsigned char' and 'fixed_vector' (vector of 1 'int' value))}}
+  // expected-error@+1 {{cannot mix vectors and sizeless vectors in a vector 
conditional}}
   return svbool ? a : b;
 }
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to