Skip to content

Commit 77f0f81

Browse files
authored
[Sema][ObjC] Treat unknown selector messages as unrecoverable errors under ARC (llvm#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
1 parent 4cd9c89 commit 77f0f81

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

clang/lib/Basic/DiagnosticIDs.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,12 @@ bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
832832
DiagID == diag::err_unavailable_message)
833833
return false;
834834

835-
// Currently we consider all ARC errors as recoverable.
836-
if (isARCDiagnostic(DiagID))
835+
// All ARC errors are currently considered recoverable, with the exception of
836+
// err_arc_may_not_respond. This specific error is treated as unrecoverable
837+
// because sending a message with an unknown selector could lead to crashes
838+
// within CodeGen if the resulting expression is used to initialize a C++
839+
// auto variable, where type deduction is required.
840+
if (isARCDiagnostic(DiagID) && DiagID != diag::err_arc_may_not_respond)
837841
return false;
838842

839843
if (isCodegenABICheckDiagnostic(DiagID))

clang/test/SemaObjCXX/arc-0x.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -fobjc-weak -verify -fblocks -fobjc-exceptions %s
1+
// RUN: %clang_cc1 -std=c++11 -fobjc-arc -fobjc-runtime-has-weak -fobjc-weak -verify -fblocks -fobjc-exceptions -emit-llvm -o - %s
22

33
// "Move" semantics, trivial version.
44
void move_it(__strong id &&from) {
@@ -14,6 +14,11 @@ @interface A
1414
// don't warn about this
1515
extern "C" A* MakeA();
1616

17+
void test_nonexistent_method(A *a) {
18+
// This used to crash in codegen.
19+
auto a1 = [a foo]; // expected-error {{no visible @interface for 'A' declares the selector 'foo'}}
20+
}
21+
1722
// Ensure that deduction works with lifetime qualifiers.
1823
void deduction(id obj) {
1924
auto a = [[A alloc] init];

0 commit comments

Comments
 (0)