Skip to content

Commit dc59f00

Browse files
committed
[silgen] Add cleanups for trivial values converted to non-trivial via copyable_to_moveonlywrapped.
The reason why this is necessary is that the trivial input value doesn't have a cleanup associated with it, but the result of the instruction is owned. So otherwise we will not have a cleanup for the result, resulting in an OSSA error.
1 parent 98dbfae commit dc59f00

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/SILGen/SILGenBuilder.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,10 @@ SILGenBuilder::createCopyableToMoveOnlyWrapperValue(SILLocation loc,
927927
ManagedValue value) {
928928
assert(value.isPlusOne(SGF) && "Argument must be at +1!");
929929
CleanupCloner cloner(*this, value);
930-
auto *mdi = SILBuilder::createCopyableToMoveOnlyWrapperValue(
931-
loc, value.forward(getSILGenFunction()));
930+
SILValue v = value.forward(getSILGenFunction());
931+
auto *mdi = SILBuilder::createCopyableToMoveOnlyWrapperValue(loc, v);
932+
if (v->getType().isTrivial(getFunction()))
933+
return SGF.emitManagedRValueWithCleanup(mdi);
932934
return cloner.clone(mdi);
933935
}
934936

0 commit comments

Comments
 (0)