Skip to content

Commit e1cac38

Browse files
committed
Don't delete dead lexical values
1 parent ab993cf commit e1cac38

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lib/SILOptimizer/Utils/InstructionDeleter.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,24 @@ static bool isScopeAffectingInstructionDead(SILInstruction *inst,
6262
return false;
6363
}
6464

65-
// If inst has any owned move-only value as a result, deleting it may shorten
66-
// that value's lifetime which is illegal according to language rules.
67-
//
68-
// In particular, this check is needed before returning true when
69-
// getSingleValueCopyOrCast returns true. That function returns true for
70-
// move_value instructions. And `move_value %moveOnlyValue` must not be
71-
// deleted.
7265
for (auto result : inst->getResults()) {
66+
// If inst has any owned move-only value as a result, deleting it may
67+
// shorten that value's lifetime which is illegal according to language
68+
// rules.
69+
//
70+
// In particular, this check is needed before returning true when
71+
// getSingleValueCopyOrCast returns true. That function returns true for
72+
// move_value instructions. And `move_value %moveOnlyValue` must not be
73+
// deleted.
7374
if (result->getType().getASTType()->isNoncopyable() &&
7475
result->getOwnershipKind() == OwnershipKind::Owned) {
7576
return false;
7677
}
78+
79+
// If result was lexical, lifetime shortening maybe observed, return.
80+
if (result->isLexical()) {
81+
return false;
82+
}
7783
}
7884

7985
// If inst is a copy or beginning of scope, inst is dead, since we know that

0 commit comments

Comments
 (0)