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

Conversation

ahatanak
Copy link
Collaborator

@ahatanak ahatanak commented Jul 2, 2025

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

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
@ahatanak ahatanak requested a review from rjmccall July 2, 2025 23:25
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 2, 2025

@llvm/pr-subscribers-clang

Author: Akira Hatanaka (ahatanak)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/146803.diff

2 Files Affected:

  • (modified) clang/lib/Basic/DiagnosticIDs.cpp (+5-1)
  • (modified) clang/test/SemaObjCXX/arc-0x.mm (+6-1)
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];

Copy link
Contributor

@rjmccall rjmccall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. Please elaborate in the comment to explain why this particular error needs to be considered unrecoverable.

@ahatanak ahatanak merged commit 77f0f81 into llvm:main Jul 3, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants