Author: Amr Hesham Date: 2026-09-17T06:15:50Z New Revision: 8e82c9b6ad958ee861d8467a3b7781b4da4e2643
URL: https://github.com/llvm/llvm-project/commit/8e82c9b6ad958ee861d8467a3b7781b4da4e2643 DIFF: https://github.com/llvm/llvm-project/commit/8e82c9b6ad958ee861d8467a3b7781b4da4e2643.diff LOG: [Clang][Sema] Improve shuffle vector size mismatch diagnostic (#223768) Previously, Clang would error out that the arguments to the shufflevector builtin in dynamic mode were not the same type, but they don't need to be. What is required is to have the same number of elements. This PR updates the error message to report the actual reason behind the error. Issue #221791 Added: Modified: clang/docs/ReleaseNotes.md clang/lib/Sema/SemaChecking.cpp clang/test/SemaCXX/vector-shuffle.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 8c1637388d990..9715298100810 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -510,6 +510,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 diff erent sizes. (GH221791) + ### Improvements to Clang's time-trace ### Improvements to Coverage Mapping diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 2f5585490619c..dcf91e901f57e 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_vec_builtin_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 7dbf375599998..c6f3533ecea69 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_ diff erent_size() { + v8b a; + v6i b; + 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
