|
| 1 | +// RUN: %target-sil-opt %s | %FileCheck %s |
| 2 | + |
| 3 | +class Klass {} |
| 4 | + |
| 5 | +public struct Wrapper { |
| 6 | + @_hasStorage var _k: Klass { get set } |
| 7 | + var k: Klass |
| 8 | +} |
| 9 | + |
| 10 | +public struct GenWrapper<T> { |
| 11 | + @_hasStorage var _prop: T { get set } |
| 12 | + public var prop: T |
| 13 | +} |
| 14 | + |
| 15 | +// CHECK-LABEL: sil [ossa] @borrow_loadable_prop : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass { |
| 16 | +sil [ossa] @borrow_loadable_prop : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass { |
| 17 | +bb0(%0 : @guaranteed $Wrapper): |
| 18 | + %2 = struct_extract %0, #Wrapper._k |
| 19 | + return %2 |
| 20 | +} |
| 21 | + |
| 22 | +// CHECK-LABEL: sil [ossa] @borrow_addressonly_prop : $@convention(method) <T> (@in_guaranteed GenWrapper<T>) -> @guaranteed_addr T { |
| 23 | +sil [ossa] @borrow_addressonly_prop : $@convention(method) <T> (@in_guaranteed GenWrapper<T>) -> @guaranteed_addr T { |
| 24 | +bb0(%0 : $*GenWrapper<T>): |
| 25 | + %2 = struct_element_addr %0, #GenWrapper._prop |
| 26 | + return %2 |
| 27 | +} |
| 28 | + |
| 29 | +sil @get_wrapper : $@convention(thin) () -> @owned Klass |
| 30 | +sil @use_klass : $@convention(thin) (@guaranteed Klass) -> () |
| 31 | +sil @use_T : $@convention(thin) <T> (@in_guaranteed T) -> () |
| 32 | + |
| 33 | +sil [ossa] @test1 : $@convention(thin) (@owned Wrapper) -> () { |
| 34 | +bb0(%0 : @owned $Wrapper): |
| 35 | + %1 = begin_borrow %0 |
| 36 | + %2 = function_ref @borrow_loadable_prop : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass |
| 37 | + %3 = apply %2(%1) : $@convention(method) (@guaranteed Wrapper) -> @guaranteed Klass |
| 38 | + %4 = copy_value %3 |
| 39 | + %5 = function_ref @use_klass : $@convention(thin) (@guaranteed Klass) -> () |
| 40 | + %6 = apply %5(%4) : $@convention(thin) (@guaranteed Klass) -> () |
| 41 | + destroy_value %4 |
| 42 | + end_borrow %1 |
| 43 | + destroy_value %0 |
| 44 | + %10 = tuple () |
| 45 | + return %10 |
| 46 | +} |
| 47 | + |
| 48 | +sil [ossa] @test2 : $@convention(thin) <T> (@in GenWrapper<T>) -> () { |
| 49 | +bb0(%0 : $*GenWrapper<T>): |
| 50 | + %1 = function_ref @borrow_addressonly_prop : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_addr τ_0_0 |
| 51 | + %2 = apply %1<T>(%0) : $@convention(method) <τ_0_0> (@in_guaranteed GenWrapper<τ_0_0>) -> @guaranteed_addr τ_0_0 |
| 52 | + %3 = function_ref @use_T : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () |
| 53 | + %4 = apply %3<T>(%2) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () |
| 54 | + destroy_addr %0 |
| 55 | + %6 = tuple () |
| 56 | + return %6 |
| 57 | +} |
| 58 | + |
0 commit comments