Skip to content

Commit ffbfcfa

Browse files
committed
SILGen: Extend scope for evaluation in memberwise initializers to include initializer expressions.
Catch any cleanups that get emitted while evaluating the initializer expression for a property. Fixes rdar://problem/63187509.
1 parent db8c500 commit ffbfcfa

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
252252
selfTy.getFieldType(field, SGF.SGM.M, SGF.getTypeExpansionContext());
253253
RValue value;
254254

255+
FullExpr scope(SGF.Cleanups, field->getParentPatternBinding());
256+
255257
// If it's memberwise initialized, do so now.
256258
if (field->isMemberwiseInitialized(/*preferDeclaredProperties=*/false)) {
257259
assert(elti != eltEnd && "number of args does not match number of fields");
@@ -276,7 +278,6 @@ static void emitImplicitValueConstructor(SILGenFunction &SGF,
276278
}
277279

278280
// Cleanup after this initialization.
279-
FullExpr scope(SGF.Cleanups, field->getParentPatternBinding());
280281
SILValue v = maybeEmitPropertyWrapperInitFromValue(SGF, Loc, field, subs,
281282
std::move(value))
282283
.forwardAsSingleStorageValue(SGF, fieldTy, Loc);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-emit-silgen -verify %s
2+
3+
protocol P { var x: Int { get } }
4+
5+
extension Int: P { var x: Int { return self } }
6+
7+
// rdar://problem/63187509: Evaluating the variable initializer for `px`
8+
// requires allocating a temporary stack slot for the address only value of
9+
// `Butt.p`. Ensure that this gets cleaned up appropriately (which is asserted
10+
// by the SIL verifier).
11+
struct Butt {
12+
static var p: P = 0
13+
14+
let px = Butt.p.x
15+
16+
let y: Int
17+
}
18+

0 commit comments

Comments
 (0)