Skip to content

IRGen: Fix ObjectiveC partial apply forwarding stub #11310

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
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: 11 additions & 3 deletions lib/IRGen/GenObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,8 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM,
// Otherwise, we have a loadable type that can either be passed directly or
// indirectly.
assert(info.getSILStorageType().isObject());
auto &ti =
cast<LoadableTypeInfo>(IGM.getTypeInfo(info.getSILStorageType()));
auto curSILType = info.getSILStorageType();
auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo(curSILType));

// Load the indirectly passed parameter.
auto &nativeSchema = ti.nativeParameterValueSchema(IGM);
Expand All @@ -881,8 +881,16 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM,
ti.loadAsTake(subIGF, paramAddr, translatedParams);
continue;
}
// Map from the native calling convention into the explosion schema.
auto &nativeParamSchema = ti.nativeParameterValueSchema(IGM);
Explosion nativeParam;
params.transferInto(nativeParam, nativeParamSchema.size());
Explosion nonNativeParam = nativeParamSchema.mapFromNative(
subIGF.IGM, subIGF, nativeParam, curSILType);
assert(nativeParam.empty());

// Pass along the value.
ti.reexplode(subIGF, params, translatedParams);
ti.reexplode(subIGF, nonNativeParam, translatedParams);
}

// Prepare the call to the underlying method.
Expand Down
8 changes: 8 additions & 0 deletions test/IRGen/Inputs/usr/include/Gizmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ struct NSRect {
} size;
};

struct Fob {
unsigned long a;
unsigned b;
unsigned c;
unsigned long d;
} Fob;

typedef long NSInteger;

@interface Gizmo : NSObject
Expand All @@ -37,6 +44,7 @@ typedef long NSInteger;
- (struct NSRect) frame;
- (void) setFrame: (struct NSRect) rect;
- (void) frob;
- (void) test: (struct Fob) fob;
+ (void) runce;
@end

Expand Down
27 changes: 27 additions & 0 deletions test/IRGen/partial_apply_objc.sil
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,30 @@ entry(%c : $Gizmo):
%g = partial_apply %f(%c) : $@convention(thin) Gizmo -> ()
return %g : $@callee_owned () -> ()
}

// CHECK: define internal swiftcc void @_T0Ta.17(i64, i64, i64, %swift.refcounted* swiftself)
// CHECK: [[TMPCOERCE:%.*]] = alloca { i64, i64, i64 }
// CHECK: [[INDIRECTTEMP:%.*]] = alloca %TSC3FobV
// CHECK: [[ADDR:%.*]] = getelementptr inbounds { i64, i64, i64 }, { i64, i64, i64 }* [[TMPCOERCE]], i32 0, i32 0
// CHECK: store i64 %0, i64* [[ADDR]]
// CHECK: [[ADDR:%.]] = getelementptr inbounds { i64, i64, i64 }, { i64, i64, i64 }* [[TMPCOERCE]], i32 0, i32 1
// CHECK: store i64 %1, i64* [[ADDR]]
// CHECK: [[ADDR:%.*]] = getelementptr inbounds { i64, i64, i64 }, { i64, i64, i64 }* [[TMPCOERCE]], i32 0, i32 2
// CHECK: store i64 %2, i64* [[ADDR]]
// CHECK: load i64
// CHECK: load i32
// CHECK: load i32
// CHECK: load i64
// CHECK: store i64
// CHECK: store i32
// CHECK: store i32
// CHECK: store i64
// CHECK: objc_msgSend
// CHECK: ret void

sil @objc_partial_apply_2 : $@convention(thin) Gizmo -> @callee_owned (Fob) -> () {
entry(%c : $Gizmo):
%m = class_method [volatile] %c : $Gizmo, #Gizmo.test!1.foreign : (Gizmo) -> (Fob) -> (), $@convention(objc_method) (Fob, Gizmo) -> ()
%p = partial_apply %m(%c) : $@convention(objc_method) (Fob, Gizmo) -> ()
return %p : $@callee_owned (Fob) -> ()
}