[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
Wed Apr 4 17:23:31 PDT 2018


DHowett-MSFT created this revision.
DHowett-MSFT added reviewers: rjmccall, theraven.
DHowett-MSFT added a project: clang.
Herald added a subscriber: cfe-commits.

Protocols that were being referenced but could not be fully realized were being emitted without `properties`/`optional_properties`. Since they're packed end-to-end, the lack of these fields is catastrophic for the runtime.

As an example, the runtime cannot know here <https://github.com/gnustep/libobjc2/blob/master/protocol.c#L73> that `properties` and `optional_properties` are invalid if they overlap with another v3 protocol.


Repository:
  rC Clang

https://reviews.llvm.org/D45305

Files:
  lib/CodeGen/CGObjCGNU.cpp


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.141094.patch
Type: text/x-patch
Size: 995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180405/cf61b6cb/attachment.bin>


More information about the cfe-commits mailing list