Skip to content

Commit 3c74824

Browse files
committed
[MoveOnlyAddressChecker] Complete block args.
Now that the underlying issue (PrunedLiveness' merging of summaries for branch instructions) has been fixed, reinstate lifetime completion and add a test to verify that it behaves correctly. This reverts commit c552b90 ("Temporarily turn off completing lifetimes of block arguments"). rdar://130427564
1 parent d0097fe commit 3c74824

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ void MoveOnlyChecker::completeObjectLifetimes(
169169
}
170170
}
171171
}
172+
for (SILArgument *arg : block->getArguments()) {
173+
assert(!arg->isReborrow() && "reborrows not legal at this SIL stage");
174+
if (!transitiveValues.isVisited(arg))
175+
continue;
176+
if (completion.completeOSSALifetime(arg) ==
177+
LifetimeCompletion::WasCompleted) {
178+
madeChange = true;
179+
}
180+
}
172181
}
173182
}
174183

test/SILOptimizer/moveonly_addresschecker_unmaximized.sil

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ struct M4: ~Copyable {
2121
let s4: M
2222
}
2323

24+
class C {}
25+
2426
sil @get_M4 : $@convention(thin) () -> @owned M4
2527
sil @end_2 : $@convention(thin) (@owned M, @owned M) -> ()
2628
sil @see_addr : $@convention(thin) (@in_guaranteed M) -> ()
2729
sil @see_addr_2 : $@convention(thin) (@in_guaranteed M, @in_guaranteed M) -> ()
2830
sil @replace_2 : $@convention(thin) (@inout M, @inout M) -> ()
2931
sil @get_out_2 : $@convention(thin) () -> (@out M, @out M)
3032
sil @take_addr_2 : $@convention(thin) (@in M, @in M) -> ()
33+
sil @getC : $@convention(thin) () -> (@owned C)
3134

3235
/// Two non-contiguous fields (#M4.s2, #M4.s4) are borrowed by @see_addr_2.
3336
/// Two non-contiguous fields (#M4.s1, #M$.s3) are consumed by @end_2.
@@ -253,3 +256,37 @@ bb0(%0 : @guaranteed $M):
253256
return %retval : $()
254257
}
255258

259+
// CHECK-LABEL: sil [ossa] @rdar130427564 : {{.*}} {
260+
// Verify that no instructions were inserted after backedge2's terminator. (In
261+
// fact, if they were, the test would crash.)
262+
// CHECK: bb2([[C0:%[^,]+]] : @owned $C, [[B0:%[^,]+]] : @reborrow @guaranteed $C):
263+
// CHECK-NEXT: end_borrow [[B0]]
264+
// CHECK-NEXT: destroy_value [[C0]]
265+
// CHECK-NEXT: br
266+
// CHECK-LABEL: } // end sil function 'rdar130427564'
267+
sil [ossa] @rdar130427564 : $@convention(thin) (@in_guaranteed M) -> () {
268+
entry(%ignore_me : $*M):
269+
%ignore_me_2 = mark_unresolved_non_copyable_value [no_consume_or_assign] %ignore_me : $*M
270+
br fn
271+
fn:
272+
%getC = function_ref @getC : $@convention(thin) () -> (@owned C)
273+
%c = apply %getC() : $@convention(thin) () -> (@owned C)
274+
%b = begin_borrow %c : $C
275+
br header(%c : $C, %b : $C)
276+
header(%c0 : @owned $C, %b0 : @reborrow @guaranteed $C):
277+
end_borrow %b0 : $C
278+
destroy_value %c0 : $C
279+
br body
280+
body:
281+
br latch
282+
latch:
283+
cond_br undef, backedge, ecit
284+
backedge:
285+
%c1 = apply %getC() : $@convention(thin) () -> (@owned C)
286+
%b1 = begin_borrow %c1 : $C
287+
br backedge2(%c1 : $C, %b1 : $C)
288+
backedge2(%c2 : @owned $C, %b2 : @reborrow @guaranteed $C):
289+
br header(%c2 : $C, %b2 : $C)
290+
ecit:
291+
unreachable
292+
}

0 commit comments

Comments
 (0)