Skip to content

SILGen: Extend scope for evaluation in memberwise initializers to include initializer expressions #31832

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
merged 1 commit into from
May 16, 2020
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
3 changes: 2 additions & 1 deletion lib/SILGen/SILGenConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
selfTy.getFieldType(field, SGF.SGM.M, SGF.getTypeExpansionContext());
RValue value;

FullExpr scope(SGF.Cleanups, field->getParentPatternBinding());

// If it's memberwise initialized, do so now.
if (field->isMemberwiseInitialized(/*preferDeclaredProperties=*/false)) {
assert(elti != eltEnd && "number of args does not match number of fields");
Expand All @@ -276,7 +278,6 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
}

// Cleanup after this initialization.
FullExpr scope(SGF.Cleanups, field->getParentPatternBinding());
SILValue v = maybeEmitPropertyWrapperInitFromValue(SGF, Loc, field, subs,
std::move(value))
.forwardAsSingleStorageValue(SGF, fieldTy, Loc);
Expand Down
18 changes: 18 additions & 0 deletions test/SILGen/memberwise_init_temporary_allocations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %target-swift-emit-silgen -verify %s

protocol P { var x: Int { get } }

extension Int: P { var x: Int { return self } }

// rdar://problem/63187509: Evaluating the variable initializer for `px`
// requires allocating a temporary stack slot for the address only value of
// `Butt.p`. Ensure that this gets cleaned up appropriately (which is asserted
// by the SIL verifier).
struct Butt {
static var p: P = 0

let px = Butt.p.x

let y: Int
}