Skip to content

[Sema][ObjC] Treat unknown selector messages as unrecoverable errors under ARC #146803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions clang/lib/Basic/DiagnosticIDs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 6 additions & 1 deletion clang/test/SemaObjCXX/arc-0x.mm
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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];
Expand Down