Skip to content

Commit c5e81dd

Browse files
Merge pull request #74835 from nate-chandler/rdar130427564_2
[MoveOnlyAddressChecker] Complete block args.
2 parents 7feb592 + 451a814 commit c5e81dd

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ void MoveOnlyChecker::completeObjectLifetimes(
171171
}
172172
}
173173
}
174+
for (SILArgument *arg : block->getArguments()) {
175+
assert(!arg->isReborrow() && "reborrows not legal at this SIL stage");
176+
if (!transitiveValues.isVisited(arg))
177+
continue;
178+
if (completion.completeOSSALifetime(
179+
arg, OSSALifetimeCompletion::Boundary::Availability) ==
180+
LifetimeCompletion::WasCompleted) {
181+
madeChange = true;
182+
}
183+
}
174184
}
175185
}
176186

test/SILOptimizer/moveonly_addresschecker_unmaximized.sil

Lines changed: 40 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,40 @@ 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: [[B0F:%[^,]+]] = borrowed [[B0]] : $C from ([[C0]] : $C)
264+
// CHECK-NEXT: end_borrow [[B0F]]
265+
// CHECK-NEXT: destroy_value [[C0]]
266+
// CHECK-NEXT: br
267+
// CHECK-LABEL: } // end sil function 'rdar130427564'
268+
sil [ossa] @rdar130427564 : $@convention(thin) (@in_guaranteed M) -> () {
269+
entry(%ignore_me : $*M):
270+
%ignore_me_2 = mark_unresolved_non_copyable_value [no_consume_or_assign] %ignore_me : $*M
271+
br fn
272+
fn:
273+
%getC = function_ref @getC : $@convention(thin) () -> (@owned C)
274+
%c = apply %getC() : $@convention(thin) () -> (@owned C)
275+
%b = begin_borrow %c : $C
276+
br header(%c : $C, %b : $C)
277+
header(%c0 : @owned $C, %b0 : @reborrow @guaranteed $C):
278+
%b0f = borrowed %b0 : $C from (%c0 : $C)
279+
end_borrow %b0f : $C
280+
destroy_value %c0 : $C
281+
br body
282+
body:
283+
br latch
284+
latch:
285+
cond_br undef, backedge, ecit
286+
backedge:
287+
%c1 = apply %getC() : $@convention(thin) () -> (@owned C)
288+
%b1 = begin_borrow %c1 : $C
289+
br backedge2(%c1 : $C, %b1 : $C)
290+
backedge2(%c2 : @owned $C, %b2 : @reborrow @guaranteed $C):
291+
%b2f = borrowed %b2 : $C from (%c2 : $C)
292+
br header(%c2 : $C, %b2f : $C)
293+
ecit:
294+
unreachable
295+
}

0 commit comments

Comments
 (0)