https://github.com/ANAMASGARD updated https://github.com/llvm/llvm-project/pull/213590
>From 0237bc2c44324d3ae4f02e8c8992b96c6d1e2bbd Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary <[email protected]> Date: Mon, 3 Aug 2026 10:17:56 +0530 Subject: [PATCH] [clang] Avoid invalid recovery cast for non-pointer Class redefinitions ShouldTryAgainWithRedefinitionType() can attempt to recover builtin Objective-C id/ Class member access using a user-written non-pointer redefinition. This constructs a CK_BitCast between incompatible type categories and violates CastExpr's AST invariants. Reject non-pointer redefinition types before attempting the recovery cast, while preserving recovery for C and Objective-C object pointers. Fixes #213066 Signed-off-by: Gaurav Chaudhary <[email protected]> --- clang/lib/Sema/SemaExprMember.cpp | 5 +++++ clang/test/SemaObjCXX/gh213066.mm | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 clang/test/SemaObjCXX/gh213066.mm diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 62ecc52c0374b..f42b94c216660 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -1188,6 +1188,11 @@ static bool ShouldTryAgainWithRedefinitionType(Sema &S, ExprResult &base) { return false; } + // Only retry with pointer redefinition types, since a non-pointer + // destination would produce an invalid CK_BitCast. + if (!redef->isAnyPointerType()) + return false; + // Do the substitution as long as the redefinition type isn't just a // possibly-qualified pointer to builtin-id or builtin-Class again. opty = redef->getAs<ObjCObjectPointerType>(); diff --git a/clang/test/SemaObjCXX/gh213066.mm b/clang/test/SemaObjCXX/gh213066.mm new file mode 100644 index 0000000000000..58123a3640a4a --- /dev/null +++ b/clang/test/SemaObjCXX/gh213066.mm @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsyntax-only -verify -x objective-c++ %s +// REQUIRES: asserts + +typedef struct {} Class; + +void test() { + Class c; + c.className; // expected-error {{member reference base type 'Class' is not a structure or union}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
