https://github.com/filaka771 updated 
https://github.com/llvm/llvm-project/pull/203792

>From ba175808e3dc5b5c4f078c2df3c5d44dcf8c73f8 Mon Sep 17 00:00:00 2001
From: Alex Filak <[email protected]>
Date: Sun, 14 Jun 2026 00:40:00 +0300
Subject: [PATCH 1/2] [clang] Fix char-array constant-conversion suppression

---
 clang/lib/Sema/SemaChecking.cpp | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 1c1cd0f2927530..c6df12923c386a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12792,7 +12792,8 @@ static void DiagnoseNullConversion(Sema &S, Expr *E, 
QualType T,
 }
 
 // Helper function to filter out cases for constant width constant conversion.
-// Don't warn on char array initialization or for non-decimal values.
+// Don't warn on char / unsigned char array initialization or for non-decimal
+// values.
 static bool isSameWidthConstantConversion(Sema &S, Expr *E, QualType T,
                                           SourceLocation CC) {
   // If initializing from a constant, and the constant starts with '0',
@@ -12805,12 +12806,16 @@ static bool isSameWidthConstantConversion(Sema &S, 
Expr *E, QualType T,
       return false;
   }
 
-  // If the CC location points to a '{', and the type is char, then assume
-  // assume it is an array initialization.
+  // If the CC location points to a '{', and the destination type is char or
+  // unsigned char, then assume this is an array initialization. Keep warning
+  // for signed char arrays, where values such as 255 change sign.
   if (CC.isValid() && T->isCharType()) {
+    const auto *BT =
+        dyn_cast<BuiltinType>(S.Context.getCanonicalType(T).getTypePtr());
     const char FirstContextCharacter =
         S.getSourceManager().getCharacterData(CC)[0];
-    if (FirstContextCharacter == '{')
+    if (BT && BT->isCharType() && BT->getKind() != BuiltinType::SChar &&
+        FirstContextCharacter == '{')
       return false;
   }
 

>From fb1c6b8bfcb91c3a60ba9437b61170fe34589536 Mon Sep 17 00:00:00 2001
From: Alex Filak <[email protected]>
Date: Sun, 14 Jun 2026 00:40:12 +0300
Subject: [PATCH 2/2] [clang] Add char-array constant-conversion tests

---
 clang/test/Sema/constant-conversion.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/clang/test/Sema/constant-conversion.c 
b/clang/test/Sema/constant-conversion.c
index ffc25b9cc49787..b40379e2180ce6 100644
--- a/clang/test/Sema/constant-conversion.c
+++ b/clang/test/Sema/constant-conversion.c
@@ -125,6 +125,16 @@ void test9(void) {
   char macro_char_dec = CHAR_MACRO_DEC;  // expected-warning {{implicit 
conversion from 'int' to 'char' changes value from 255 to -1}}
 
   char array_init[] = { 255, 127, 128, 129, 0 };
+  unsigned char unsigned_array_init[] = { 255 };
+  unsigned char unsigned_array_init_multi[] = { 255, 127, 128, 129, 0 };
+  signed char signed_array_init[] = { 255 }; // expected-warning {{implicit 
conversion from 'int' to 'signed char' changes value from 255 to -1}}
+  signed char signed_array_init_multi[] = {
+    255, // expected-warning {{implicit conversion from 'int' to 'signed char' 
changes value from 255 to -1}}
+    127,
+    128, // expected-warning {{implicit conversion from 'int' to 'signed char' 
changes value from 128 to -128}}
+    129, // expected-warning {{implicit conversion from 'int' to 'signed char' 
changes value from 129 to -127}}
+    0
+  };
 }
 
 #define A 1

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

Reply via email to