Skip to content

Commit a59de54

Browse files
authored
Merge pull request #71964 from jckarter/move-value-cleanup
SILGen: Produce move_values with a fresh cleanup.
2 parents c64b062 + 69513f3 commit a59de54

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)