Merge pull request #35218 from hborla/assign-by-wrapper-crash

[Property Wrappers] Fix a few corner cases where property wrappers with nonmutating setters fail in DI
This commit is contained in:
Holly Borla
2021-01-11 08:57:35 -08:00
committed by GitHub
5 changed files with 99 additions and 84 deletions

View File

@@ -625,6 +625,22 @@ bool LifetimeChecker::shouldEmitError(const SILInstruction *Inst) {
}))
return false;
// Ignore loads used only by an assign_by_wrapper setter. This
// is safe to ignore because assign_by_wrapper will only be
// re-written to use the setter if the value is fully initialized.
if (auto *load = dyn_cast<SingleValueInstruction>(Inst)) {
if (auto Op = load->getSingleUse()) {
if (auto PAI = dyn_cast<PartialApplyInst>(Op->getUser())) {
if (std::find_if(PAI->use_begin(), PAI->use_end(),
[](auto PAIUse) {
return isa<AssignByWrapperInst>(PAIUse->getUser());
}) != PAI->use_end()) {
return false;
}
}
}
}
EmittedErrorLocs.push_back(InstLoc);
return true;
}
@@ -1842,20 +1858,6 @@ void LifetimeChecker::handleLoadUseFailure(const DIMemoryUse &Use,
TheMemory.isAnyInitSelf() && !TheMemory.isClassInitSelf()) {
if (!shouldEmitError(Inst)) return;
// Ignore loads used only for a set-by-value (nonmutating) setter
// since it will be deleted by lowering anyway.
auto load = cast<SingleValueInstruction>(Inst);
if (auto Op = load->getSingleUse()) {
if (auto PAI = dyn_cast<PartialApplyInst>(Op->getUser())) {
if (std::find_if(PAI->use_begin(), PAI->use_end(),
[](auto PAIUse) {
return isa<AssignByWrapperInst>(PAIUse->getUser());
}) != PAI->use_end()) {
return;
}
}
}
diagnose(Module, Inst->getLoc(), diag::use_of_self_before_fully_init);
noteUninitializedMembers(Use);
return;