Skip to content

[IRGen] Fix ObjC method signatures for .cxx_construct and .cxx_destruct #17884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/IRGen/GenObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,9 @@ void irgen::emitObjCMethodDescriptorParts(IRGenModule &IGM,
/// The first element is the selector.
selectorRef = IGM.getAddrOfObjCMethodName(selector.str());

/// The second element is the type @encoding.
/// The second element is the method signature. A method signature is made of
/// the return type @encoding and every parameter type @encoding, glued with
/// numbers that used to represent stack offsets for each of these elements.
CanSILFunctionType methodType = getObjCMethodType(IGM, method);
atEncoding = getObjCEncodingForMethodType(IGM, methodType, extendedEncoding);

Expand Down Expand Up @@ -1349,9 +1351,13 @@ void irgen::emitObjCIVarInitDestroyDescriptor(IRGenModule &IGM,
Selector selector(declRef);
auto selectorRef = IGM.getAddrOfObjCMethodName(selector.str());

/// The second element is the type @encoding, which is always "@?"
/// for a function type.
auto atEncoding = IGM.getAddrOfGlobalString("@?");
/// The second element is the method signature. A method signature is made of
/// the return type @encoding and every parameter type @encoding, glued with
/// numbers that used to represent stack offsets for each of these elements.
auto ptrSize = IGM.getPointerSize().getValue();
llvm::SmallString<8> signature;
signature = "v" + llvm::itostr(ptrSize * 2) + "@0:" + llvm::itostr(ptrSize);
auto atEncoding = IGM.getAddrOfGlobalString(signature);

/// The third element is the method implementation pointer.
auto impl = llvm::ConstantExpr::getBitCast(objcImpl, IGM.Int8PtrTy);
Expand Down
21 changes: 19 additions & 2 deletions test/IRGen/objc_methods.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ class Foo: Fooable {
@objc func fail() throws {}
}

// CHECK: [[BAZ_SIGNATURE:@.*]] = private unnamed_addr constant [8 x i8] c"v16@0:8\00"
class ObjcDestructible: NSObject {
var object: NSObject

init(object: NSObject) {
self.object = object
}
}

// CHECK: [[NO_ARGS_SIGNATURE:@.*]] = private unnamed_addr constant [8 x i8] c"v16@0:8\00"
// CHECK: [[GARPLY_SIGNATURE:@.*]] = private unnamed_addr constant [11 x i8] c"v24@0:8@16\00"
// CHECK: [[BLOCK_SIGNATURE_TRAD:@.*]] = private unnamed_addr constant [12 x i8] c"v24@0:8@?16\00"
// CHECK-macosx: [[FAIL_SIGNATURE:@.*]] = private unnamed_addr constant [12 x i8] c"c24@0:8^@16\00"
Expand All @@ -45,7 +53,7 @@ class Foo: Fooable {
// CHECK: i32 9,
// CHECK: [9 x { i8*, i8*, i8* }] [{
// CHECK: i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01L_selector_data(baz)", i64 0, i64 0),
// CHECK: i8* getelementptr inbounds ([8 x i8], [8 x i8]* [[BAZ_SIGNATURE]], i64 0, i64 0),
// CHECK: i8* getelementptr inbounds ([8 x i8], [8 x i8]* [[NO_ARGS_SIGNATURE]], i64 0, i64 0),
// CHECK: i8* bitcast (void (i8*, i8*)* @"$S12objc_methods3FooC3bazyyFTo" to i8*)
// CHECK: }, {
// CHECK: i8* getelementptr inbounds ([8 x i8], [8 x i8]* @"\01L_selector_data(garply:)", i64 0, i64 0),
Expand All @@ -66,6 +74,15 @@ class Foo: Fooable {
// CHECK-ios: i8* bitcast (i1 (i8*, i8*, %4**)* @"$S12objc_methods3FooC4failyyKFTo" to i8*)
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: @_INSTANCE_METHODS__TtC12objc_methods16ObjcDestructible = private constant { {{.*}}] } {
// CHECK: i32 24,
// CHECK: i32 2,
// CHECK: [2 x { i8*, i8*, i8* }] [{
// CHECK: i8* getelementptr inbounds ([14 x i8], [14 x i8]* @"\01L_selector_data(.cxx_destruct)", i64 0, i64 0),
// CHECK: i8* getelementptr inbounds ([8 x i8], [8 x i8]* [[NO_ARGS_SIGNATURE]], i64 0, i64 0),
// CHECK: i8* bitcast (void (%6*, i8*)* @"$S12objc_methods16ObjcDestructibleCfETo" to i8*) }]
// CHECK: }]
// CHECK: }, section "__DATA, __objc_const", align 8
// CHECK: [[BLOCK_SIGNATURE_EXT_1:@.*]] = private unnamed_addr constant [18 x i8] c"v24@0:8@?<q@?q>16\00"
// CHECK: [[BLOCK_SIGNATURE_EXT_2:@.*]] = private unnamed_addr constant [19 x i8] c"v24@0:8@?<q@?qq>16\00"
// CHECK: [[STRING_SIGNATURE_EXT:@.*]] = private unnamed_addr constant [31 x i8] c"@\22NSString\2224@0:8@\22NSString\2216\00"
Expand Down