https://github.com/ahatanak updated https://github.com/llvm/llvm-project/pull/146803
>From c74ab1b752c4d6f0f52bfb682b0d0949c2912230 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka <ahata...@gmail.com> Date: Wed, 2 Jul 2025 15:51:54 -0700 Subject: [PATCH 1/3] [Sema][ObjC] Treat unknown selector messages as unrecoverable errors under ARC 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 --- clang/lib/Basic/DiagnosticIDs.cpp | 6 +++++- clang/test/SemaObjCXX/arc-0x.mm | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp index dcf0c6cb54282..04a7f7732429d 100644 --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/lib/Basic/DiagnosticIDs.cpp @@ -832,7 +832,11 @@ bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const { DiagID == diag::err_unavailable_message) return false; - // Currently we consider all ARC errors as recoverable. + // Currently we consider all ARC errors except err_arc_may_not_respond as + // recoverable. + if (DiagID == diag::err_arc_may_not_respond) + return true; + if (isARCDiagnostic(DiagID)) return false; 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]; >From 83714a8717387020b48fef8ed6e21f5a3650c70d Mon Sep 17 00:00:00 2001 From: Akira Hatanaka <ahata...@gmail.com> Date: Wed, 2 Jul 2025 17:35:35 -0700 Subject: [PATCH 2/3] Call isARCDiagnostic first --- clang/lib/Basic/DiagnosticIDs.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp index 04a7f7732429d..fb18c767a7de5 100644 --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/lib/Basic/DiagnosticIDs.cpp @@ -834,10 +834,7 @@ bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const { // Currently we consider all ARC errors except err_arc_may_not_respond as // recoverable. - if (DiagID == diag::err_arc_may_not_respond) - return true; - - if (isARCDiagnostic(DiagID)) + if (isARCDiagnostic(DiagID) && DiagID != diag::err_arc_may_not_respond) return false; if (isCodegenABICheckDiagnostic(DiagID)) >From 7205f2be2c1afa1473b6de72433834cb27d6a74b Mon Sep 17 00:00:00 2001 From: Akira Hatanaka <ahata...@gmail.com> Date: Thu, 3 Jul 2025 08:26:23 -0700 Subject: [PATCH 3/3] Explain why err_arc_may_not_respond needs to be treated as unrecoverable --- clang/lib/Basic/DiagnosticIDs.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp index fb18c767a7de5..73f24a82d4c75 100644 --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/lib/Basic/DiagnosticIDs.cpp @@ -832,8 +832,11 @@ bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const { DiagID == diag::err_unavailable_message) return false; - // Currently we consider all ARC errors except err_arc_may_not_respond as - // recoverable. + // 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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits