Files
swift-mirror/test/IRGen/ptrauth-partial-apply.sil
Nate Chandler 62d5b729cf [Test] Matched ordering in ptrauth-partial-apply.sil.
In f1d263b2ba, partial apply forwarder
emission was tweaked by moving the ptrauth emission for dynamic function
pointers prior to the bitcast to enable the emitted ptrauth info to be
used in extracting values from the async function pointer.  Here, the
ptrauth-partial-apply.sil test is updated to reflect that change.
2020-12-07 08:53:32 -08:00

65 lines
5.0 KiB
Plaintext

// RUN: %swift -swift-version 4 -target arm64e-apple-ios12.0 -parse-stdlib -parse-as-library %s -emit-ir -module-name test -Xcc -Xclang -Xcc -fptrauth-calls | %FileCheck %s --check-prefix=CHECK
// REQUIRES: CPU=arm64e
// REQUIRES: OS=ios
import Builtin
// CHECK: @"$sTA.ptrauth" = private constant { i8*, i32, i64, i64 } { i8* bitcast (void (%swift.refcounted*)* @"$sTA" to i8*), i32 0, i64 0, i64 {{.*}} }, section "llvm.ptrauth"
sil @test_thin_indirect : $@convention(thin) (@convention(thin) (Builtin.Int32, Builtin.Int32) -> (), Builtin.Int32) -> @owned @callee_owned () -> () {
bb0(%0 : $@convention(thin) (Builtin.Int32, Builtin.Int32) -> (), %1 : $Builtin.Int32):
%2 = partial_apply %0(%1, %1) : $@convention(thin) (Builtin.Int32, Builtin.Int32) -> ()
return %2 : $@callee_owned () -> ()
}
// CHECK-LABEL: define swiftcc { i8*, %swift.refcounted* } @test_thin_indirect(i8* %0, i32 %1)
// CHECK: [[FN:%.*]] = bitcast i8* %0 to void (i32, i32)*
// CHECK: [[ALLOC:%.*]] = call {{.*}}swift_allocObject(
// CHECK: [[CTXT:%.*]] = bitcast %swift.refcounted* [[ALLOC]] to [[CTXT_TY:<{ %swift.refcounted, i32, i32, i8\* }>]]*
// CHECK: [[SLOT:%.*]] = getelementptr inbounds [[CTXT_TY]], [[CTXT_TY]]* [[CTXT]], i32 0, i32 3
// CHECK: [[T0:%.*]] = ptrtoint i8** [[SLOT]] to i64
// CHECK: [[DISC:%.*]] = call i64 @llvm.ptrauth.blend.i64(i64 [[T0]], i64 7185)
// CHECK: [[T0:%.*]] = ptrtoint void (i32, i32)* [[FN]] to i64
// CHECK: [[T1:%.*]] = call i64 @llvm.ptrauth.resign.i64(i64 [[T0]], i32 0, i64 {{.*}}, i32 1, i64 [[DISC]])
// CHECK: [[T2:%.*]] = inttoptr i64 [[T1]] to void (i32, i32)*
// CHECK: [[T3:%.*]] = bitcast void (i32, i32)* [[T2]] to i8*
// CHECK: store i8* [[T3]], i8** [[SLOT]], align 8
// CHECK: insertvalue { i8*, %swift.refcounted* } { i8* bitcast ({ i8*, i32, i64, i64 }* @"$sTA.ptrauth" to i8*), %swift.refcounted* undef }, %swift.refcounted* {{.*}}, 1
// CHECK-LABEL: define internal swiftcc void @"$sTA"(%swift.refcounted* swiftself %0)
// CHECK: [[T0:%.*]] = bitcast %swift.refcounted* %0 to [[CTXT_TY:<{ %swift.refcounted, i32, i32, i8\* }>]]*
// CHECK: [[SLOT:%.*]] = getelementptr inbounds [[CTXT_TY]], [[CTXT_TY]]* [[T0]], i32 0, i32 3
// CHECK: [[T0:%.*]] = load i8*, i8** [[SLOT]], align 8
// CHECK: [[T1:%.*]] = ptrtoint i8** [[SLOT]] to i64
// CHECK: [[DISC:%.*]] = call i64 @llvm.ptrauth.blend.i64(i64 [[T1]], i64 7185)
// CHECK: [[FN:%.*]] = bitcast i8* [[T0]] to void (i32, i32)*
// CHECK: call swiftcc void [[FN]](i32 {{.*}}, i32 {{.*}}) [ "ptrauth"(i32 1, i64 [[DISC]]) ]
sil @test_thick_indirect : $@convention(thin) (@callee_owned (Builtin.Int32, Builtin.Int32) -> (), Builtin.Int32) -> @owned @callee_owned () -> () {
bb0(%0 : $@callee_owned (Builtin.Int32, Builtin.Int32) -> (), %1 : $Builtin.Int32):
%2 = partial_apply %0(%1, %1) : $@callee_owned (Builtin.Int32, Builtin.Int32) -> ()
return %2 : $@callee_owned () -> ()
}
// CHECK-LABEL: define swiftcc { i8*, %swift.refcounted* } @test_thick_indirect(i8* %0, %swift.refcounted* %1, i32 %2)
// CHECK: [[FN:%.*]] = bitcast i8* %0 to void (i32, i32, %swift.refcounted*)*
// CHECK: [[ALLOC:%.*]] = call {{.*}}swift_allocObject(
// CHECK: [[CTXT:%.*]] = bitcast %swift.refcounted* [[ALLOC]] to [[CTXT_TY:<{ %swift.refcounted, i32, i32, %swift.refcounted\*, i8\* }>]]*
// CHECK: [[SLOT:%.*]] = getelementptr inbounds [[CTXT_TY]], [[CTXT_TY]]* {{%.*}}, i32 0, i32 4
// CHECK: [[T0:%.*]] = ptrtoint i8** [[SLOT]] to i64
// CHECK: [[DISC:%.*]] = call i64 @llvm.ptrauth.blend.i64(i64 [[T0]], i64 7185)
// CHECK: [[T0:%.*]] = ptrtoint void (i32, i32, %swift.refcounted*)* [[FN]] to i64
// CHECK: [[T1:%.*]] = call i64 @llvm.ptrauth.resign.i64(i64 [[T0]], i32 0, i64 {{.*}}, i32 1, i64 [[DISC]])
// CHECK: [[T2:%.*]] = inttoptr i64 [[T1]] to void (i32, i32, %swift.refcounted*)*
// CHECK: [[T3:%.*]] = bitcast void (i32, i32, %swift.refcounted*)* [[T2]] to i8*
// CHECK: store i8* [[T3]], i8** [[SLOT]], align 8
// CHECK: insertvalue { i8*, %swift.refcounted* } { i8* bitcast ({ i8*, i32, i64, i64 }* @"$sTA{{.*}}.ptrauth" to i8*), %swift.refcounted* undef }, %swift.refcounted* {{.*}}, 1
// CHECK-LABEL: define internal swiftcc void @"$sTA{{.*}}"(%swift.refcounted* swiftself %0)
// CHECK: [[T0:%.*]] = bitcast %swift.refcounted* %0 to <{ %swift.refcounted, i32, i32, %swift.refcounted*, i8* }>*
// CHECK: [[SLOT:%.*]] = getelementptr inbounds <{ %swift.refcounted, i32, i32, %swift.refcounted*, i8* }>, <{ %swift.refcounted, i32, i32, %swift.refcounted*, i8* }>* [[T0]], i32 0, i32 4
// CHECK: [[T0:%.*]] = load i8*, i8** [[SLOT]], align 8
// CHECK: [[T1:%.*]] = ptrtoint i8** [[SLOT]] to i64
// CHECK: [[DISC:%.*]] = call i64 @llvm.ptrauth.blend.i64(i64 [[T1]], i64 7185)
// CHECK: [[FN:%.*]] = bitcast i8* [[T0]] to void (i32, i32, %swift.refcounted*)*
// CHECK: call swiftcc void [[FN]](i32 {{.*}}, i32 {{.*}}, %swift.refcounted* {{.*}}) [ "ptrauth"(i32 1, i64 [[DISC]]) ]