Skip to content

Commit a16c485

Browse files
committed
IRGen: "Simple" partial_apply still needs to re-sign the entry point pointer.
Fixes rdar://problem/63184042
1 parent db8c500 commit a16c485

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,16 +2659,20 @@ void IRGenSILFunction::visitPartialApplyInst(swift::PartialApplyInst *i) {
26592659
if (isSimplePartialApply(*this, i)) {
26602660
Explosion function;
26612661

2662-
auto schema = IGM.getTypeInfo(v->getType()).getSchema();
2662+
auto &ti = IGM.getTypeInfo(v->getType());
2663+
auto schema = ti.getSchema();
26632664
assert(schema.size() == 2);
26642665
auto calleeTy = schema[0].getScalarType();
26652666
auto contextTy = schema[1].getScalarType();
2666-
26672667
auto callee = getLoweredExplosion(i->getCallee());
26682668
auto calleeValue = callee.claimNext();
26692669
assert(callee.empty());
26702670
calleeValue = Builder.CreateBitOrPointerCast(calleeValue, calleeTy);
2671-
function.add(calleeValue);
2671+
2672+
// Re-sign the implementation pointer as a closure entry point.
2673+
auto calleeFn = FunctionPointer::forExplosionValue(*this, calleeValue,
2674+
i->getOrigCalleeType());
2675+
function.add(calleeFn.getExplosionValue(*this, i->getFunctionType()));
26722676

26732677
Explosion context;
26742678
for (auto arg : i->getArguments()) {

test/IRGen/simple_partial_apply.sil

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-cpu
22

33
sil_stage canonical
44

@@ -13,7 +13,8 @@ struct SingleRefcounted {
1313
}
1414

1515
// CHECK-LABEL: define {{.*}} @escape_partial_apply_swift_class
16-
// CHECK: [[FPTR:%.*]] = insertvalue { i8*, %swift.refcounted* } undef, i8* %0, 0
16+
// CHECK-arm64e: call i64 @llvm.ptrauth.resign.i64
17+
// CHECK: [[FPTR:%.*]] = insertvalue { i8*, %swift.refcounted* } undef, i8* {{.*}}, 0
1718
// CHECK-NEXT: [[FCTX:%.*]] = insertvalue { i8*, %swift.refcounted* } [[FPTR]], %swift.refcounted* {{.*}}, 1
1819
// CHECK-NEXT: ret { i8*, %swift.refcounted* } [[FCTX]]
1920
sil @escape_partial_apply_swift_class : $@convention(thin) (@convention(method) (Int, @guaranteed C) -> Int, @guaranteed C) -> @callee_guaranteed (Int) -> Int {
@@ -23,7 +24,8 @@ entry(%body : $@convention(method) (Int, @guaranteed C) -> Int, %context : $C):
2324
}
2425

2526
// CHECK-LABEL: define {{.*}} @escape_partial_apply_swift_single_refcount_struct
26-
// CHECK: [[FPTR:%.*]] = insertvalue { i8*, %swift.refcounted* } undef, i8* %0, 0
27+
// CHECK-arm64e: call i64 @llvm.ptrauth.resign.i64
28+
// CHECK: [[FPTR:%.*]] = insertvalue { i8*, %swift.refcounted* } undef, i8* {{.*}}, 0
2729
// CHECK-NEXT: [[FCTX:%.*]] = insertvalue { i8*, %swift.refcounted* } [[FPTR]], %swift.refcounted* {{.*}}, 1
2830
// CHECK-NEXT: ret { i8*, %swift.refcounted* } [[FCTX]]
2931
sil @escape_partial_apply_swift_single_refcount_struct : $@convention(thin) (@convention(method) (Int, @guaranteed SingleRefcounted) -> Int, @guaranteed SingleRefcounted) -> @callee_guaranteed (Int) -> Int {
@@ -33,9 +35,10 @@ entry(%body : $@convention(method) (Int, @guaranteed SingleRefcounted) -> Int, %
3335
}
3436

3537
// CHECK-LABEL: define {{.*}} @noescape_partial_apply_swift_indirect
38+
// CHECK-arm64e: call i64 @llvm.ptrauth.resign.i64
3639
// CHECK: [[CTX:%.*]] = bitcast {{.*}}** %1 to %swift.opaque*
3740
// CHECK-NEXT: [[CONT:%.*]] = bitcast i8* %2
38-
// CHECK-NEXT: call {{.*}}void [[CONT]](i8* %0, %swift.opaque* [[CTX]], %swift.refcounted* {{.*}}%3)
41+
// CHECK-NEXT: call {{.*}}void [[CONT]](i8* {{.*}}, %swift.opaque* [[CTX]], %swift.refcounted* {{.*}}%3)
3942
sil @noescape_partial_apply_swift_indirect : $@convention(thin) (@convention(method) (Int, @in_guaranteed C) -> Int, @in_guaranteed C, @guaranteed @callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()) -> () {
4043
entry(%body : $@convention(method) (Int, @in_guaranteed C) -> Int, %context : $*C, %cont : $@callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()):
4144
%closure = partial_apply [callee_guaranteed] [on_stack] %body(%context) : $@convention(method) (Int, @in_guaranteed C) -> Int
@@ -45,9 +48,10 @@ entry(%body : $@convention(method) (Int, @in_guaranteed C) -> Int, %context : $*
4548
}
4649

4750
// CHECK-LABEL: define {{.*}} @noescape_partial_apply_swift_direct_word
51+
// CHECK-arm64e: call i64 @llvm.ptrauth.resign.i64
4852
// CHECK: [[CTX:%.*]] = inttoptr i{{.*}} %1 to %swift.opaque*
4953
// CHECK-NEXT: [[CONT:%.*]] = bitcast i8* %2
50-
// CHECK-NEXT: call {{.*}}void [[CONT]](i8* %0, %swift.opaque* [[CTX]], %swift.refcounted* {{.*}}%3)
54+
// CHECK-NEXT: call {{.*}}void [[CONT]](i8* {{.*}}, %swift.opaque* [[CTX]], %swift.refcounted* {{.*}}%3)
5155
sil @noescape_partial_apply_swift_direct_word : $@convention(thin) (@convention(method) (Int, Int) -> Int, Int, @guaranteed @callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()) -> () {
5256
entry(%body : $@convention(method) (Int, Int) -> Int, %context : $Int, %cont : $@callee_guaranteed (@noescape @callee_guaranteed (Int) -> Int) -> ()):
5357
%closure = partial_apply [callee_guaranteed] [on_stack] %body(%context) : $@convention(method) (Int, Int) -> Int

0 commit comments

Comments
 (0)