https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/154351

>From 2dabc7de6840fb092c411a3e494ced6e970f5c47 Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aa...@aaronballman.com>
Date: Tue, 19 Aug 2025 10:43:35 -0400
Subject: [PATCH 1/2] [C] Fix issue with -Wimplicit-void-ptr-cast

The changes from https://github.com/llvm/llvm-project/pull/136855
missed a change with atomic assignment constraints. This fixes a bug
where we'd accidentally drop a non-atomic-to-atomic conversion step.

Fixes #154157
---
 clang/lib/Sema/SemaExpr.cpp              | 8 ++++----
 clang/test/Sema/implicit-void-ptr-cast.c | 8 ++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 237c068f59283..265cd799373a5 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9317,14 +9317,14 @@ AssignConvertType 
Sema::CheckAssignmentConstraints(QualType LHSType,
   // If we have an atomic type, try a non-atomic assignment, then just add an
   // atomic qualification step.
   if (const AtomicType *AtomicTy = dyn_cast<AtomicType>(LHSType)) {
-    AssignConvertType result =
+    AssignConvertType Result =
         CheckAssignmentConstraints(AtomicTy->getValueType(), RHS, Kind);
-    if (result != AssignConvertType::Compatible)
-      return result;
+    if (!IsAssignConvertCompatible(Result))
+      return Result;
     if (Kind != CK_NoOp && ConvertRHS)
       RHS = ImpCastExprToType(RHS.get(), AtomicTy->getValueType(), Kind);
     Kind = CK_NonAtomicToAtomic;
-    return AssignConvertType::Compatible;
+    return Result;
   }
 
   // If the left-hand side is a reference type, then we are in a
diff --git a/clang/test/Sema/implicit-void-ptr-cast.c 
b/clang/test/Sema/implicit-void-ptr-cast.c
index 3c3e153d1dbda..1a8e1574907d4 100644
--- a/clang/test/Sema/implicit-void-ptr-cast.c
+++ b/clang/test/Sema/implicit-void-ptr-cast.c
@@ -82,3 +82,11 @@ void more(void) {
   ptr3 = SOMETHING_THAT_IS_NOT_NULL; // c-warning {{implicit conversion when 
assigning to 'char *' from type 'void *' is not permitted in C++}} \
                                         cxx-error {{assigning to 'char *' from 
incompatible type 'void *'}}
 }
+
+void gh154157(void) {
+  #define ATOMIC_VAR_INIT(value) (value)
+
+  typedef const struct T * T_Ref;
+  static T_Ref _Atomic x = ATOMIC_VAR_INIT((void*)NULL); // c-warning 
{{implicit conversion when initializing '_Atomic(T_Ref)' with an expression of 
type 'void *' is not permitted in C++}} \
+                                                            cxx-error {{cannot 
initialize a variable of type '_Atomic(T_Ref)' with an rvalue of type 'void *'}}
+}

>From 9c2250cb2806753aacd5958b6aae86ee5a329a60 Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aa...@aaronballman.com>
Date: Tue, 19 Aug 2025 11:32:37 -0400
Subject: [PATCH 2/2] Add more tests based on review feedback

---
 clang/test/Sema/implicit-void-ptr-cast.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/test/Sema/implicit-void-ptr-cast.c 
b/clang/test/Sema/implicit-void-ptr-cast.c
index 1a8e1574907d4..f083cfb77329f 100644
--- a/clang/test/Sema/implicit-void-ptr-cast.c
+++ b/clang/test/Sema/implicit-void-ptr-cast.c
@@ -89,4 +89,8 @@ void gh154157(void) {
   typedef const struct T * T_Ref;
   static T_Ref _Atomic x = ATOMIC_VAR_INIT((void*)NULL); // c-warning 
{{implicit conversion when initializing '_Atomic(T_Ref)' with an expression of 
type 'void *' is not permitted in C++}} \
                                                             cxx-error {{cannot 
initialize a variable of type '_Atomic(T_Ref)' with an rvalue of type 'void *'}}
+  static T_Ref const y = ATOMIC_VAR_INIT((void*)NULL);   // c-warning 
{{implicit conversion when initializing 'const T_Ref' (aka 'const struct T 
*const') with an expression of type 'void *' is not permitted in C++}} \
+                                                            cxx-error {{cannot 
initialize a variable of type 'const T_Ref' (aka 'const struct T *const') with 
an rvalue of type 'void *'}}
+  static T_Ref z = ATOMIC_VAR_INIT((void*)NULL);         // c-warning 
{{implicit conversion when initializing 'T_Ref' (aka 'const struct T *') with 
an expression of type 'void *' is not permitted in C++}} \
+                                                            cxx-error {{cannot 
initialize a variable of type 'T_Ref' (aka 'const struct T *') with an rvalue 
of type 'void *'}}
 }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to