[clang] d01219d - [Sema] Return RecoveryExpr for ARC atomic ownership error (#224849)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 29 20:57:23 PDT 2026


Author: ʟᴜɴᴇx
Date: 2026-09-29T20:57:12-07:00
New Revision: d01219d32dbe64d5a108ad644c294cf7289f28b1

URL: https://github.com/llvm/llvm-project/commit/d01219d32dbe64d5a108ad644c294cf7289f28b1
DIFF: https://github.com/llvm/llvm-project/commit/d01219d32dbe64d5a108ad644c294cf7289f28b1.diff

LOG: [Sema] Return RecoveryExpr for ARC atomic ownership error (#224849)

`BuiltinAtomicOverloaded` returned a bare `ExprError()` on the ARC
ownership check and made CodeGen hit `llvm_unreachable`.
so return a `RecoveryExpr` instead so bad data can't reach codegen.

Fixes #222528.

Added: 
    clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm

Modified: 
    clang/lib/Basic/DiagnosticIDs.cpp
    clang/lib/Sema/SemaChecking.cpp

Removed: 
    


################################################################################
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 a7012d78b2c6a..c0cfc51f5b68f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5793,6 +5793,7 @@ ExprResult Sema::BuiltinAtomicOverloaded(ExprResult TheCallResult) {
   case Qualifiers::OCL_Autoreleasing:
     Diag(DRE->getBeginLoc(), diag::err_arc_atomic_ownership)
         << ValType << FirstArg->getSourceRange();
+
     return ExprError();
   }
 

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..fd5cc65d75f1c
--- /dev/null
+++ b/clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm
@@ -0,0 +1,11 @@
+// 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
+
+ at 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}}
+}


        


More information about the cfe-commits mailing list