diff options
author | David Chisnall <csdavec@swan.ac.uk> | 2018-04-12 06:46:15 +0000 |
---|---|---|
committer | David Chisnall <csdavec@swan.ac.uk> | 2018-04-12 06:46:15 +0000 |
commit | 10e590e950b80dd1cef95c5ec3cfc11b513343da (patch) | |
tree | 0bf451f3043ef5acc8046fe293d8dacd7724c7d3 | |
parent | 60874d4fafde7439cb4610b704abba93ab45af13 (diff) | |
download | bcm5719-llvm-10e590e950b80dd1cef95c5ec3cfc11b513343da.tar.gz bcm5719-llvm-10e590e950b80dd1cef95c5ec3cfc11b513343da.zip |
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
llvm-svn: 329882
-rw-r--r-- | clang/lib/CodeGen/CGObjCGNU.cpp | 12 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/gnu-empty-protocol-v3.m | 25 |
2 files changed, 32 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index a6b6c38d5cc..6f4cde569f8 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -1748,11 +1748,13 @@ CGObjCGNU::GenerateEmptyProtocol(const std::string &ProtocolName) { 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()); } diff --git a/clang/test/CodeGenObjC/gnu-empty-protocol-v3.m b/clang/test/CodeGenObjC/gnu-empty-protocol-v3.m new file mode 100644 index 00000000000..cdaf215e6c3 --- /dev/null +++ b/clang/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 |