|
| 1 | +// RUN: %target-sil-opt -test-runner %s \ |
| 2 | +// RUN: -enable-experimental-feature LifetimeDependence \ |
| 3 | +// RUN: -o /dev/null 2>&1 | %FileCheck %s |
| 4 | + |
| 5 | +// REQUIRES: swift_in_compiler |
| 6 | +// REQUIRES: swift_feature_LifetimeDependence |
| 7 | + |
| 8 | +sil_stage raw |
| 9 | + |
| 10 | +import Builtin |
| 11 | +import Swift |
| 12 | +import SwiftShims |
| 13 | + |
| 14 | +struct NE: ~Escapable {} |
| 15 | + |
| 16 | +sil @makeDepNE : $@convention(thin) (@inout NE) -> @lifetime(borrow address_for_deps 0) @out NE |
| 17 | + |
| 18 | +// CHECK-LABEL: testNEInitNoEscape: local_variable_reachable_uses with: %1, @instruction |
| 19 | +// CHECK: ### Access map: |
| 20 | +// CHECK-NEXT: Access map for: %{{.*}} = alloc_box ${ var NE }, var, name "self" |
| 21 | +// CHECK-NEXT: assign: true, store destroy_value %{{.*}} : ${ var NE } |
| 22 | +// CHECK-NEXT: assign: false, escape %{{.*}} = address_to_pointer %{{.*}} : $*NE to $Builtin.RawPointer |
| 23 | +// CHECK-NEXT: assign: true, beginAccess %{{.*}} = begin_access [modify] [unknown] %{{.*}} : $*NE |
| 24 | +// CHECK-NEXT: assign: false, load %{{.*}} = load [copy] %{{.*}} : $*NE |
| 25 | +// CHECK-NEXT: assign: true, beginAccess %{{.*}} = begin_access [modify] [unknown] %{{.*}} : $*NE |
| 26 | +// CHECK-NEXT: ### Modify: %{{.*}} = begin_access [modify] [unknown] %4 : $*NE |
| 27 | +// CHECK-NEXT: ### Reachable access: |
| 28 | +// CHECK-NEXT: load %{{.*}} = load [copy] %{{.*}} : $*NE |
| 29 | +// CHECK-NEXT: testNEInitNoEscape: local_variable_reachable_uses with: %1, @instruction |
| 30 | + |
| 31 | +// CHECK-LABEL: testNEInitNoEscape: local_variable_reaching_assignments with: %1, @instruction |
| 32 | +// CHECK: ### Instruction: end_access %{{.*}} : $*NE |
| 33 | +// CHECK-NEXT: ### Reachable assignments: |
| 34 | +// CHECK-NEXT: beginAccess %21 = begin_access [modify] [unknown] %4 : $*NE |
| 35 | +// CHECK-NEXT: testNEInitNoEscape: local_variable_reaching_assignments with: %1, @instruction |
| 36 | +sil [ossa] @testNEInitNoEscape : $@convention(thin) (@inout NE) -> @lifetime(borrow 0) @owned NE { |
| 37 | +bb0(%0 : $*NE): |
| 38 | + %1 = alloc_box ${ var NE }, var, name "self" |
| 39 | + %2 = mark_uninitialized [rootself] %1 |
| 40 | + %3 = begin_borrow [lexical] [var_decl] %2 |
| 41 | + %4 = project_box %3, 0 |
| 42 | + cond_br undef, bb1, bb2 |
| 43 | + |
| 44 | +bb1: |
| 45 | + br bb3 |
| 46 | + |
| 47 | +bb2: |
| 48 | + br bb3 |
| 49 | + |
| 50 | +bb3: |
| 51 | + %8 = alloc_stack $NE |
| 52 | + |
| 53 | + %9 = begin_access [modify] [unknown] %0 |
| 54 | + |
| 55 | + %10 = function_ref @makeDepNE : $@convention(thin) (@inout NE) -> @lifetime(borrow address_for_deps 0) @out NE |
| 56 | + %11 = apply %10(%8, %9) : $@convention(thin) (@inout NE) -> @lifetime(borrow address_for_deps 0) @out NE |
| 57 | + |
| 58 | + mark_dependence_addr [unresolved] %8 on %9 |
| 59 | + end_access %9 |
| 60 | + |
| 61 | + %14 = load [take] %8 |
| 62 | + |
| 63 | + specify_test "local_variable_reachable_uses %1 @instruction" |
| 64 | + %15 = begin_access [modify] [unknown] %4 |
| 65 | + assign %14 to %15 |
| 66 | + end_access %15 |
| 67 | + dealloc_stack %8 |
| 68 | + %19 = load [copy] %4 |
| 69 | + |
| 70 | + %21 = load [take] %8 |
| 71 | + %22 = begin_access [modify] [unknown] %4 |
| 72 | + assign %21 to %22 |
| 73 | + specify_test "local_variable_reaching_assignments %1 @instruction" |
| 74 | + end_access %22 |
| 75 | + %escape = address_to_pointer %4 : $*NE to $Builtin.RawPointer |
| 76 | + end_borrow %3 |
| 77 | + destroy_value %2 |
| 78 | + return %19 |
| 79 | +} |
| 80 | + |
| 81 | +// CHECK-LABEL: testNEInitEscape: local_variable_reaching_assignments with: %1, @instruction |
| 82 | +// CHECK: ### Instruction: %{{.*}} = load [take] %{{.*}} : $*NE |
| 83 | +// CHECK-NEXT: !!! Reaching escape |
| 84 | +// CHECK-NEXT: testNEInitEscape: local_variable_reaching_assignments with: %1, @instruction |
| 85 | + |
| 86 | +// CHECK-LABEL: testNEInitEscape: local_variable_reachable_uses with: %1, @instruction |
| 87 | +// CHECK: ### Access map: |
| 88 | +// CHECK-NEXT: Access map for: %{{.*}} = alloc_box ${ var NE }, var, name "self" |
| 89 | +// CHECK-NEXT: assign: true, store destroy_value %{{.*}} : ${ var NE } |
| 90 | +// CHECK-NEXT: assign: false, load %{{.*}} = load [copy] %{{.*}} : $*NE |
| 91 | +// CHECK-NEXT: assign: true, beginAccess %{{.*}} = begin_access [modify] [unknown] %{{.*}} : $*NE |
| 92 | +// CHECK-NEXT: assign: false, escape %6 = address_to_pointer %4 : $*NE to $Builtin.RawPointer |
| 93 | +// CHECK-NEXT: ### Modify: %{{.*}} = begin_access [modify] [unknown] %4 : $*NE |
| 94 | +// CHECK-NEXT: !!! Reachable escape |
| 95 | +// CHECK-NEXT: testNEInitEscape: local_variable_reachable_uses with: %1, @instruction |
| 96 | +sil [ossa] @testNEInitEscape : $@convention(thin) (@inout NE) -> @lifetime(borrow 0) @owned NE { |
| 97 | +bb0(%0 : $*NE): |
| 98 | + %1 = alloc_box ${ var NE }, var, name "self" |
| 99 | + %2 = mark_uninitialized [rootself] %1 |
| 100 | + %3 = begin_borrow [lexical] [var_decl] %2 |
| 101 | + %4 = project_box %3, 0 |
| 102 | + cond_br undef, bb1, bb2 |
| 103 | + |
| 104 | +bb1: |
| 105 | + %escape = address_to_pointer %4 : $*NE to $Builtin.RawPointer |
| 106 | + br bb3 |
| 107 | + |
| 108 | +bb2: |
| 109 | + br bb3 |
| 110 | + |
| 111 | +bb3: |
| 112 | + %8 = alloc_stack $NE |
| 113 | + |
| 114 | + %9 = begin_access [modify] [unknown] %0 |
| 115 | + |
| 116 | + %10 = function_ref @makeDepNE : $@convention(thin) (@inout NE) -> @lifetime(borrow address_for_deps 0) @out NE |
| 117 | + %11 = apply %10(%8, %9) : $@convention(thin) (@inout NE) -> @lifetime(borrow address_for_deps 0) @out NE |
| 118 | + |
| 119 | + mark_dependence_addr [unresolved] %8 on %9 |
| 120 | + end_access %9 |
| 121 | + |
| 122 | + specify_test "local_variable_reaching_assignments %1 @instruction" |
| 123 | + %14 = load [take] %8 |
| 124 | + |
| 125 | + specify_test "local_variable_reachable_uses %1 @instruction" |
| 126 | + %15 = begin_access [modify] [unknown] %4 |
| 127 | + assign %14 to %15 |
| 128 | + end_access %15 |
| 129 | + dealloc_stack %8 |
| 130 | + %19 = load [copy] %4 |
| 131 | + end_borrow %3 |
| 132 | + destroy_value %2 |
| 133 | + return %19 |
| 134 | +} |
0 commit comments