[CopyPropagation] Only delete if canonicalized.

Owned lifetime canonicalization bails on move-only values.

Previously, though, every value that was fed to canonicalization was
then attempted to be deleted.  For dead move-only values, the result
could be to shorten move-only lifetimes, which is illegal per language
rules.

Here, this is fixed by not attempting to delete owned values for which
canonicalization bailed.

rdar://114323803
This commit is contained in:
Nate Chandler
2023-08-23 08:34:26 -07:00
parent 9179bc5611
commit a67c22d905
2 changed files with 28 additions and 1 deletions

View File

@@ -617,7 +617,9 @@ void CopyPropagation::run() {
// Canonicalize all owned defs.
while (!defWorklist.ownedValues.empty()) {
SILValue def = defWorklist.ownedValues.pop_back_val();
canonicalizer.canonicalizeValueLifetime(def);
auto canonicalized = canonicalizer.canonicalizeValueLifetime(def);
if (!canonicalized)
continue;
// Copies of borrowed values may be dead.
if (auto *inst = def->getDefiningInstruction())
deleter.trackIfDead(inst);