Skip to content

Commit 69513f3

Browse files
committed
SILGen: Produce move_values with a fresh cleanup.
If the value being moved was a trivial value of a nontrivial type (like nil for Optional<T>) then the lifetime checker would complain that there was no `destroy_value` ending the consumed value's lifetime. Partial fix for #71608.
1 parent c6f981b commit 69513f3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/SILGen/SILGenBuilder.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,13 @@ ManagedValue SILGenBuilder::createFormalAccessBeginBorrow(SILLocation loc,
10611061
ManagedValue SILGenBuilder::createMoveValue(SILLocation loc, ManagedValue value,
10621062
bool isLexical) {
10631063
assert(value.isPlusOne(SGF) && "Must be +1 to be moved!");
1064-
CleanupCloner cloner(*this, value);
10651064
auto *mdi =
10661065
createMoveValue(loc, value.forward(getSILGenFunction()), isLexical);
1067-
return cloner.clone(mdi);
1066+
// We always want a generic destroy_value cleanup on the moved value, even
1067+
// if the original had a more specialized cleanup (because it was a trivial
1068+
// case of an enum or something like that), so that the move checker does
1069+
// the right thing with the moved value.
1070+
return SGF.emitManagedRValueWithCleanup(mdi);
10681071
}
10691072

10701073
ManagedValue
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-emit-silgen -verify %s
2+
3+
// https://github.com/apple/swift/issues/71608
4+
func f(x:[Int]?)
5+
{
6+
}
7+
func g()
8+
{
9+
let x:[Int]? = nil
10+
f(x: consume x)
11+
}

0 commit comments

Comments
 (0)