Skip to content

Commit c34fe93

Browse files
committed
[IRGen] Generate proper type descriptors for ObjC subscript accessors
https://bugs.swift.org/browse/SR-8356 rdar://problem/42284266
1 parent 4abb570 commit c34fe93

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ class ObjCProtocolInitializerVisitor
434434
Builder.CreateCall(protocol_addMethodDescription, getterArgs);
435435

436436
if (prop->isSettable(nullptr)) {
437-
emitObjCSetterDescriptorParts(IGM, prop, name, types, imp);
437+
emitObjCSetterDescriptorParts(IGM, prop,
438+
name, types, imp);
438439
sel = Builder.CreateCall(IGM.getObjCSelRegisterNameFn(), name);
439440
llvm::Value *setterArgs[] = {
440441
NewProto, sel, types,

lib/IRGen/GenObjC.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,8 @@ SILFunction *irgen::emitObjCGetterDescriptorParts(IRGenModule &IGM,
11951195
llvm::Constant *&impl) {
11961196
Selector getterSel(subscript, Selector::ForGetter);
11971197
selectorRef = IGM.getAddrOfObjCMethodName(getterSel.str());
1198-
atEncoding = llvm::ConstantPointerNull::get(IGM.Int8PtrTy);
1198+
CanSILFunctionType methodTy = getObjCMethodType(IGM, subscript->getGetter());
1199+
atEncoding = getObjCEncodingForMethodType(IGM, methodTy, /*extended*/false);
11991200
SILFunction *silFn = nullptr;
12001201
impl = getObjCGetterPointer(IGM, subscript, silFn);
12011202
return silFn;
@@ -1270,7 +1271,8 @@ SILFunction *irgen::emitObjCSetterDescriptorParts(IRGenModule &IGM,
12701271

12711272
Selector setterSel(subscript, Selector::ForSetter);
12721273
selectorRef = IGM.getAddrOfObjCMethodName(setterSel.str());
1273-
atEncoding = llvm::ConstantPointerNull::get(IGM.Int8PtrTy);
1274+
CanSILFunctionType methodTy = getObjCMethodType(IGM, subscript->getSetter());
1275+
atEncoding = getObjCEncodingForMethodType(IGM, methodTy, /*extended*/false);
12741276
SILFunction *silFn = nullptr;
12751277
impl = getObjCSetterPointer(IGM, subscript, silFn);
12761278
return silFn;
@@ -1379,8 +1381,8 @@ void irgen::emitObjCGetterDescriptor(IRGenModule &IGM,
13791381
ConstantArrayBuilder &descriptors,
13801382
AbstractStorageDecl *storage) {
13811383
llvm::Constant *selectorRef, *atEncoding, *impl;
1382-
auto *silFn = emitObjCGetterDescriptorParts(IGM, storage, selectorRef,
1383-
atEncoding, impl);
1384+
auto *silFn = emitObjCGetterDescriptorParts(IGM, storage,
1385+
selectorRef, atEncoding, impl);
13841386
buildMethodDescriptor(descriptors, selectorRef, atEncoding, impl);
13851387
if (silFn && silFn->hasObjCReplacement()) {
13861388
auto replacedSelector =
@@ -1393,8 +1395,8 @@ void irgen::emitObjCSetterDescriptor(IRGenModule &IGM,
13931395
ConstantArrayBuilder &descriptors,
13941396
AbstractStorageDecl *storage) {
13951397
llvm::Constant *selectorRef, *atEncoding, *impl;
1396-
auto *silFn = emitObjCSetterDescriptorParts(IGM, storage, selectorRef,
1397-
atEncoding, impl);
1398+
auto *silFn = emitObjCSetterDescriptorParts(IGM, storage,
1399+
selectorRef, atEncoding, impl);
13981400
buildMethodDescriptor(descriptors, selectorRef, atEncoding, impl);
13991401
if (silFn && silFn->hasObjCReplacement()) {
14001402
auto replacedSelector =

test/IRGen/objc_protocol_extended_method_types.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
import Foundation
99

10-
// CHECK: [[INIT:@.*]] = private unnamed_addr constant [8 x i8] c"@16@0:8\00"
11-
// CHECK: [[NSNUMBER:@.*]] = private unnamed_addr constant [31 x i8] c"@\22NSNumber\2224@0:8@\22NSNumber\2216\00"
12-
// CHECK: [[NSMUTABLEARRAY_GET:@.*]] = private unnamed_addr constant [24 x i8] c"@\22NSMutableArray\2216@0:8\00"
13-
// CHECK: [[NSMUTABLEARRAY_SET:@.*]] = private unnamed_addr constant [27 x i8] c"v24@0:8@\22NSMutableArray\2216\00"
14-
// CHECK: [[SUBSCRIPT:@.*]] = private unnamed_addr constant [11 x i8] c"q24@0:8q16\00"
15-
// CHECK: [[NSSTRING:@.*]] = private unnamed_addr constant [31 x i8] c"@\22NSString\2224@0:8@\22NSString\2216\00"
16-
// CHECK: [[NSOBJECT:@.*]] = private unnamed_addr constant [31 x i8] c"@\22NSObject\2224@0:8@\22NSObject\2216\00"
17-
// CHECK: [[NSMUTABLESTRING:@.*]] = private unnamed_addr constant [28 x i8] c"v24@0:8@\22NSMutableString\2216\00"
10+
// CHECK-DAG: [[INIT:@.*]] = private unnamed_addr constant [8 x i8] c"@16@0:8\00"
11+
// CHECK-DAG: [[NSNUMBER:@.*]] = private unnamed_addr constant [31 x i8] c"@\22NSNumber\2224@0:8@\22NSNumber\2216\00"
12+
// CHECK-DAG: [[NSMUTABLEARRAY_GET:@.*]] = private unnamed_addr constant [24 x i8] c"@\22NSMutableArray\2216@0:8\00"
13+
// CHECK-DAG: [[NSMUTABLEARRAY_SET:@.*]] = private unnamed_addr constant [27 x i8] c"v24@0:8@\22NSMutableArray\2216\00"
14+
// CHECK-DAG: [[SUBSCRIPT:@.*]] = private unnamed_addr constant [11 x i8] c"q24@0:8q16\00"
15+
// CHECK-DAG: [[NSSTRING:@.*]] = private unnamed_addr constant [31 x i8] c"@\22NSString\2224@0:8@\22NSString\2216\00"
16+
// CHECK-DAG: [[NSOBJECT:@.*]] = private unnamed_addr constant [31 x i8] c"@\22NSObject\2224@0:8@\22NSObject\2216\00"
17+
// CHECK-DAG: [[NSMUTABLESTRING:@.*]] = private unnamed_addr constant [28 x i8] c"v24@0:8@\22NSMutableString\2216\00"
1818

1919
// CHECK-LABEL: @_PROTOCOL_METHOD_TYPES__TtP35objc_protocol_extended_method_types1P_ = private constant [16 x i8*] [
2020
// -- required instance methods:

test/IRGen/objc_subscripts.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,37 @@
22

33
// REQUIRES: CPU=x86_64
44

5+
// CHECK: [[INDEXED_GETTER_ENCODING:@.+]] = private unnamed_addr constant [11 x i8] c"@24@0:8q16\00"
6+
// CHECK: [[INDEXED_SETTER_ENCODING:@.+]] = private unnamed_addr constant [14 x i8] c"v32@0:8@16q24\00"
7+
// CHECK: [[KEYED_GETTER_ENCODING:@.+]] = private unnamed_addr constant [11 x i8] c"q24@0:8@16\00"
8+
// CHECK: [[KEYED_SETTER_ENCODING:@.+]] = private unnamed_addr constant [14 x i8] c"v32@0:8q16@24\00"
9+
510
// CHECK: @_INSTANCE_METHODS__TtC15objc_subscripts10SomeObject =
611
// CHECK: private constant { i32, i32, [5 x { i8*, i8*, i8* }] }
712
// CHECK: { i32 24, i32 5, [5 x { i8*, i8*, i8* }]
813
// CHECK: [
914
// CHECK: { i8*, i8*, i8* }
1015
// CHECK: {
1116
// CHECK: i8* getelementptr inbounds ([26 x i8], [26 x i8]* @"\01L_selector_data(objectAtIndexedSubscript:)", i64 0, i64 0),
12-
// CHECK: i8* null,
17+
// CHECK: i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[INDEXED_GETTER_ENCODING]], i64 0, i64 0),
1318
// CHECK: i8* bitcast ([[OPAQUE0:%.*]]* ([[OPAQUE1:%.*]]*, i8*, i64)* @"$s15objc_subscripts10SomeObjectCyACSicigTo" to i8*)
1419
// CHECK: },
1520
// CHECK: { i8*, i8*, i8* }
1621
// CHECK: {
1722
// CHECK: i8* getelementptr inbounds ([30 x i8], [30 x i8]* @"\01L_selector_data(setObject:atIndexedSubscript:)", i64 0, i64 0),
18-
// CHECK: i8* null,
23+
// CHECK: i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[INDEXED_SETTER_ENCODING]], i64 0, i64 0),
1924
// CHECK: i8* bitcast (void ([[OPAQUE2:%.*]]*, i8*, [[OPAQUE3:%.*]]*, i64)* @"$s15objc_subscripts10SomeObjectCyACSicisTo" to i8*)
2025
// CHECK: },
2126
// CHECK: { i8*, i8*, i8* }
2227
// CHECK: {
2328
// CHECK: i8* getelementptr inbounds ([25 x i8], [25 x i8]* @"\01L_selector_data(objectForKeyedSubscript:)", i64 0, i64 0),
24-
// CHECK: i8* null,
29+
// CHECK: i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[KEYED_GETTER_ENCODING]], i64 0, i64 0),
2530
// CHECK: i8* bitcast (i64 ([[OPAQUE4:%.*]]*, i8*, [[OPAQUE5:%.*]]*)* @"$s15objc_subscripts10SomeObjectCySiACcigTo" to i8*)
2631
// CHECK: },
2732
// CHECK: { i8*, i8*, i8* }
2833
// CHECK: {
2934
// CHECK: i8* getelementptr inbounds ([29 x i8], [29 x i8]* @"\01L_selector_data(setObject:forKeyedSubscript:)", i64 0, i64 0),
30-
// CHECK: i8* null,
35+
// CHECK: i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[KEYED_SETTER_ENCODING]], i64 0, i64 0),
3136
// CHECK: i8* bitcast (void ([[OPAQUE6:%.*]]*, i8*, i64, [[OPAQUE7:%.*]]*)* @"$s15objc_subscripts10SomeObjectCySiACcisTo" to i8*)
3237
// CHECK: },
3338
// CHECK: { i8*, i8*, i8* }

0 commit comments

Comments
 (0)