https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/223768

>From b9cd662e7ba1b7ff09731648a80a8aa953c20196 Mon Sep 17 00:00:00 2001
From: Amr Hesham <[email protected]>
Date: Tue, 15 Sep 2026 09:59:13 +0200
Subject: [PATCH 1/2] [Clang][Sema] Improve shuffle vector size mismatch
 diagnostic

---
 clang/docs/ReleaseNotes.md                       | 3 +++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaChecking.cpp                  | 2 +-
 clang/test/SemaCXX/vector-shuffle.cpp            | 7 +++++++
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index f37bcda179c95f..4848bd8aa1b8f9 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -499,6 +499,9 @@ features cannot lower the translation-unit ABI level;
 
 - Clang now diagnoses matrix logical operations are only supported for HLSL. 
(GH222381)
 
+- Improve the input size mismatch diagnostic when calling 
`__builtin_shufflevector` with valid
+  vector element types but different sizes. (GH221791)
+
 ### Improvements to Clang's time-trace
 
 ### Improvements to Coverage Mapping
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fa9b748bda39ff..df5f7c6e40dd9b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11441,6 +11441,8 @@ def err_shufflevector_argument_too_large : Error<
   "of vector elements">;
 def err_shufflevector_minus_one_is_undefined_behavior_constexpr : Error<
   "index for __builtin_shufflevector not within the bounds of the input 
vectors; index of -1 found at position %0 is not permitted in a constexpr 
context">;
+def err_shufflevector_incompatible_vector : Error<
+  "first two arguments to __builtin_shufflevector must have the same number of 
elements">;
 
 def err_convertvector_non_vector : Error<
   "first argument to __builtin_convertvector must be a vector">;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ac333d5b666620..0e5b26c3ee5eac 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -6603,7 +6603,7 @@ ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
 
       if (RHSVecType->getNumElements() != NumElements)
         return ExprError(Diag(TheCall->getBeginLoc(),
-                              diag::err_vec_builtin_incompatible_vector)
+                              diag::err_shufflevector_incompatible_vector)
                          << TheCall->getDirectCallee()
                          << /*isMoreThanTwoArgs*/ false
                          << SourceRange(TheCall->getArg(1)->getBeginLoc(),
diff --git a/clang/test/SemaCXX/vector-shuffle.cpp 
b/clang/test/SemaCXX/vector-shuffle.cpp
index 7dbf375599998c..2393e02428216c 100644
--- a/clang/test/SemaCXX/vector-shuffle.cpp
+++ b/clang/test/SemaCXX/vector-shuffle.cpp
@@ -2,6 +2,7 @@
 
 typedef bool v8b __attribute__((ext_vector_type(8)));
 typedef float v8f __attribute__((ext_vector_type(8)));
+typedef int v6i __attribute__((ext_vector_type(6)));
 
 void vector_of_bool_mask() {
   v8b a;
@@ -14,3 +15,9 @@ void vector_of_float_mask() {
   v8f b;
   auto r = __builtin_shufflevector(a, b); // expected-error {{2nd argument 
must be a vector of integer types (was 'v8f' (vector of 8 'float' values))}}
 }
+
+void mask_vector_with_different_size() {
+  v8b a;
+  v6i b;
+  auto r = __builtin_shufflevector(a, b); // expected-error {{first two 
arguments to __builtin_shufflevector must have the same number of elements}}
+}

>From 911ffb10d9818e11a5c18d4ee6386f88d67f1b91 Mon Sep 17 00:00:00 2001
From: Amr Hesham <[email protected]>
Date: Tue, 15 Sep 2026 21:02:32 +0200
Subject: [PATCH 2/2] Use the more generic diagnostic

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 --
 clang/lib/Sema/SemaChecking.cpp                  | 5 ++---
 clang/test/SemaCXX/vector-shuffle.cpp            | 2 +-
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index df5f7c6e40dd9b..fa9b748bda39ff 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11441,8 +11441,6 @@ def err_shufflevector_argument_too_large : Error<
   "of vector elements">;
 def err_shufflevector_minus_one_is_undefined_behavior_constexpr : Error<
   "index for __builtin_shufflevector not within the bounds of the input 
vectors; index of -1 found at position %0 is not permitted in a constexpr 
context">;
-def err_shufflevector_incompatible_vector : Error<
-  "first two arguments to __builtin_shufflevector must have the same number of 
elements">;
 
 def err_convertvector_non_vector : Error<
   "first argument to __builtin_convertvector must be a vector">;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0e5b26c3ee5eac..13e54b17d58d09 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -6603,9 +6603,8 @@ ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
 
       if (RHSVecType->getNumElements() != NumElements)
         return ExprError(Diag(TheCall->getBeginLoc(),
-                              diag::err_shufflevector_incompatible_vector)
-                         << TheCall->getDirectCallee()
-                         << /*isMoreThanTwoArgs*/ false
+                              diag::err_typecheck_vector_lengths_not_equal)
+                         << LHSType << RHSType << /*isMoreThanTwoArgs*/ false
                          << SourceRange(TheCall->getArg(1)->getBeginLoc(),
                                         TheCall->getArg(1)->getEndLoc()));
     } else if (!Context.hasSameUnqualifiedType(LHSType, RHSType)) {
diff --git a/clang/test/SemaCXX/vector-shuffle.cpp 
b/clang/test/SemaCXX/vector-shuffle.cpp
index 2393e02428216c..c6f3533ecea691 100644
--- a/clang/test/SemaCXX/vector-shuffle.cpp
+++ b/clang/test/SemaCXX/vector-shuffle.cpp
@@ -19,5 +19,5 @@ void vector_of_float_mask() {
 void mask_vector_with_different_size() {
   v8b a;
   v6i b;
-  auto r = __builtin_shufflevector(a, b); // expected-error {{first two 
arguments to __builtin_shufflevector must have the same number of elements}}
+  auto r = __builtin_shufflevector(a, b); // expected-error {{vector operands 
do not have the same number of elements ('v8b' (vector of 8 'bool' values) and 
'v6i' (vector of 6 'int' values))}}
 }

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

Reply via email to