Skip to content

Revert "[silgen] Ensure that the outer cleanup is emitted along failure paths when initializing sub-tuple patterns" #39545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,9 @@ void TupleInitialization::copyOrInitValueInto(SILGenFunction &SGF,
// In the address case, we forward the underlying value and store it
// into memory and then create a +1 cleanup. since we assume here
// that we have a +1 value since we are forwarding into memory.
//
// In order to ensure that we properly clean up along any failure paths, we
// need to mark value as being persistently active. We then unforward it once
// we are done.
assert(value.isPlusOne(SGF) && "Can not store a +0 value into memory?!");
CleanupStateRestorationScope valueScope(SGF.Cleanups);
if (value.hasCleanup())
valueScope.pushCleanupState(value.getCleanup(),
CleanupState::PersistentlyActive);
copyOrInitValueIntoHelper(
value = ManagedValue::forUnmanaged(value.forward(SGF));
return copyOrInitValueIntoHelper(
SGF, loc, value, isInit, SubInitializations,
[&](ManagedValue aggregate, unsigned i,
SILType fieldType) -> ManagedValue {
Expand All @@ -90,8 +83,6 @@ void TupleInitialization::copyOrInitValueInto(SILGenFunction &SGF,

return SGF.emitManagedRValueWithCleanup(elt.getValue());
});
std::move(valueScope).pop();
value.forward(SGF);
}

void TupleInitialization::finishUninitialized(SILGenFunction &SGF) {
Expand Down
20 changes: 0 additions & 20 deletions test/SILGen/enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,3 @@ func sr7799_1(bar: SR7799??) {
default: print("default")
}
}

// Make sure that we handle enum, tuple initialization composed
// correctly. Previously, we leaked down a failure path due to us misusing
// scopes.
enum rdar81817725 {
case localAddress
case setOption(Int, Any)

static func takeAny(_:Any) -> Bool { return true }

static func testSwitchCleanup(syscall: rdar81817725, expectedLevel: Int,
valueMatcher: (Any) -> Bool)
throws -> Bool {
if case .setOption(expectedLevel, let value) = syscall {
return rdar81817725.takeAny(value)
} else {
return false
}
}
}