@@ -80,6 +80,9 @@ static SILInstruction *endOSSALifetime(SILValue value,
8080 if (auto scopedAddress = ScopedAddressValue (value)) {
8181 return scopedAddress.createScopeEnd (builder.getInsertionPoint (), loc);
8282 }
83+ if (value->getOwnershipKind () == OwnershipKind::None) {
84+ return builder.createExtendLifetime (loc, value);
85+ }
8386 return builder.createEndBorrow (loc, lookThroughBorrowedFromUser (value));
8487}
8588
@@ -297,9 +300,16 @@ void AvailabilityBoundaryVisitor::computeRegion(
297300 regionWorklist.push (block);
298301 };
299302
300- for (auto *endBlock : boundary.endBlocks ) {
301- if (!consumingBlocks.contains (endBlock)) {
302- collect (endBlock);
303+ // Trivial values that correspond to local variables (as opposed to
304+ // ScopedAddresses) are available only up to their last extend_lifetime on
305+ // non-dead-end paths. They cannot be consumed, but are only "available" up to
306+ // the end of their scope.
307+ if (value->getOwnershipKind () != OwnershipKind::None
308+ || ScopedAddressValue (value)) {
309+ for (auto *endBlock : boundary.endBlocks ) {
310+ if (!consumingBlocks.contains (endBlock)) {
311+ collect (endBlock);
312+ }
303313 }
304314 }
305315 for (SILBasicBlock *edge : boundary.boundaryEdges ) {
@@ -497,12 +507,21 @@ bool OSSALifetimeCompletion::analyzeAndUpdateLifetime(SILValue value,
497507 if (auto scopedAddress = ScopedAddressValue (value)) {
498508 return analyzeAndUpdateLifetime (scopedAddress, boundary);
499509 }
500-
501510 // Called for inner borrows, inner adjacent reborrows, inner reborrows, and
502511 // scoped addresses.
503512 auto handleInnerScope = [this , boundary](SILValue innerBorrowedValue) {
504513 completeOSSALifetime (innerBorrowedValue, boundary);
505514 };
515+ if (value->getOwnershipKind () == OwnershipKind::None) {
516+ // Trivial variable lifetimes are only relevant up to the extend_lifetime
517+ // instructions emitted by SILGen. Their other uses have no meaning with
518+ // respect to lifetime. The only purpose of "completing" their lifetime is
519+ // to insert extend_lifetime on dead-end blocks.
520+ LinearLiveness liveness (value);
521+ liveness.compute ();
522+ return endLifetimeAtBoundary (value, liveness.getLiveness (), boundary,
523+ deadEndBlocks);
524+ }
506525 InteriorLiveness liveness (value);
507526 liveness.compute (domInfo, handleInnerScope);
508527 // TODO: Rebuild outer adjacent phis on demand (SILGen does not currently
0 commit comments