Look through copy_addr and opened existentials to diagnose move-only sources.

This commit is contained in:
Joe Groff
2023-12-15 16:36:09 -08:00
parent 1b9a0712bf
commit 02800046c6
3 changed files with 23 additions and 7 deletions

View File

@@ -93,6 +93,19 @@ static void getVariableNameForValue(SILValue value2,
value2->getFunction());
while (true) {
if (auto *allocInst = dyn_cast<AllocationInst>(searchValue)) {
// If the instruction itself doesn't carry any variable info, see whether
// it's copied from another place that does.
if (!allocInst->getDecl()) {
if (auto copy = allocInst->getSingleUserOfType<CopyAddrInst>()) {
if (copy->getDest() == allocInst
&& !copy->isTakeOfSrc()
&& copy->isInitializationOfDest()) {
searchValue = copy->getSrc();
continue;
}
}
}
variableNamePath.push_back(allocInst);
break;
}
@@ -102,6 +115,11 @@ static void getVariableNameForValue(SILValue value2,
break;
}
if (auto *oeInst = dyn_cast<OpenExistentialAddrInst>(searchValue)) {
searchValue = oeInst->getOperand();
continue;
}
if (auto *rei = dyn_cast<RefElementAddrInst>(searchValue)) {
variableNamePath.push_back(rei);
searchValue = rei->getOperand();