DHowett-MSFT updated this revision to Diff 141701.
DHowett-MSFT edited the summary of this revision.
DHowett-MSFT added a comment.

I've fixed the test to check the LLVM IR; I chose to use `CHECK-SAME` and use 
indentation to clarify what was going on. We're now checking that an empty 
protocol is emitted in full, and that all of its members match our expectations.


Repository:
  rC Clang

https://reviews.llvm.org/D45305

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


Index: test/CodeGenObjC/gnu-empty-protocol-v3.m
===================================================================
--- /dev/null
+++ test/CodeGenObjC/gnu-empty-protocol-v3.m
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fobjc-runtime=gnustep-1.9 
-emit-llvm -o - %s | FileCheck %s
+
+@protocol X;
+
+__attribute__((objc_root_class))
+@interface Z <X>
+@end
+
+@implementation Z
+@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
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());
 }


Index: test/CodeGenObjC/gnu-empty-protocol-v3.m
===================================================================
--- /dev/null
+++ test/CodeGenObjC/gnu-empty-protocol-v3.m
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fobjc-runtime=gnustep-1.9 -emit-llvm -o - %s | FileCheck %s
+
+@protocol X;
+
+__attribute__((objc_root_class))
+@interface Z <X>
+@end
+
+@implementation Z
+@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
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());
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to