|
| 1 | +// RUN: %target-sil-opt -module-name moveonly_addresschecker -emit-verbose-sil -sil-move-only-checker -enable-sil-verify-all %s | %FileCheck %s |
| 2 | + |
| 3 | +sil_stage raw |
| 4 | + |
| 5 | +public class CopyableKlass {} |
| 6 | + |
| 7 | +@_moveOnly |
| 8 | +public struct NonTrivialStruct { |
| 9 | + var k: CopyableKlass |
| 10 | +} |
| 11 | + |
| 12 | +sil @get_nontrivial_struct : $@convention(thin) () -> @owned NonTrivialStruct |
| 13 | +sil @use_nontrivial_struct : $@convention(thin) (@guaranteed NonTrivialStruct) -> () |
| 14 | +sil @consume_nontrivial_struct : $@convention(thin) (@owned NonTrivialStruct) -> () |
| 15 | +sil @consume_nontrivial_struct_addr : $@convention(thin) (@in NonTrivialStruct) -> () |
| 16 | + |
| 17 | +// CHECK-LABEL: sil [ossa] @non_lifetime_ending_use_test_inst : $@convention(thin) () -> () { |
| 18 | +// CHECK: [[STACK:%.*]] = alloc_stack $NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC:.*]] |
| 19 | +// CHECK: store {{%.*}} to [init] [[STACK]] |
| 20 | +// CHECK: [[BORROW:%.*]] = load_borrow [[STACK]] |
| 21 | +// CHECK: apply {{%.*}}([[BORROW]]) |
| 22 | +// CHECK-NEXT: end_borrow [[BORROW]] |
| 23 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 24 | +// CHECK: } // end sil function 'non_lifetime_ending_use_test_inst' |
| 25 | +sil [ossa] @non_lifetime_ending_use_test_inst : $@convention(thin) () -> () { |
| 26 | + %f = function_ref @get_nontrivial_struct : $@convention(thin) () -> @owned NonTrivialStruct |
| 27 | + %0 = apply %f() : $@convention(thin) () -> @owned NonTrivialStruct |
| 28 | + %1 = alloc_stack $NonTrivialStruct, let, name "v" |
| 29 | + %2 = mark_must_check [consumable_and_assignable] %1 : $*NonTrivialStruct |
| 30 | + store %0 to [init] %2 : $*NonTrivialStruct |
| 31 | + br bb1 |
| 32 | + |
| 33 | +bb1: |
| 34 | + %3 = load [copy] %2 : $*NonTrivialStruct |
| 35 | + %f2 = function_ref @use_nontrivial_struct : $@convention(thin) (@guaranteed NonTrivialStruct) -> () |
| 36 | + apply %f2(%3) : $@convention(thin) (@guaranteed NonTrivialStruct) -> () |
| 37 | + destroy_value %3 : $NonTrivialStruct |
| 38 | + destroy_addr %2 : $*NonTrivialStruct |
| 39 | + dealloc_stack %1 : $*NonTrivialStruct |
| 40 | + %9999 = tuple () |
| 41 | + return %9999 : $() |
| 42 | +} |
| 43 | + |
| 44 | +// CHECK-LABEL: sil [ossa] @non_lifetime_ending_use_test_boundary_edge : $@convention(thin) () -> () { |
| 45 | +// CHECK: [[STACK:%.*]] = alloc_stack $NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC:.*]] |
| 46 | +// CHECK: store {{%.*}} to [init] [[STACK]] |
| 47 | +// CHECK: cond_br undef, bb1, bb2 |
| 48 | + |
| 49 | +// CHECK: bb1: |
| 50 | +// CHECK: [[BORROW:%.*]] = load_borrow [[STACK]] |
| 51 | +// CHECK: apply {{%.*}}([[BORROW]]) |
| 52 | +// CHECK-NEXT: end_borrow [[BORROW]] |
| 53 | +// CHECK-NEXT: destroy_addr [[STACK]] |
| 54 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 55 | +// CHECK: br bb3 |
| 56 | +// |
| 57 | +// CHECK: bb2: |
| 58 | +// CHECK-NEXT: destroy_addr [[STACK]] |
| 59 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 60 | +// CHECK: } // end sil function 'non_lifetime_ending_use_test_boundary_edge' |
| 61 | +sil [ossa] @non_lifetime_ending_use_test_boundary_edge : $@convention(thin) () -> () { |
| 62 | + %f = function_ref @get_nontrivial_struct : $@convention(thin) () -> @owned NonTrivialStruct |
| 63 | + %0 = apply %f() : $@convention(thin) () -> @owned NonTrivialStruct |
| 64 | + %1 = alloc_stack $NonTrivialStruct, let, name "v" |
| 65 | + %2 = mark_must_check [consumable_and_assignable] %1 : $*NonTrivialStruct |
| 66 | + store %0 to [init] %2 : $*NonTrivialStruct |
| 67 | + cond_br undef, bb1, bb2 |
| 68 | + |
| 69 | +bb1: |
| 70 | + %3 = load [copy] %2 : $*NonTrivialStruct |
| 71 | + %f2 = function_ref @use_nontrivial_struct : $@convention(thin) (@guaranteed NonTrivialStruct) -> () |
| 72 | + apply %f2(%3) : $@convention(thin) (@guaranteed NonTrivialStruct) -> () |
| 73 | + destroy_value %3 : $NonTrivialStruct |
| 74 | + br bb3 |
| 75 | + |
| 76 | +bb2: |
| 77 | + br bb3 |
| 78 | + |
| 79 | +bb3: |
| 80 | + destroy_addr %2 : $*NonTrivialStruct |
| 81 | + dealloc_stack %1 : $*NonTrivialStruct |
| 82 | + %9999 = tuple () |
| 83 | + return %9999 : $() |
| 84 | +} |
| 85 | + |
| 86 | +// CHECK-LABEL: sil [ossa] @lifetime_ending_use : $@convention(thin) () -> () { |
| 87 | +// CHECK: [[STACK:%.*]] = alloc_stack $NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC:.*]] |
| 88 | +// CHECK: store {{%.*}} to [init] [[STACK]] |
| 89 | +// CHECK: cond_br undef, bb1, bb2 |
| 90 | + |
| 91 | +// CHECK: bb1: |
| 92 | +// |
| 93 | +// TODO: We should be smarter here and redefine the debug_value to be on the |
| 94 | +// take value and then when that value is destroyed, insert the actual |
| 95 | +// debug_value undef. |
| 96 | +// |
| 97 | +// CHECK: [[TAKE:%.*]] = load [take] [[STACK]] |
| 98 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 99 | +// CHECK-NEXT: // function_ref |
| 100 | +// CHECK-NEXT: function_ref |
| 101 | +// CHECK-NEXT: apply {{%.*}}([[TAKE]]) |
| 102 | +// CHECK: br bb3 |
| 103 | +// |
| 104 | +// CHECK: bb2: |
| 105 | +// CHECK-NEXT: destroy_addr [[STACK]] |
| 106 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 107 | +// CHECK: } // end sil function 'lifetime_ending_use' |
| 108 | +sil [ossa] @lifetime_ending_use : $@convention(thin) () -> () { |
| 109 | + %f = function_ref @get_nontrivial_struct : $@convention(thin) () -> @owned NonTrivialStruct |
| 110 | + %0 = apply %f() : $@convention(thin) () -> @owned NonTrivialStruct |
| 111 | + %1 = alloc_stack $NonTrivialStruct, let, name "v" |
| 112 | + %2 = mark_must_check [consumable_and_assignable] %1 : $*NonTrivialStruct |
| 113 | + store %0 to [init] %2 : $*NonTrivialStruct |
| 114 | + cond_br undef, bb1, bb2 |
| 115 | + |
| 116 | +bb1: |
| 117 | + %3 = load [copy] %2 : $*NonTrivialStruct |
| 118 | + %f2 = function_ref @consume_nontrivial_struct : $@convention(thin) (@owned NonTrivialStruct) -> () |
| 119 | + apply %f2(%3) : $@convention(thin) (@owned NonTrivialStruct) -> () |
| 120 | + br bb3 |
| 121 | + |
| 122 | +bb2: |
| 123 | + br bb3 |
| 124 | + |
| 125 | +bb3: |
| 126 | + destroy_addr %2 : $*NonTrivialStruct |
| 127 | + dealloc_stack %1 : $*NonTrivialStruct |
| 128 | + %9999 = tuple () |
| 129 | + return %9999 : $() |
| 130 | +} |
| 131 | + |
| 132 | +// CHECK-LABEL: sil [ossa] @lifetime_ending_use_addr : $@convention(thin) () -> () { |
| 133 | +// CHECK: [[STACK:%.*]] = alloc_stack $NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC:.*]] |
| 134 | +// CHECK: store {{%.*}} to [init] [[STACK]] |
| 135 | +// CHECK: cond_br undef, bb1, bb2 |
| 136 | + |
| 137 | +// CHECK: bb1: |
| 138 | +// CHECK: apply {{%.*}}([[STACK]]) |
| 139 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 140 | +// CHECK: br bb3 |
| 141 | +// |
| 142 | +// CHECK: bb2: |
| 143 | +// CHECK-NEXT: destroy_addr [[STACK]] |
| 144 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 145 | +// CHECK: } // end sil function 'lifetime_ending_use_addr' |
| 146 | +sil [ossa] @lifetime_ending_use_addr : $@convention(thin) () -> () { |
| 147 | + %f = function_ref @get_nontrivial_struct : $@convention(thin) () -> @owned NonTrivialStruct |
| 148 | + %0 = apply %f() : $@convention(thin) () -> @owned NonTrivialStruct |
| 149 | + %1 = alloc_stack $NonTrivialStruct, let, name "v" |
| 150 | + %2 = mark_must_check [consumable_and_assignable] %1 : $*NonTrivialStruct |
| 151 | + store %0 to [init] %2 : $*NonTrivialStruct |
| 152 | + cond_br undef, bb1, bb2 |
| 153 | + |
| 154 | +bb1: |
| 155 | + %f2 = function_ref @consume_nontrivial_struct_addr : $@convention(thin) (@in NonTrivialStruct) -> () |
| 156 | + apply %f2(%2) : $@convention(thin) (@in NonTrivialStruct) -> () |
| 157 | + br bb3 |
| 158 | + |
| 159 | +bb2: |
| 160 | + br bb3 |
| 161 | + |
| 162 | +bb3: |
| 163 | + destroy_addr %2 : $*NonTrivialStruct |
| 164 | + dealloc_stack %1 : $*NonTrivialStruct |
| 165 | + %9999 = tuple () |
| 166 | + return %9999 : $() |
| 167 | +} |
| 168 | + |
| 169 | +// CHECK-LABEL: sil [ossa] @dead_def_test_inst : $@convention(thin) () -> () { |
| 170 | +// CHECK: [[STACK:%.*]] = alloc_stack $NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC:.*]] |
| 171 | +// CHECK: store {{%.*}} to [init] [[STACK]] |
| 172 | +// CHECK: cond_br undef, bb1, bb3 |
| 173 | +// |
| 174 | +// CHECK: bb1: |
| 175 | +// CHECK: apply {{%.*}}([[STACK]]) |
| 176 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 177 | +// CHECK-NEXT: br bb2 |
| 178 | +// |
| 179 | +// CHECK: bb2: |
| 180 | +// CHECK: [[NEW_VAL:%.*]] = apply {{%.*}}() : |
| 181 | +// CHECK-NEXT: store [[NEW_VAL]] to [init] [[STACK]] |
| 182 | +// CHECK-NEXT: destroy_addr [[STACK]] |
| 183 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 184 | +// CHECK-NEXT: br bb4 |
| 185 | +// |
| 186 | +// CHECK: bb3: |
| 187 | +// CHECK-NEXT: destroy_addr [[STACK]] |
| 188 | +// CHECK-NEXT: debug_value undef : $*NonTrivialStruct, let, name "v" // {{.*}}; line:[[DEBUG_LOC]] |
| 189 | +// CHECK: br bb4 |
| 190 | +// CHECK: } // end sil function 'dead_def_test_inst' |
| 191 | +sil [ossa] @dead_def_test_inst : $@convention(thin) () -> () { |
| 192 | + %f = function_ref @get_nontrivial_struct : $@convention(thin) () -> @owned NonTrivialStruct |
| 193 | + %0 = apply %f() : $@convention(thin) () -> @owned NonTrivialStruct |
| 194 | + %1 = alloc_stack $NonTrivialStruct, let, name "v" |
| 195 | + %2 = mark_must_check [consumable_and_assignable] %1 : $*NonTrivialStruct |
| 196 | + store %0 to [init] %2 : $*NonTrivialStruct |
| 197 | + cond_br undef, bb1, bb2 |
| 198 | + |
| 199 | +bb1: |
| 200 | + // TODO: Fix bug where we do not propagate this use to bb0 and thus think that |
| 201 | + // store %0 is a dead def. |
| 202 | + %f2 = function_ref @consume_nontrivial_struct_addr : $@convention(thin) (@in NonTrivialStruct) -> () |
| 203 | + apply %f2(%2) : $@convention(thin) (@in NonTrivialStruct) -> () |
| 204 | + br bb1a |
| 205 | + |
| 206 | +bb1a: |
| 207 | + %0a = apply %f() : $@convention(thin) () -> @owned NonTrivialStruct |
| 208 | + store %0a to [init] %2 : $*NonTrivialStruct |
| 209 | + br bb3 |
| 210 | + |
| 211 | +bb2: |
| 212 | + br bb3 |
| 213 | + |
| 214 | +bb3: |
| 215 | + destroy_addr %2 : $*NonTrivialStruct |
| 216 | + dealloc_stack %1 : $*NonTrivialStruct |
| 217 | + %9999 = tuple () |
| 218 | + return %9999 : $() |
| 219 | +} |
0 commit comments