Skip to content

Commit 8059c99

Browse files
authored
Merge pull request #64161 from gottesmm/pr-e9199690b31f6695cd42471f85f41b6493f722c1
[move-only] Fix crash due to an earlier change I made to move end_borrow out of addressUseChecker and into the liveness checker.
2 parents 3d2e0c9 + f5acc07 commit 8059c99

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,28 @@ bool GlobalLivenessChecker::testInstVectorLiveness(
16461646
break;
16471647
}
16481648

1649+
// Check if we have a non-consuming liveness use.
1650+
//
1651+
// DISCUSSION: In certain cases, we only represent uses like end_borrow
1652+
// in liveness and not in address use state. This ensures that we
1653+
// properly emit a diagnostic in these cases.
1654+
//
1655+
// TODO: We should include liveness uses of the load_borrow itself in an
1656+
// array and emit an error on those instead since it would be a better
1657+
// error than using end_borrow here.
1658+
{
1659+
auto pair = liveness.isInterestingUser(&*ii);
1660+
if (pair.first == FieldSensitivePrunedLiveness::NonLifetimeEndingUse &&
1661+
pair.second->contains(errorSpan)) {
1662+
diagnosticEmitter.emitAddressDiagnostic(
1663+
addressUseState.address, &*ii, errorUser, false /*is consuming*/,
1664+
addressUseState.isInOutTermUser(&*ii));
1665+
foundSingleBlockError = true;
1666+
emittedDiagnostic = true;
1667+
break;
1668+
}
1669+
}
1670+
16491671
if (addressUseState.isInitUse(&*ii, errorSpan)) {
16501672
llvm::errs() << "Should not have errored if we see an init?! Init: "
16511673
<< *ii;

test/SILOptimizer/moveonly_addresschecker_diagnostics.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,21 @@ bb0(%0 : @owned $NonTrivialStruct):
261261
%27 = tuple ()
262262
return %27 : $()
263263
}
264+
265+
sil @borrow_and_consume : $@convention(thin) (@guaranteed NonTrivialStruct, @owned NonTrivialStruct) -> ()
266+
267+
sil hidden [ossa] @$s4test1d1xyAA1NonTrivialStructVn_tF : $@convention(thin) (@owned NonTrivialStruct) -> () {
268+
bb0(%0 : @owned $NonTrivialStruct):
269+
%1 = alloc_stack $NonTrivialStruct, let, name "x", argno 1
270+
%2 = mark_must_check [consumable_and_assignable] %1 : $*NonTrivialStruct // expected-error {{'x' used after consume}}
271+
store %0 to [init] %2 : $*NonTrivialStruct
272+
%4 = load_borrow %2 : $*NonTrivialStruct
273+
%5 = load [copy] %2 : $*NonTrivialStruct // expected-note {{consuming use here}}
274+
%6 = function_ref @borrow_and_consume : $@convention(thin) (@guaranteed NonTrivialStruct, @owned NonTrivialStruct) -> ()
275+
%7 = apply %6(%4, %5) : $@convention(thin) (@guaranteed NonTrivialStruct, @owned NonTrivialStruct) -> ()
276+
end_borrow %4 : $NonTrivialStruct // expected-note {{non-consuming use here}}
277+
destroy_addr %2 : $*NonTrivialStruct
278+
dealloc_stack %1 : $*NonTrivialStruct
279+
%11 = tuple ()
280+
return %11 : $()
281+
}

test/SILOptimizer/moveonly_addresschecker_diagnostics.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,3 +2455,15 @@ func inoutCaptureTest() -> (() -> ()) {
24552455

24562456
return f
24572457
}
2458+
2459+
////////////////
2460+
// Misc Tests //
2461+
////////////////
2462+
2463+
func borrowAndConsumeAtSameTime(_: __shared NonTrivialStruct, consume _: __owned NonTrivialStruct) {}
2464+
2465+
func borrowAndConsumeAtSameTimeTest(x: __owned NonTrivialStruct) { // expected-error {{'x' used after consume}}
2466+
borrowAndConsumeAtSameTime(x, consume: x)
2467+
// expected-note @-1 {{consuming use here}}
2468+
// expected-note @-2 {{non-consuming use here}}
2469+
}

0 commit comments

Comments
 (0)