r329882 - ObjCGNU: Fix empty v3 protocols being emitted two fields short

David Chisnall via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 11 23:46:15 PDT 2018


Author: theraven
Date: Wed Apr 11 23:46:15 2018
New Revision: 329882

URL: http://llvm.org/viewvc/llvm-project?rev=329882&view=rev
Log:
ObjCGNU: Fix empty v3 protocols being emitted two fields short

Summary:
Protocols that were being referenced but could not be fully realized were being emitted without `properties`/`optional_properties`. Since all v3 protocols must be 9 processor words wide, 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.

Reviewers: rjmccall, theraven

Reviewed By: rjmccall, theraven

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D45305

Added:
    cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m
Modified:
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=329882&r1=329881&r2=329882&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Apr 11 23:46:15 2018
@@ -1748,11 +1748,13 @@ CGObjCGNU::GenerateEmptyProtocol(const s
           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());
 }

Added: cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m?rev=329882&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m (added)
+++ cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m Wed Apr 11 23:46:15 2018
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fobjc-runtime=gnustep-1.9 -emit-llvm -o - %s | FileCheck %s
+
+ at protocol X;
+
+__attribute__((objc_root_class))
+ at interface Z <X>
+ at end
+
+ at implementation Z
+ at end
+
+// CHECK:      @.objc_protocol_list = internal global { i8*, i32, [0 x i8*] } zeroinitializer, align 4
+// CHECK:      @.objc_method_list = internal global { i32, [0 x { i8*, i8* }] } zeroinitializer, align 4
+// CHECK:      @.objc_protocol_name = private unnamed_addr constant [2 x i8] c"X\00", align 1
+// CHECK:      @.objc_protocol = internal global { i8*, i8*, { i8*, i32, [0 x i8*] }*, { i32, [0 x { i8*, i8* }] }*, { i32, [0 x { i8*, i8* }] }*, { i32, [0 x { i8*, i8* }] }*, { i32, [0 x { i8*, i8* }] }*, i8*, i8* } {
+// CHECK-SAME:     i8* inttoptr (i32 3 to i8*),
+// CHECK-SAME:     i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.objc_protocol_name, i32 0, i32 0),
+// CHECK-SAME:     { i8*, i32, [0 x i8*] }* @.objc_protocol_list,
+// CHECK-SAME:     { i32, [0 x { i8*, i8* }] }* @.objc_method_list,
+// CHECK-SAME:     { i32, [0 x { i8*, i8* }] }* @.objc_method_list,
+// CHECK-SAME:     { i32, [0 x { i8*, i8* }] }* @.objc_method_list,
+// CHECK-SAME:     { i32, [0 x { i8*, i8* }] }* @.objc_method_list,
+// CHECK-SAME:     i8* null,
+// CHECK-SAME:     i8* null
+// CHECK-SAME: }, align 4




More information about the cfe-commits mailing list