Skip to content

Commit 3d5a16a

Browse files
committed
DI: Use new 'self initialized' analysis in LifetimeChecker::isInitializedAtUse()
1 parent 9d80f60 commit 3d5a16a

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,15 +2720,6 @@ bool LifetimeChecker::isInitializedAtUse(const DIMemoryUse &Use,
27202720
if (FailedSelfUse) *FailedSelfUse = false;
27212721
if (SuperInitDone) *SuperInitDone = true;
27222722

2723-
if (TheMemory.isAnyInitSelf()) {
2724-
// If the self.init() or super.init() call threw an error and
2725-
// we caught it, self is no longer available.
2726-
if (getSelfConsumedAtInst(Use.Inst) != DIKind::No) {
2727-
if (FailedSelfUse) *FailedSelfUse = true;
2728-
return false;
2729-
}
2730-
}
2731-
27322723
// Determine the liveness states of the elements that we care about.
27332724
AvailabilitySet Liveness =
27342725
getLivenessAtInst(Use.Inst, Use.FirstElement, Use.NumElements);
@@ -2743,9 +2734,23 @@ bool LifetimeChecker::isInitializedAtUse(const DIMemoryUse &Use,
27432734

27442735
// Check all the results.
27452736
for (unsigned i = Use.FirstElement, e = i+Use.NumElements;
2746-
i != e; ++i)
2737+
i != e; ++i) {
27472738
if (Liveness.get(i) != DIKind::Yes)
27482739
return false;
2740+
}
2741+
2742+
// If the self.init() or super.init() call threw an error and
2743+
// we caught it, self is no longer available.
2744+
if (TheMemory.isNonRootClassSelf()) {
2745+
if (getSelfInitializedAtInst(Use.Inst) != DIKind::Yes) {
2746+
auto SelfLiveness = getLivenessAtInst(Use.Inst,
2747+
0, TheMemory.NumElements);
2748+
if (SelfLiveness.isAllYes()) {
2749+
if (FailedSelfUse) *FailedSelfUse = true;
2750+
return false;
2751+
}
2752+
}
2753+
}
27492754

27502755
return true;
27512756
}

test/SILOptimizer/definite_init_failable_initializers_diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ErrantClass : ErrantBaseClass {
5959
} catch {
6060
try super.init() // expected-error {{'self' used inside 'catch' block reachable from super.init call}}
6161
}
62-
} // expected-error {{'self' used inside 'catch' block reachable from super.init call}}
62+
}
6363

6464
init(invalidEscapeDesignated3: ()) {
6565
x = 10
@@ -95,7 +95,7 @@ class ErrantClass : ErrantBaseClass {
9595
} catch {
9696
try self.init() // expected-error {{'self' used inside 'catch' block reachable from self.init call}}
9797
}
98-
} // expected-error {{'self' used inside 'catch' block reachable from self.init call}}
98+
}
9999

100100
convenience init(invalidEscapeConvenience3: ()) throws {
101101
do {

0 commit comments

Comments
 (0)