|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=pointer_to_address | %FileCheck %s |
| 2 | + |
| 3 | +// REQUIRES: swift_in_compiler |
| 4 | + |
| 5 | +sil_stage canonical |
| 6 | + |
| 7 | +import Builtin |
| 8 | +import Swift |
| 9 | +import SwiftShims |
| 10 | + |
| 11 | +class C {} |
| 12 | + |
| 13 | +// CHECK-LABEL: sil @remove_conversion : |
| 14 | +// CHECK-NOT: address_to_pointer |
| 15 | +// CHECK-NOT: pointer_to_address |
| 16 | +// CHECK: [[L:%.*]] = load %0 |
| 17 | +// CHECK: return [[L]] |
| 18 | +// CHECK: } // end sil function 'remove_conversion' |
| 19 | +sil @remove_conversion : $@convention(thin) (@in Int) -> Int { |
| 20 | +bb0(%0 : $*Int): |
| 21 | + %1 = address_to_pointer %0 : $*Int to $Builtin.RawPointer |
| 22 | + %2 = pointer_to_address %1 : $Builtin.RawPointer to [strict] $*Int |
| 23 | + %3 = load %2 : $*Int |
| 24 | + return %3 : $Int |
| 25 | +} |
| 26 | + |
| 27 | +// CHECK-LABEL: sil @mismatching_type : |
| 28 | +// CHECK: address_to_pointer |
| 29 | +// CHECK: [[A:%.*]] = pointer_to_address |
| 30 | +// CHECK: [[L:%.*]] = load [[A]] |
| 31 | +// CHECK: return [[L]] |
| 32 | +// CHECK: } // end sil function 'mismatching_type' |
| 33 | +sil @mismatching_type : $@convention(thin) (@in Int) -> Bool { |
| 34 | +bb0(%0 : $*Int): |
| 35 | + %1 = address_to_pointer %0 : $*Int to $Builtin.RawPointer |
| 36 | + %2 = pointer_to_address %1 : $Builtin.RawPointer to [strict] $*Bool |
| 37 | + %3 = load %2 : $*Bool |
| 38 | + return %3 : $Bool |
| 39 | +} |
| 40 | + |
| 41 | +// CHECK-LABEL: sil @no_strict : |
| 42 | +// CHECK: address_to_pointer |
| 43 | +// CHECK: [[A:%.*]] = pointer_to_address |
| 44 | +// CHECK: [[L:%.*]] = load [[A]] |
| 45 | +// CHECK: return [[L]] |
| 46 | +// CHECK: } // end sil function 'no_strict' |
| 47 | +sil @no_strict : $@convention(thin) (@in Int) -> Int { |
| 48 | +bb0(%0 : $*Int): |
| 49 | + %1 = address_to_pointer %0 : $*Int to $Builtin.RawPointer |
| 50 | + %2 = pointer_to_address %1 : $Builtin.RawPointer to $*Int |
| 51 | + %3 = load %2 : $*Int |
| 52 | + return %3 : $Int |
| 53 | +} |
| 54 | + |
| 55 | +// CHECK-LABEL: sil [ossa] @borrow_escape : |
| 56 | +// CHECK: address_to_pointer |
| 57 | +// CHECK: [[A:%.*]] = pointer_to_address |
| 58 | +// CHECK: [[L:%.*]] = load [trivial] [[A]] |
| 59 | +// CHECK: return [[L]] |
| 60 | +// CHECK: } // end sil function 'borrow_escape' |
| 61 | +sil [ossa] @borrow_escape : $@convention(thin) (@guaranteed C) -> Int { |
| 62 | +bb0(%0 : @guaranteed $C): |
| 63 | + %1 = begin_borrow %0 : $C |
| 64 | + %2 = ref_tail_addr %1: $C, $Int |
| 65 | + %3 = address_to_pointer %2 : $*Int to $Builtin.RawPointer |
| 66 | + end_borrow %1 : $C |
| 67 | + %5 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Int |
| 68 | + %6 = load [trivial] %5 : $*Int |
| 69 | + return %6 : $Int |
| 70 | +} |
| 71 | + |
| 72 | +sil @createC : $@convention(thin) () -> @owned C |
| 73 | + |
| 74 | +// CHECK-LABEL: sil @non_ossa_local_ownership : |
| 75 | +// CHECK: [[A:%.*]] = ref_tail_addr |
| 76 | +// CHECK-NOT: address_to_pointer |
| 77 | +// CHECK-NOT: pointer_to_address |
| 78 | +// CHECK: [[L:%.*]] = load [[A]] |
| 79 | +// CHECK: return [[L]] |
| 80 | +// CHECK: } // end sil function 'non_ossa_local_ownership' |
| 81 | +sil @non_ossa_local_ownership : $@convention(thin) () -> Int { |
| 82 | +bb0: |
| 83 | + %f = function_ref @createC : $@convention(thin) () -> @owned C |
| 84 | + %0 = apply %f() : $@convention(thin) () -> @owned C |
| 85 | + %2 = ref_tail_addr %0: $C, $Int |
| 86 | + %3 = address_to_pointer %2 : $*Int to $Builtin.RawPointer |
| 87 | + %5 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Int |
| 88 | + %6 = load %5 : $*Int |
| 89 | + strong_release %0 : $C |
| 90 | + return %6 : $Int |
| 91 | +} |
| 92 | + |
0 commit comments