Skip to content

Commit e1e59ac

Browse files
committed
Handle OperandOwnerhip::NonUse in PrunedLiveness::computeSSALiveness.
Fixes a bug in the simple PrunedLiveness routine for SSA values. Without this fix, the init_existential_ref instruction below was not considered a lifetime-ending use because the non-use type dependednt operand (which is not really an operand at all) would override the forwarding operand: %1 = open_existential_ref %0 : $any P to $@opened("...", any P) Self %2 = init_existential_ref %1 : $@opened("...", any P) Self : $@opened("...", any P) Self, $AnyObject This will be tested by silgen_cleanup_complete_ossa.sil.
1 parent a7e5f28 commit e1e59ac

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,26 @@ bool PrunedLiveness::areUsesOutsideBoundaryOfDef(
263263
// uses with no holes in the liverange. The lifetime-ending uses are also
264264
// recorded--destroy_value or end_borrow. However destroy_values may not
265265
// jointly-post dominate if dead-end blocks are present.
266+
//
267+
// Note: Uses with OperandOwnership::NonUse cannot be considered normal uses for
268+
// liveness. Otherwise, liveness would need to separately track non-uses
269+
// everywhere. Non-uses cannot be treated like normal non-lifetime-ending uses
270+
// because they can occur on both applies, which need to extend liveness to the
271+
// return point, and on forwarding instructions, like init_existential_ref,
272+
// which need to consume their use even when type-dependent operands exist.
266273
void PrunedLiveness::computeSSALiveness(SILValue def) {
267274
initializeDefBlock(def->getParentBlock());
268275
for (Operand *use : def->getUses()) {
269-
updateForUse(use->getUser(), use->isLifetimeEnding());
276+
switch (use->getOperandOwnership()) {
277+
default:
278+
updateForUse(use->getUser(), use->isLifetimeEnding());
279+
break;
280+
case OperandOwnership::NonUse:
281+
break;
282+
case OperandOwnership::Borrow:
283+
updateForBorrowingOperand(use);
284+
break;
285+
}
270286
}
271287
}
272288

0 commit comments

Comments
 (0)