https://github.com/akash-manna-sky created 
https://github.com/llvm/llvm-project/pull/219987

Fixes #202317

Comparing an `ext_vector_type` of `char32_t` against one of its own elements 
(`V.xyzw < V.x`) splats the scalar to the vector type, and `-Wconversion` 
checking then trips `Source != Target` in 
`DiagnoseMixedUnicodeImplicitConversion`. `CheckImplicitConversion` does reject 
`Source == Target` at the top, but only on the outer types; when it later 
strips the vector wrapper off the target it ends up with `char32_t` on both 
sides and nothing re-checks that. Every other element check just happened to 
tolerate identical types silently, the Unicode one is the first to assert, 
which is why this only showed up as a Clang 21 regression.

The fix is at the call site rather than in the diagnostic: once the vector, 
matrix and SVE wrappers have been stripped, return early if the element types 
are the same. That covers matrix splats and HLSL truncation to the same element 
type too, not just this one warning, and leaves the assertion and the warning's 
behaviour alone. A genuine mismatch such as `V.xyzw < u8` still warns as 
before. Added a test with the reproducer.

LLM tools were used for this contribution. I've reviewed, built, and tested the 
change myself before pushing to GitHub.


>From 3260c658b3d403567368573d6126f4d0be6359fb Mon Sep 17 00:00:00 2001
From: Akash Manna <[email protected]>
Date: Mon, 31 Aug 2026 20:16:10 +0530
Subject: [PATCH] [Clang] Fix assertion when a Unicode character is splatted to
 a vector of its own type

CheckImplicitConversion rejects Source == Target up front, but the
vector/matrix/SVE element stripping can make the two types identical
again (e.g. a char32_t splatted to an ext_vector of char32_t). The
Unicode mixed-type check then asserts Source != Target. Bail out once
the wrappers are stripped and the element types match, since there is
no conversion left to diagnose.

Fixes #202317
---
 clang/docs/ReleaseNotes.md      |  1 +
 clang/lib/Sema/SemaChecking.cpp |  5 +++++
 clang/test/SemaCXX/GH202317.cpp | 22 ++++++++++++++++++++++
 3 files changed, 28 insertions(+)
 create mode 100644 clang/test/SemaCXX/GH202317.cpp

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index bdbabf2cd98d0..5c45cde0a39fe 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -450,6 +450,7 @@ features cannot lower the translation-unit ABI level;
 - Fixed a crash when declaring a member template within a local class inside 
an OpenMP region. (#GH216052)
 - Fixed a bug where repeated #imports of modular headers in non-modular 
compilation were translated to #pragma clang module import. (#GH216924)
 - Fixed an assertion when `#pragma omp declare simd` or `#pragma omp declare 
variant` is followed by another OpenMP declarative directive containing a 
qualified identifier. (#GH217204)
+- Fixed an assertion failure when a value of a Unicode character type 
(`char8_t`, `char16_t`, `char32_t`) was implicitly splatted to a vector of the 
same element type, e.g. when comparing an `ext_vector_type` of `char32_t` with 
one of its elements. (#GH202317)
 
 #### Bug Fixes to Compiler Builtins
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 5c831e6cdebce..8aa58b1f877bc 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -13585,6 +13585,11 @@ void Sema::CheckImplicitConversion(Expr *E, QualType 
T, SourceLocation CC,
   if (TargetBT && TargetBT->isSveVLSBuiltinType())
     Target = TargetBT->getSveEltType(Context).getTypePtr();
 
+  // Nothing to diagnose if stripping the wrappers left identical element types
+  // (e.g. a scalar splatted to a vector of its own type).
+  if (Source == Target)
+    return;
+
   // If the source is floating point...
   if (SourceBT && SourceBT->isFloatingPoint()) {
     // ...and the target is floating point...
diff --git a/clang/test/SemaCXX/GH202317.cpp b/clang/test/SemaCXX/GH202317.cpp
new file mode 100644
index 0000000000000..7dd82948fe7bc
--- /dev/null
+++ b/clang/test/SemaCXX/GH202317.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -Wconversion %s
+
+typedef __attribute__((__ext_vector_type__(4))) char32_t vf4;
+typedef __attribute__((__ext_vector_type__(4))) int vi4;
+
+vi4 foo(vf4 &V) { return V.xyzw < V.x; }
+
+void same_element_type(vf4 &V, char32_t u32) {
+  vf4 v = u32;
+  v = V.x;
+  (void)(V.xyzw == u32);
+  (void)(u32 < V.xyzw);
+}
+
+void different_element_type(vf4 &V, char8_t u8, char16_t u16, char32_t u32) {
+  (void)(V.xyzw < u8); // expected-warning {{implicit conversion from 
'char8_t' to 'vf4'}}
+  vf4 v = u8;          // expected-warning {{implicit conversion from 
'char8_t' to 'vf4'}}
+
+  char16_t c16 = u32; // expected-warning {{implicit conversion from 
'char32_t' to 'char16_t' may lose precision and change the meaning of the 
represented code unit}}
+  char32_t c32 = u8;  // expected-warning {{implicit conversion from 'char8_t' 
to 'char32_t' may change the meaning of the represented code unit}}
+  char32_t c32b = u16;
+}

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

Reply via email to