https://github.com/im-lunex updated 
https://github.com/llvm/llvm-project/pull/224849

From e47cb03a0d8965d31e856aff80a3bea5b7994f10 Mon Sep 17 00:00:00 2001
From: im-lunex <[email protected]>
Date: Sat, 19 Sep 2026 23:55:13 +0600
Subject: [PATCH 1/2] Return RecoveryExpr for ARC atomic ownership

---
 clang/lib/Sema/SemaChecking.cpp                      |  5 ++++-
 .../CodeGenObjCXX/objc-atomic-ownership-recovery.mm  | 12 ++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index dcf91e901f57e..7e96895d4f91b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5739,7 +5739,10 @@ ExprResult Sema::BuiltinAtomicOverloaded(ExprResult 
TheCallResult) {
   case Qualifiers::OCL_Autoreleasing:
     Diag(DRE->getBeginLoc(), diag::err_arc_atomic_ownership)
         << ValType << FirstArg->getSourceRange();
-    return ExprError();
+
+    return CreateRecoveryExpr(TheCall->getBeginLoc(), TheCall->getEndLoc(),
+                              llvm::to_vector(TheCall->arguments()),
+                              TheCall->getType());
   }
 
   // Strip any qualifiers off ValType.
diff --git a/clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm 
b/clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm
new file mode 100644
index 0000000000000..f8583fe34682f
--- /dev/null
+++ b/clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu 
-fobjc-runtime=macosx-10.14 -fobjc-arc -emit-llvm -o /dev/null %s -verify
+
+// Test for - https://github.com/llvm/llvm-project/issues/222528
+
+@class incompatible;
+
+static incompatible *g;
+
+void integer(incompatible *o) {
+  __sync_bool_compare_and_swap(&g, 0, o); // expected-error {{cannot perform 
atomic operation on a pointer to type 'incompatible *__strong': type has 
non-trivial ownership}} \
+                                          // expected-error {{cannot compile 
this scalar expression yet}}
+}

From 500564917a3120760ba8489b1fd0c828bac485fa Mon Sep 17 00:00:00 2001
From: im-lunex <[email protected]>
Date: Sun, 27 Sep 2026 23:48:06 +0600
Subject: [PATCH 2/2] Make err_arc_atomic_ownership unrecoverable

---
 clang/lib/Basic/DiagnosticIDs.cpp                             | 3 ++-
 clang/lib/Sema/SemaChecking.cpp                               | 4 +---
 .../objc-atomic-ownership-recovery.mm                         | 3 +--
 3 files changed, 4 insertions(+), 6 deletions(-)
 rename clang/test/{CodeGenObjCXX => 
SemaObjCXX}/objc-atomic-ownership-recovery.mm (72%)

diff --git a/clang/lib/Basic/DiagnosticIDs.cpp 
b/clang/lib/Basic/DiagnosticIDs.cpp
index 3709528e497d2..efc9346140796 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -961,7 +961,8 @@ bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
   // because sending a message with an unknown selector could lead to crashes
   // within CodeGen if the resulting expression is used to initialize a C++
   // auto variable, where type deduction is required.
-  if (isARCDiagnostic(DiagID) && DiagID != diag::err_arc_may_not_respond)
+  if (isARCDiagnostic(DiagID) && DiagID != diag::err_arc_may_not_respond &&
+      DiagID != diag::err_arc_atomic_ownership)
     return false;
 
   if (isCodegenABICheckDiagnostic(DiagID))
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 7e96895d4f91b..ec6cec6cfb222 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5740,9 +5740,7 @@ ExprResult Sema::BuiltinAtomicOverloaded(ExprResult 
TheCallResult) {
     Diag(DRE->getBeginLoc(), diag::err_arc_atomic_ownership)
         << ValType << FirstArg->getSourceRange();
 
-    return CreateRecoveryExpr(TheCall->getBeginLoc(), TheCall->getEndLoc(),
-                              llvm::to_vector(TheCall->arguments()),
-                              TheCall->getType());
+    return ExprError();
   }
 
   // Strip any qualifiers off ValType.
diff --git a/clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm 
b/clang/test/SemaObjCXX/objc-atomic-ownership-recovery.mm
similarity index 72%
rename from clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm
rename to clang/test/SemaObjCXX/objc-atomic-ownership-recovery.mm
index f8583fe34682f..fd5cc65d75f1c 100644
--- a/clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm
+++ b/clang/test/SemaObjCXX/objc-atomic-ownership-recovery.mm
@@ -7,6 +7,5 @@
 static incompatible *g;
 
 void integer(incompatible *o) {
-  __sync_bool_compare_and_swap(&g, 0, o); // expected-error {{cannot perform 
atomic operation on a pointer to type 'incompatible *__strong': type has 
non-trivial ownership}} \
-                                          // expected-error {{cannot compile 
this scalar expression yet}}
+  __sync_bool_compare_and_swap(&g, 0, o); // expected-error {{cannot perform 
atomic operation on a pointer to type 'incompatible *__strong': type has 
non-trivial ownership}}
 }

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

Reply via email to