Skip to content

Commit 24c4fcc

Browse files
committed
[DI] Fix check that ignores loads related to assign_or_init and assign_by_wrapper
For cases where init accessor field has a nonmutating set we need ignore copies and borrows associated with load of "self" because they are going to be erased together with the setter application by DI.
1 parent ab54ea7 commit 24c4fcc

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,32 @@ bool LifetimeChecker::shouldEmitError(const SILInstruction *Inst) {
662662
// This is safe to ignore because assign_by_wrapper/assign_or_init will
663663
// only be re-written to use the setter if the value is fully initialized.
664664
if (auto *load = dyn_cast<SingleValueInstruction>(Inst)) {
665-
if (auto Op = load->getSingleUse()) {
666-
if (auto PAI = dyn_cast<PartialApplyInst>(Op->getUser())) {
667-
if (std::find_if(PAI->use_begin(), PAI->use_end(), [](auto PAIUse) {
668-
return isa<AssignByWrapperInst>(PAIUse->getUser()) ||
669-
isa<AssignOrInitInst>(PAIUse->getUser());
670-
}) != PAI->use_end()) {
671-
return false;
672-
}
665+
auto isOnlyUsedByPartialApply =
666+
[&](const SingleValueInstruction *inst) -> PartialApplyInst * {
667+
Operand *result = nullptr;
668+
for (auto *op : inst->getUses()) {
669+
auto *user = op->getUser();
670+
671+
// Ignore copies, destroys and borrows because they'd be
672+
// erased together with the setter.
673+
if (isa<DestroyValueInst>(user) || isa<CopyValueInst>(user) ||
674+
isa<BeginBorrowInst>(user) || isa<EndBorrowInst>(user))
675+
continue;
676+
677+
if (result)
678+
return nullptr;
679+
680+
result = op;
681+
}
682+
return result ? dyn_cast<PartialApplyInst>(result->getUser()) : nullptr;
683+
};
684+
685+
if (auto *PAI = isOnlyUsedByPartialApply(load)) {
686+
if (std::find_if(PAI->use_begin(), PAI->use_end(), [](auto PAIUse) {
687+
return isa<AssignByWrapperInst>(PAIUse->getUser()) ||
688+
isa<AssignOrInitInst>(PAIUse->getUser());
689+
}) != PAI->use_end()) {
690+
return false;
673691
}
674692
}
675693
}

0 commit comments

Comments
 (0)