Skip to content

Commit a263263

Browse files
committed
DefiniteInitialization: correctly handle implicit closures in initializers of derived classes.
Support for implicit closures was already added in c452e4c: init() { bool_member1 = false bool_member2 = false || bool_member1 // implicit closure } But this didn't work for initializers of derived classes. rdar://66420045
1 parent c3e9676 commit a263263

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,11 @@ void ElementUseCollector::collectClassSelfUses(SILValue ClassPointer) {
10651065

10661066
// If we are looking at the init method for a root class, just walk the
10671067
// MUI use-def chain directly to find our uses.
1068-
if (TheMemory.isRootSelf()) {
1068+
if (TheMemory.isRootSelf() ||
1069+
1070+
// Also, just visit all users if ClassPointer is a closure argument,
1071+
// i.e. collectClassSelfUses is called from addClosureElementUses.
1072+
isa<SILFunctionArgument>(ClassPointer)) {
10691073
collectClassSelfUses(ClassPointer, TheMemory.getType(), EltNumbering);
10701074
return;
10711075
}

test/SILOptimizer/definite_init_closures.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,15 @@ struct Generic<T : P> {
6969
}
7070
}
7171

72+
class Base { }
73+
74+
class Derived : Base {
75+
var x: Bool
76+
var y: Bool
77+
78+
init(_: Int) {
79+
x = false
80+
y = true || x
81+
}
82+
}
7283

0 commit comments

Comments
 (0)