1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
// 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: @global_function.ptrauth = private constant { ptr, i32, i64, i64 } { ptr @global_function, i32 0, i64 0, i64 {{.*}} }, section "llvm.ptrauth", align 8
sil @global_function : $@convention(thin) () -> ()
sil @test_sign : $@convention(thin) () -> @convention(thin) () -> () {
bb0:
%0 = function_ref @global_function : $@convention(thin) () -> ()
return %0 : $@convention(thin) () -> ()
}
// CHECK-LABEL: define swiftcc ptr @test_sign()
// CHECK: ret ptr @global_function.ptrauth
sil @test_direct_call : $@convention(thin) () -> () {
bb0:
%0 = function_ref @global_function : $@convention(thin) () -> ()
%1 = apply %0() : $@convention(thin) () -> ()
return %1 : $()
}
// CHECK-LABEL: define swiftcc void @test_direct_call()
// CHECK: call swiftcc void @global_function(){{$}}
sil @test_indirect_call_thin : $@convention(thin) (@convention(thin) () -> ()) -> () {
bb0(%0 : $@convention(thin) () -> ()):
%1 = apply %0() : $@convention(thin) () -> ()
return %1 : $()
}
// CHECK-LABEL: define swiftcc void @test_indirect_call_thin(ptr %0)
// CHECK: call swiftcc void %0() [ "ptrauth"(i32 0, i64 {{.*}}) ]
sil @test_indirect_call_thick : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> () {
bb0(%0 : $@callee_guaranteed () -> ()):
%1 = apply %0() : $@callee_guaranteed () -> ()
return %1 : $()
}
// CHECK-LABEL: define swiftcc void @test_indirect_call_thick(ptr %0, ptr %1)
// CHECK: call swiftcc void %0(ptr swiftself %1) [ "ptrauth"(i32 0, i64 {{.*}}) ]
sil @test_indirect_call_c : $@convention(thin) (@convention(c) () -> ()) -> () {
bb0(%0 : $@convention(c) () -> ()):
%1 = apply %0() : $@convention(c) () -> ()
return %1 : $()
}
// CHECK-LABEL: define swiftcc void @test_indirect_call_c(ptr %0)
// CHECK: call void %0() [ "ptrauth"(i32 0, i64 {{.*}}) ]
sil @test_thin_to_thick : $@convention(thin) (@convention(thin) () -> ()) -> (@callee_guaranteed () -> ()) {
bb0(%0 : $@convention(thin) () -> ()):
%1 = thin_to_thick_function %0 : $@convention(thin) () -> () to $@callee_guaranteed () -> ()
return %1 : $@callee_guaranteed () -> ()
}
// CHECK-LABEL: define swiftcc { ptr, ptr } @test_thin_to_thick(ptr %0)
// CHECK: [[T0:%.*]] = insertvalue { ptr, ptr } undef, ptr %0, 0
// CHECK-NEXT: [[T1:%.*]] = insertvalue { ptr, ptr } [[T0]], ptr null, 1
// CHECK-NEXT: ret { ptr, ptr } [[T1]]
sil @test_sign_thin_to_thick : $@convention(thin) () -> (@callee_guaranteed () -> ()) {
bb0:
%0 = function_ref @global_function : $@convention(thin) () -> ()
%1 = thin_to_thick_function %0 : $@convention(thin) () -> () to $@callee_guaranteed () -> ()
return %1 : $@callee_guaranteed () -> ()
}
// CHECK: define swiftcc { ptr, ptr } @test_sign_thin_to_thick() #[[ATTRS:[0-9]+]] {
// CHECK: ret { ptr, ptr } { ptr @global_function.ptrauth, ptr null }
class F {}
sil @generic_return : $@convention(thin) @yield_once <T : F> (@guaranteed T) -> @yields @guaranteed T
sil @test_generic_return : $@convention(thin) <T : F> (@guaranteed T) -> () {
bb0(%0 : $T):
%1 = function_ref @generic_return : $@convention(thin) @yield_once <T : F> (@guaranteed T) -> (@yields @guaranteed T)
(%value, %token) = begin_apply %1<T>(%0) : $@convention(thin) @yield_once <T : F> (@guaranteed T) -> (@yields @guaranteed T)
end_apply %token
%ret = tuple ()
return %ret : $()
}
sil_vtable F {
}
// CHECK: #[[ATTRS]] = {{{.*}} "ptrauth-auth-traps" "ptrauth-calls" "ptrauth-indirect-gotos" "ptrauth-returns"
|