Skip to content

Conversation

@MacDue
Copy link
Member

@MacDue MacDue commented Dec 3, 2025

Fixes #170279

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Dec 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 3, 2025

@llvm/pr-subscribers-clang

Author: Benjamin Maxwell (MacDue)

Changes

Fixes #170279


Full diff: https://github.com/llvm/llvm-project/pull/170485.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaExpr.cpp (+5)
  • (modified) clang/test/Sema/AArch64/sve-vector-conditional-op.cpp (+10)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index cfabd1b76c103..b74f4b00a2d46 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10363,6 +10363,11 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
   QualType LHSType = LHS.get()->getType().getUnqualifiedType();
   QualType RHSType = RHS.get()->getType().getUnqualifiedType();
 
+  // Bail out if either vector is "sizeless". This is only supported in
+  // CheckSizelessVectorOperands.
+  if (LHSType->isSizelessVectorType() || RHSType->isSizelessVectorType())
+    return InvalidOperands(Loc, LHS, RHS);
+
   const VectorType *LHSVecType = LHSType->getAs<VectorType>();
   const VectorType *RHSVecType = RHSType->getAs<VectorType>();
   assert(LHSVecType || RHSVecType);
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) {

@github-actions
Copy link

github-actions bot commented Dec 3, 2025

🐧 Linux x64 Test Results

  • 111767 tests passed
  • 4477 tests skipped

✅ The build succeeded and all tests passed.

@MacDue MacDue marked this pull request as draft December 3, 2025 14:59
@MacDue MacDue changed the title [clang] Check (and disallow) "sizeless" vector types in CheckVectorOperands [clang] Only use CheckVectorOperands for fixed-length vector operands Dec 3, 2025
}

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')}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These diagnostics are pretty hard to understand.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not changed the second error (that was already present), but I agree. I'll see if a more appropriate message already exists. If not, I'll add one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reworked both error messages (by extending an existing error) 👍

@MacDue MacDue marked this pull request as ready for review December 3, 2025 23:28
Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MacDue MacDue merged commit 8ce5d85 into llvm:main Dec 5, 2025
10 checks passed
@MacDue MacDue deleted the fix_check branch December 5, 2025 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AArch64][SVE] crashes when applying ternary operator to SVE and GNU vector types

3 participants