llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Hugo Melder (hmelder)

<details>
<summary>Changes</summary>

When constructing the protocol list in the class metadata generation 
(`GenerateClass`), only the protocols from the base class are added but not 
protocols declared in class extensions.

This is fixed by using `all_referenced_protocol_{begin, end}` instead of 
`protocol_{begin, end}`, matching the behaviour on Apple platforms.

A unit test is included to check if all protocol metadata was emitted and that 
no duplication occurs in the protocol list.

Fixes https://github.com/gnustep/libobjc2/issues/339

CC: @<!-- -->davidchisnall  

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+2-2) 
- (added) clang/test/CodeGenObjC/gnustep2-class-exts.m (+25) 


``````````diff
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] }

``````````

</details>


https://github.com/llvm/llvm-project/pull/148827
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to