[clang] 77f0f81 - [Sema][ObjC] Treat unknown selector messages as unrecoverable errors under ARC (#146803)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 3 10:01:12 PDT 2025
Author: Akira Hatanaka
Date: 2025-07-03T10:01:08-07:00
New Revision: 77f0f812b4195bfde3b8d2ddb4b85f78f41a628f
URL: https://github.com/llvm/llvm-project/commit/77f0f812b4195bfde3b8d2ddb4b85f78f41a628f
DIFF: https://github.com/llvm/llvm-project/commit/77f0f812b4195bfde3b8d2ddb4b85f78f41a628f.diff
LOG: [Sema][ObjC] Treat unknown selector messages as unrecoverable errors under ARC (#146803)
Fixes a CodeGen crash observed when C++ auto variable types remained
non-deduced due to a message being sent with an unknown selector under
ARC.
By treating these instances as an unrecoverable error, we prevent the
compiler from proceeding to CodeGen with fundamentally incorrect code.
rdar://144394403
Added:
Modified:
clang/lib/Basic/DiagnosticIDs.cpp
clang/test/SemaObjCXX/arc-0x.mm
Removed:
################################################################################
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index dcf0c6cb54282..73f24a82d4c75 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -832,8 +832,12 @@ bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
DiagID == diag::err_unavailable_message)
return false;
- // Currently we consider all ARC errors as recoverable.
- if (isARCDiagnostic(DiagID))
+ // All ARC errors are currently considered recoverable, with the exception of
+ // err_arc_may_not_respond. This specific error is treated as unrecoverable
+ // 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)
return false;
if (isCodegenABICheckDiagnostic(DiagID))
diff --git a/clang/test/SemaObjCXX/arc-0x.mm b/clang/test/SemaObjCXX/arc-0x.mm
index ac788686a7374..bcaa5da6b9283 100644
--- a/clang/test/SemaObjCXX/arc-0x.mm
+++ b/clang/test/SemaObjCXX/arc-0x.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -fobjc-weak -verify -fblocks -fobjc-exceptions %s
+// RUN: %clang_cc1 -std=c++11 -fobjc-arc -fobjc-runtime-has-weak -fobjc-weak -verify -fblocks -fobjc-exceptions -emit-llvm -o - %s
// "Move" semantics, trivial version.
void move_it(__strong id &&from) {
@@ -14,6 +14,11 @@ @interface A
// don't warn about this
extern "C" A* MakeA();
+void test_nonexistent_method(A *a) {
+ // This used to crash in codegen.
+ auto a1 = [a foo]; // expected-error {{no visible @interface for 'A' declares the selector 'foo'}}
+}
+
// Ensure that deduction works with lifetime qualifiers.
void deduction(id obj) {
auto a = [[A alloc] init];
More information about the cfe-commits
mailing list