Author: Akash Manna Date: 2026-09-08T15:51:11Z New Revision: b12d510875d4d3b56a34bb425757a1b488ba3e4b
URL: https://github.com/llvm/llvm-project/commit/b12d510875d4d3b56a34bb425757a1b488ba3e4b DIFF: https://github.com/llvm/llvm-project/commit/b12d510875d4d3b56a34bb425757a1b488ba3e4b.diff LOG: [Clang] Fix assertion when a Unicode character is splatted to a vector of its own type (#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. Added: Modified: clang/docs/ReleaseNotes.md clang/lib/Sema/SemaChecking.cpp clang/test/SemaCXX/warn-implicit-unicode-conversions.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index cd59d6e942a35..f8eba5237ba3a 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -501,6 +501,7 @@ features cannot lower the translation-unit ABI level; - Fixed USR generation for declarations whose signature mentions a class-type non-type template parameter. (#GH212351) - Fixed an assertion caused by Microsoft integer literals exceeding the maximum value. (#GH212504) +- 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) - Fixed a crash when checking scalar type with excess braces. (#GH69213), (#GH137845), (#GH198767), (#GH207566), (#GH106180) - Fixed an assertion crash when instantiating a nested requirement with an invalid constraint. (#GH213575) - Clang now defines the GCC-compatible predefined macro `__SIG_ATOMIC_TYPE__`. (#GH213895) diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index f0a1a529841b2..0e85af73696dc 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -13588,6 +13588,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/warn-implicit-unicode-conversions.cpp b/clang/test/SemaCXX/warn-implicit-unicode-conversions.cpp index 6f9f8f3898625..80420d836a55d 100644 --- a/clang/test/SemaCXX/warn-implicit-unicode-conversions.cpp +++ b/clang/test/SemaCXX/warn-implicit-unicode-conversions.cpp @@ -149,3 +149,22 @@ void check_arithmetic(char8_t u8, char16_t u16, char32_t u32) { (void)(u16 | u32); // expected-warning {{bitwise operation between diff erent Unicode character types 'char16_t' and 'char32_t'}} (void)(1 ? u32 : u16); // expected-warning {{conditional expression between diff erent Unicode character types 'char32_t' and 'char16_t'}} } + +namespace GH202317 { +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 diff erent_element_type(vf4 &V, char8_t u8) { + (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'}} +} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
