[clang] [Sema] Return RecoveryExpr for ARC atomic ownership error (PR #224849)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 19 11:04:55 PDT 2026
https://github.com/im-lunex created https://github.com/llvm/llvm-project/pull/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.
>From e47cb03a0d8965d31e856aff80a3bea5b7994f10 Mon Sep 17 00:00:00 2001
From: im-lunex <thisissamir04 at gmail.com>
Date: Sat, 19 Sep 2026 23:55:13 +0600
Subject: [PATCH] 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
+
+ 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}} \
+ // expected-error {{cannot compile this scalar expression yet}}
+}
More information about the cfe-commits
mailing list