@@ -69,9 +69,16 @@ void TupleInitialization::copyOrInitValueInto(SILGenFunction &SGF,
69
69
// In the address case, we forward the underlying value and store it
70
70
// into memory and then create a +1 cleanup. since we assume here
71
71
// that we have a +1 value since we are forwarding into memory.
72
+ //
73
+ // In order to ensure that we properly clean up along any failure paths, we
74
+ // need to mark value as being persistently active. We then unforward it once
75
+ // we are done.
72
76
assert (value.isPlusOne (SGF) && " Can not store a +0 value into memory?!" );
73
- value = ManagedValue::forUnmanaged (value.forward (SGF));
74
- return copyOrInitValueIntoHelper (
77
+ CleanupStateRestorationScope valueScope (SGF.Cleanups );
78
+ if (value.hasCleanup ())
79
+ valueScope.pushCleanupState (value.getCleanup (),
80
+ CleanupState::PersistentlyActive);
81
+ copyOrInitValueIntoHelper (
75
82
SGF, loc, value, isInit, SubInitializations,
76
83
[&](ManagedValue aggregate, unsigned i,
77
84
SILType fieldType) -> ManagedValue {
@@ -83,6 +90,8 @@ void TupleInitialization::copyOrInitValueInto(SILGenFunction &SGF,
83
90
84
91
return SGF.emitManagedRValueWithCleanup (elt.getValue ());
85
92
});
93
+ std::move (valueScope).pop ();
94
+ value.forward (SGF);
86
95
}
87
96
88
97
void TupleInitialization::finishUninitialized (SILGenFunction &SGF) {
0 commit comments