https://github.com/hmelder updated https://github.com/llvm/llvm-project/pull/148827
>From 07f00da14d0716da4ad3637e9296e68fee95f64e Mon Sep 17 00:00:00 2001 From: hmelder <serv...@hugomelder.com> Date: Tue, 15 Jul 2025 13:09:28 +0200 Subject: [PATCH] [CodeGen][ObjC] Include all referenced protocols in protocol list When constructing the protocol list in the class metadata generation (`GenerateClass`), only the protocols from the base class are added but not from class extensions. This is fixed by using `all_referenced_protocol_{begin, end}` instead of `protocol_{begin, end}`, matching the behaviour on Apple platforms. --- clang/lib/CodeGen/CGObjCGNU.cpp | 4 ++-- clang/test/CodeGenObjC/gnustep2-class-exts.m | 25 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenObjC/gnustep2-class-exts.m diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index d828702cbb87f..126b46e08df48 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -1942,8 +1942,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { // struct objc_class *sibling_class classFields.addNullPointer(PtrTy); // struct objc_protocol_list *protocols; - auto RuntimeProtocols = GetRuntimeProtocolList(classDecl->protocol_begin(), - classDecl->protocol_end()); + auto RuntimeProtocols = GetRuntimeProtocolList(classDecl->all_referenced_protocol_begin(), + classDecl->all_referenced_protocol_end()); SmallVector<llvm::Constant *, 16> Protocols; for (const auto *I : RuntimeProtocols) Protocols.push_back(GenerateProtocolRef(I)); diff --git a/clang/test/CodeGenObjC/gnustep2-class-exts.m b/clang/test/CodeGenObjC/gnustep2-class-exts.m new file mode 100644 index 0000000000000..b065490a7d8d8 --- /dev/null +++ b/clang/test/CodeGenObjC/gnustep2-class-exts.m @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -fobjc-runtime=gnustep-2.2 -emit-llvm -o - %s | FileCheck %s + +@protocol BaseProtocol +@end + +@protocol ExtendedProtocol +@end + +@interface TestClass <BaseProtocol> + +-(void) Meth; +@end + +@interface TestClass () <BaseProtocol, ExtendedProtocol> +@end + +@implementation TestClass +@end + +// Check that we emit metadata for both protocols +// CHECK: @._OBJC_PROTOCOL_ExtendedProtocol = global +// CHECK: @._OBJC_PROTOCOL_BaseProtocol = global + +// Check that we deduplicate the protocol list +// CHECK: @.objc_protocol_list{{\.[0-9]*}} = internal global { ptr, i64, [2 x ptr] } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits