Skip to content

Conversation

AaronBallman
Copy link
Collaborator

The changes from #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

co-authored-by: @ahatanak

The changes from llvm#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 llvm#154157
@AaronBallman AaronBallman added this to the LLVM 21.x Release milestone Aug 19, 2025
@AaronBallman AaronBallman added c clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid labels Aug 19, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Aug 19, 2025
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Aug 19, 2025
@AaronBallman
Copy link
Collaborator Author

Because this is fixing an issue introduced in Clang 21, there's no release note because I plan to backport the fix to the release branch.

@llvmbot
Copy link
Member

llvmbot commented Aug 19, 2025

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

The changes from #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

co-authored-by: @ahatanak


Full diff: https://github.com/llvm/llvm-project/pull/154351.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaExpr.cpp (+4-4)
  • (modified) clang/test/Sema/implicit-void-ptr-cast.c (+8)
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 *'}}
+}

@github-project-automation github-project-automation bot moved this from Needs Triage to Needs Merge in LLVM Release Status Aug 19, 2025
@AaronBallman
Copy link
Collaborator Author

I believe the Windows failure is unrelated, but we'll see what precommit CI comes back with this time. I wasn't able to reproduce the crash locally on my Windows machine, though.

@AaronBallman
Copy link
Collaborator Author

Windows failures are unrelated, other PRs are having the same issue:
#154342
#154347

@AaronBallman AaronBallman merged commit ae434cd into llvm:main Aug 19, 2025
9 checks passed
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Aug 19, 2025
@AaronBallman AaronBallman deleted the aballman-gh154157 branch August 19, 2025 16:55
@AaronBallman
Copy link
Collaborator Author

/cherry-pick ae434cd

@llvmbot
Copy link
Member

llvmbot commented Aug 19, 2025

/pull-request #154386

ahatanaka pushed a commit to swiftlang/llvm-project that referenced this pull request Aug 20, 2025
The changes from llvm#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 llvm#154157

co-authored-by: @ahatanak
ahatanaka pushed a commit to swiftlang/llvm-project that referenced this pull request Aug 20, 2025
The changes from llvm#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 llvm#154157

co-authored-by: @ahatanak
AaronBallman added a commit to llvmbot/llvm-project that referenced this pull request Aug 20, 2025
The changes from llvm#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 llvm#154157

co-authored-by: @ahatanak
(cherry picked from commit ae434cd)
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 21, 2025
The changes from llvm#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 llvm#154157

co-authored-by: @ahatanak
(cherry picked from commit ae434cd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category rejects-valid
Projects
Development

Successfully merging this pull request may close these issues.

[clang][-Wimplicit-void-ptr-cast] A new false error caused by an unexpected AST change
3 participants