|
| 1 | +// RUN: %swift-frontend %s -enable-import-ptrauth-field-function-pointers -emit-silgen -target arm64e-apple-ios13.0 -I %S/Inputs/ 2>&1 | %FileCheck %s |
| 2 | +// REQUIRES: CPU=arm64e |
| 3 | +// REQUIRES: OS=ios |
| 4 | + |
| 5 | +import PointerAuth |
| 6 | + |
| 7 | +// CHECK-LABEL: sil hidden [ossa] @$s25ptrauth_field_fptr_import05test_B8_fn_reads5Int32VyF : |
| 8 | +// CHECK: [[GLOB:%.*]] = global_addr @ptr_to_secure_struct : $*Optional<UnsafeMutablePointer<SecureStruct>> |
| 9 | +// CHECK: [[A1:%.*]] = begin_access [read] [dynamic] [[GLOB]] : $*Optional<UnsafeMutablePointer<SecureStruct>> |
| 10 | +// CHECK: [[LD1:%.*]] = load [trivial] [[A1]] : $*Optional<UnsafeMutablePointer<SecureStruct>> |
| 11 | +// CHECK: end_access [[A1]] : $*Optional<UnsafeMutablePointer<SecureStruct>> |
| 12 | +// CHECK: switch_enum [[LD1]] : $Optional<UnsafeMutablePointer<SecureStruct>>, case #Optional.some!enumelt: bb2, case #Optional.none!enumelt: bb1 |
| 13 | +// CHECK: bb2([[BBARG1:%.*]] : $UnsafeMutablePointer<SecureStruct>): |
| 14 | +// CHECK: [[F1:%.*]] = function_ref @$sSp7pointeexvlu : $@convention(method) <τ_0_0> (UnsafeMutablePointer<τ_0_0>) -> UnsafePointer<τ_0_0> |
| 15 | +// CHECK: [[PTR1:%.*]] = apply [[F1]]<SecureStruct>([[BBARG1]]) : $@convention(method) <τ_0_0> (UnsafeMutablePointer<τ_0_0>) -> UnsafePointer<τ_0_0> |
| 16 | +// CHECK: [[RAW1:%.*]] = struct_extract [[PTR1]] : $UnsafePointer<SecureStruct>, #UnsafePointer._rawValue |
| 17 | +// CHECK: [[ADDR1:%.*]] = pointer_to_address [[RAW1]] : $Builtin.RawPointer to [strict] $*SecureStruct |
| 18 | +// CHECK: [[A2:%.*]] = begin_access [read] [unsafe] [[ADDR1]] : $*SecureStruct |
| 19 | +// CHECK: [[ELEM1:%.*]] = struct_element_addr [[A2]] : $*SecureStruct, #SecureStruct.secure_func_ptr1 |
| 20 | +// CHECK: [[ASIGNED:%.*]] = begin_access [read] [signed] [[ELEM1]] : $*Optional<@convention(c) () -> Int32> |
| 21 | +// CHECK: [[FPLOAD:%.*]] = load [trivial] [[ASIGNED]] : $*Optional<@convention(c) () -> Int32> |
| 22 | +// CHECK: end_access [[ASIGNED]] : $*Optional<@convention(c) () -> Int32> |
| 23 | +// CHECK: end_access [[A2]] : $*SecureStruct |
| 24 | +// CHECK: switch_enum [[FPLOAD]] : $Optional<@convention(c) () -> Int32>, case #Optional.some!enumelt: bb4, case #Optional.none!enumelt: bb3 |
| 25 | +// CHECK-LABEL: } // end sil function '$s25ptrauth_field_fptr_import05test_B8_fn_reads5Int32VyF' |
| 26 | +func test_field_fn_read() -> Int32 { |
| 27 | + let fn = ptr_to_secure_struct!.pointee.secure_func_ptr1! |
| 28 | + return fn() |
| 29 | +} |
| 30 | + |
| 31 | +// CHECK-LABEL: sil hidden [ossa] @$s25ptrauth_field_fptr_import05test_B12_fn_ptr_swapyyF : |
| 32 | +// CHECK:bb8([[UMP:%.*]] : $UnsafeMutablePointer<SecureStruct>): |
| 33 | +// CHECK: [[F1:%.*]] = function_ref @$sSp7pointeexvau : $@convention(method) <τ_0_0> (UnsafeMutablePointer<τ_0_0>) -> UnsafeMutablePointer<τ_0_0> |
| 34 | +// CHECK: [[P:%.*]] = apply [[F1]]<SecureStruct>([[UMP]]) : $@convention(method) <τ_0_0> (UnsafeMutablePointer<τ_0_0>) -> UnsafeMutablePointer<τ_0_0> |
| 35 | +// CHECK: [[EX1:%.*]] = struct_extract [[P]] : $UnsafeMutablePointer<SecureStruct>, #UnsafeMutablePointer._rawValue |
| 36 | +// CHECK: [[ADDR:%.*]] = pointer_to_address [[EX1]] : $Builtin.RawPointer to [strict] $*SecureStruct |
| 37 | +// CHECK: [[A1:%.*]] = begin_access [modify] [unsafe] [[ADDR]] : $*SecureStruct |
| 38 | +// CHECK: [[ELEM1:%.*]] = struct_element_addr [[A1]] : $*SecureStruct, #SecureStruct.secure_func_ptr2 |
| 39 | +// CHECK: [[A2:%.*]] = begin_access [modify] [signed] [[ELEM1]] : $*Optional<@convention(c) () -> Int32> |
| 40 | +// CHECK: assign {{.*}} to [[A2]] : $*Optional<@convention(c) () -> Int32> |
| 41 | +// CHECK: end_access [[A2]] : $*Optional<@convention(c) () -> Int32> |
| 42 | +// CHECK: end_access [[A1]] : $*SecureStruct |
| 43 | +// CHECK-LABEL: } // end sil function '$s25ptrauth_field_fptr_import05test_B12_fn_ptr_swapyyF' |
| 44 | +func test_field_fn_ptr_swap() { |
| 45 | + let t = ptr_to_secure_struct!.pointee.secure_func_ptr1 |
| 46 | + ptr_to_secure_struct!.pointee.secure_func_ptr1 = ptr_to_secure_struct!.pointee.secure_func_ptr2 |
| 47 | + ptr_to_secure_struct!.pointee.secure_func_ptr2 = t |
| 48 | +} |
| 49 | + |
0 commit comments