[PATCH] D45305: ObjCGNU: Fix empty v3 protocols being emitted two fields short

Dustin L. Howett via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 6 16:24:09 PDT 2018


DHowett-MSFT updated this revision to Diff 141450.
DHowett-MSFT added a comment.

Added a test per @rjmccall's suggestion. I chose to test this by emitting assembly because the llvm ir is significantly harder to pick apart for the true _size_ of the protocol.


Repository:
  rC Clang

https://reviews.llvm.org/D45305

Files:
  lib/CodeGen/CGObjCGNU.cpp
  test/CodeGenObjC/undefined-protocol-v3.m


Index: test/CodeGenObjC/undefined-protocol-v3.m
===================================================================
--- /dev/null
+++ test/CodeGenObjC/undefined-protocol-v3.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fobjc-runtime=gnustep-1.9 -S -o - %s | FileCheck %s
+
+ at protocol X;
+
+__attribute__((objc_root_class))
+ at interface Z <X>
+ at end
+
+ at implementation Z
+ at end
+
+// CHECK-DAG: .objc_protocol:
+// CHECK-DAG:   .long 3
+// CHECK-DAG:   .size   .objc_protocol, 36
Index: lib/CodeGen/CGObjCGNU.cpp
===================================================================
--- lib/CodeGen/CGObjCGNU.cpp
+++ lib/CodeGen/CGObjCGNU.cpp
@@ -1813,11 +1813,13 @@
           llvm::ConstantInt::get(Int32Ty, ProtocolVersion), IdTy));
 
   Elements.add(MakeConstantString(ProtocolName, ".objc_protocol_name"));
-  Elements.add(ProtocolList);
-  Elements.add(MethodList);
-  Elements.add(MethodList);
-  Elements.add(MethodList);
-  Elements.add(MethodList);
+  Elements.add(ProtocolList); /* .protocol_list */
+  Elements.add(MethodList);   /* .instance_methods */
+  Elements.add(MethodList);   /* .class_methods */
+  Elements.add(MethodList);   /* .optional_instance_methods */
+  Elements.add(MethodList);   /* .optional_class_methods */
+  Elements.add(NULLPtr);      /* .properties */
+  Elements.add(NULLPtr);      /* .optional_properties */
   return Elements.finishAndCreateGlobal(".objc_protocol",
                                         CGM.getPointerAlign());
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45305.141450.patch
Type: text/x-patch
Size: 1491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180406/b2fdce06/attachment.bin>


More information about the cfe-commits mailing list