Skip to content

Commit f05e063

Browse files
authored
Merge pull request swiftlang#31799 from jckarter/simple-partial-apply-arm64e
IRGen: "Simple" partial_apply still needs to re-sign the entry point pointer.
2 parents 47d1457 + a16c485 commit f05e063

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
@@ -2661,16 +2661,20 @@ void IRGenSILFunction::visitPartialApplyInst(swift::PartialApplyInst *i) {
26612661
if (isSimplePartialApply(*this, i)) {
26622662
Explosion function;
26632663

2664-
auto schema = IGM.getTypeInfo(v->getType()).getSchema();
2664+
auto &ti = IGM.getTypeInfo(v->getType());
2665+
auto schema = ti.getSchema();
26652666
assert(schema.size() == 2);
26662667
auto calleeTy = schema[0].getScalarType();
26672668
auto contextTy = schema[1].getScalarType();
2668-
26692669
auto callee = getLoweredExplosion(i->getCallee());
26702670
auto calleeValue = callee.claimNext();
26712671
assert(callee.empty());
26722672
calleeValue = Builder.CreateBitOrPointerCast(calleeValue, calleeTy);
2673-
function.add(calleeValue);
2673+
2674+
// Re-sign the implementation pointer as a closure entry point.
2675+
auto calleeFn = FunctionPointer::forExplosionValue(*this, calleeValue,
2676+
i->getOrigCalleeType());
2677+
function.add(calleeFn.getExplosionValue(*this, i->getFunctionType()));
26742678

26752679
Explosion context;
26762680
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)