Skip to content

Commit 3e9a30b

Browse files
committed
DI: Only call getSelfConsumedAtInst() inside initializers
1 parent d5a21fa commit 3e9a30b

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -923,15 +923,17 @@ void LifetimeChecker::handleLoadUse(unsigned UseID) {
923923
void LifetimeChecker::handleStoreUse(unsigned UseID) {
924924
DIMemoryUse &InstInfo = Uses[UseID];
925925

926-
if (getSelfConsumedAtInst(InstInfo.Inst) != DIKind::No) {
927-
// FIXME: more specific diagnostics here, handle this case gracefully below.
928-
if (!shouldEmitError(InstInfo.Inst))
929-
return;
926+
if (TheMemory.isAnyInitSelf()) {
927+
if (getSelfConsumedAtInst(InstInfo.Inst) != DIKind::No) {
928+
// FIXME: more specific diagnostics here, handle this case gracefully below.
929+
if (!shouldEmitError(InstInfo.Inst))
930+
return;
930931

931-
diagnose(Module, InstInfo.Inst->getLoc(),
932-
diag::self_inside_catch_superselfinit,
933-
(unsigned)TheMemory.isDelegatingInit());
934-
return;
932+
diagnose(Module, InstInfo.Inst->getLoc(),
933+
diag::self_inside_catch_superselfinit,
934+
(unsigned)TheMemory.isDelegatingInit());
935+
return;
936+
}
935937
}
936938

937939
// Determine the liveness state of the element that we care about.
@@ -1664,6 +1666,7 @@ void LifetimeChecker::handleLoadUseFailure(const DIMemoryUse &Use,
16641666
void LifetimeChecker::handleSelfInitUse(DIMemoryUse &InstInfo) {
16651667
auto *Inst = InstInfo.Inst;
16661668

1669+
assert(TheMemory.isAnyInitSelf());
16671670
assert(TheMemory.getType()->hasReferenceSemantics());
16681671

16691672
if (getSelfConsumedAtInst(Inst) != DIKind::No) {
@@ -1899,8 +1902,10 @@ void LifetimeChecker::processNonTrivialRelease(unsigned ReleaseID) {
18991902
isa<DestroyAddrInst>(Release));
19001903

19011904
auto Availability = getLivenessAtInst(Release, 0, TheMemory.NumElements);
1902-
DIKind SelfConsumed =
1903-
getSelfConsumedAtInst(Release);
1905+
DIKind SelfConsumed = DIKind::No;
1906+
1907+
if (TheMemory.isAnyInitSelf())
1908+
SelfConsumed = getSelfConsumedAtInst(Release);
19041909

19051910
if (SelfConsumed == DIKind::Yes) {
19061911
// We're in an error path after performing a self.init or super.init
@@ -2643,12 +2648,14 @@ bool LifetimeChecker::isInitializedAtUse(const DIMemoryUse &Use,
26432648
bool *FailedSelfUse) {
26442649
if (FailedSelfUse) *FailedSelfUse = false;
26452650
if (SuperInitDone) *SuperInitDone = true;
2646-
2647-
// If the self.init() or super.init() call threw an error and
2648-
// we caught it, self is no longer available.
2649-
if (getSelfConsumedAtInst(Use.Inst) != DIKind::No) {
2650-
if (FailedSelfUse) *FailedSelfUse = true;
2651-
return false;
2651+
2652+
if (TheMemory.isAnyInitSelf()) {
2653+
// If the self.init() or super.init() call threw an error and
2654+
// we caught it, self is no longer available.
2655+
if (getSelfConsumedAtInst(Use.Inst) != DIKind::No) {
2656+
if (FailedSelfUse) *FailedSelfUse = true;
2657+
return false;
2658+
}
26522659
}
26532660

26542661
// Determine the liveness states of the elements that we care about.

0 commit comments

Comments
 (0)