[clang] [Sema] Return RecoveryExpr for ARC atomic ownership error (PR #224849)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 19 11:05:37 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: ʟᴜɴᴇx (im-lunex)
<details>
<summary>Changes</summary>
`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.
---
Full diff: https://github.com/llvm/llvm-project/pull/224849.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaChecking.cpp (+4-1)
- (added) clang/test/CodeGenObjCXX/objc-atomic-ownership-recovery.mm (+12)
``````````diff
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}}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/224849
More information about the cfe-commits
mailing list