Skip to content

Commit 4c9d736

Browse files
committed
DI: Use new 'self initialized' analysis in LifetimeChecker::handleStoreUse()
1 parent 18c29b0 commit 4c9d736

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -973,13 +973,6 @@ void LifetimeChecker::emitSelfConsumedDiagnostic(SILInstruction *Inst) {
973973
void LifetimeChecker::handleStoreUse(unsigned UseID) {
974974
DIMemoryUse &InstInfo = Uses[UseID];
975975

976-
if (TheMemory.isAnyInitSelf()) {
977-
if (getSelfConsumedAtInst(InstInfo.Inst) != DIKind::No) {
978-
emitSelfConsumedDiagnostic(InstInfo.Inst);
979-
return;
980-
}
981-
}
982-
983976
// Determine the liveness state of the element that we care about.
984977
auto Liveness = getLivenessAtInst(InstInfo.Inst, InstInfo.FirstElement,
985978
InstInfo.NumElements);
@@ -997,6 +990,17 @@ void LifetimeChecker::handleStoreUse(unsigned UseID) {
997990
isFullyUninitialized = false;
998991
}
999992

993+
if (TheMemory.isNonRootClassSelf()) {
994+
if (getSelfInitializedAtInst(InstInfo.Inst) != DIKind::Yes) {
995+
auto SelfLiveness = getLivenessAtInst(InstInfo.Inst,
996+
0, TheMemory.NumElements);
997+
if (SelfLiveness.isAllYes()) {
998+
emitSelfConsumedDiagnostic(InstInfo.Inst);
999+
return;
1000+
}
1001+
}
1002+
}
1003+
10001004
// If this is a partial store into a struct and the whole struct hasn't been
10011005
// initialized, diagnose this as an error.
10021006
if (InstInfo.Kind == DIUseKind::PartialStore && !isFullyInitialized) {

test/SILOptimizer/definite_init_diagnostics.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,3 +1230,20 @@ class SuperConvenienceSub : SuperConvenienceBase {
12301230
self.init(i1, i1)
12311231
}
12321232
}
1233+
1234+
// While testing some changes I found this regression that wasn't
1235+
// covered by any existing tests
1236+
class Base {}
1237+
1238+
func makeAnAny() -> Any { return 3 }
1239+
1240+
class Derived : Base {
1241+
var x: Int?
1242+
var y: Int?
1243+
1244+
override init() {
1245+
x = makeAnAny() as? Int
1246+
y = makeAnAny() as? Int
1247+
super.init()
1248+
}
1249+
}

0 commit comments

Comments
 (0)