Skip to content

Commit 225fd4a

Browse files
committed
[silgen] Create Scope::popPreservingValue(ManagedValue).
What this routine does is: 1. "Imprints" a cleanup cloner with the managed value. 2. Forwards the managed value. 3. Pop the scope. 4. Use the imprinted cleanup cloner to recreate the managed value in the scope outside of the current scope.
1 parent 572dbd4 commit 225fd4a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/SILGen/Scope.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ class LLVM_LIBRARY_VISIBILITY Scope {
5757

5858
bool isValid() const { return depth.isValid(); }
5959

60+
ManagedValue popPreservingValue(ManagedValue mv) {
61+
// If we have a value, make sure that it is an object. The reason why is
62+
// that we want to make sure that we are not forwarding a cleanup for a
63+
// stack location that will be destroyed by this scope.
64+
assert(!mv.getValue() || mv.getType().isObject());
65+
CleanupCloner cloner(cleanups.SGF, mv);
66+
SILValue value = mv.forward(cleanups.SGF);
67+
pop();
68+
return cloner.clone(value);
69+
}
70+
6071
private:
6172
void popImpl() {
6273
cleanups.stack.checkIterator(depth);

0 commit comments

Comments
 (0)