@@ -89,6 +89,9 @@ class MemoryLifetimeVerifier {
8989 // / Register the destination address of a store_borrow as borrowed location.
9090 void registerStoreBorrowLocation (SILValue addr);
9191
92+ // / Registers all store_borrow instructions in a block.
93+ void registerStoreBorrowsInBlock (SILBasicBlock *block);
94+
9295 // / Handles locations of the predecessor's terminator, which are only valid
9396 // / in \p block.
9497 // / Example: @out results of try_apply. They are only valid in the
@@ -286,6 +289,13 @@ void MemoryLifetimeVerifier::registerStoreBorrowLocation(SILValue addr) {
286289 }
287290}
288291
292+ void MemoryLifetimeVerifier::registerStoreBorrowsInBlock (SILBasicBlock *block) {
293+ for (SILInstruction &inst : *block) {
294+ if (auto *sbi = dyn_cast<StoreBorrowInst>(&inst))
295+ registerStoreBorrowLocation (sbi->getDest ());
296+ }
297+ }
298+
289299void MemoryLifetimeVerifier::initDataflow (BitDataflow &dataFlow) {
290300 // Initialize the entry and exit sets to all-bits-set. Except for the function
291301 // entry.
@@ -579,7 +589,6 @@ void MemoryLifetimeVerifier::checkBlock(SILBasicBlock *block, Bits &bits) {
579589 case SILInstructionKind::StoreBorrowInst: {
580590 SILValue destAddr = cast<StoreBorrowInst>(&I)->getDest ();
581591 locations.setBits (bits, destAddr);
582- registerStoreBorrowLocation (destAddr);
583592 break ;
584593 }
585594 case SILInstructionKind::CopyAddrInst: {
@@ -764,6 +773,7 @@ void MemoryLifetimeVerifier::verify() {
764773 locations.handleSingleBlockLocations ([this ](SILBasicBlock *block) {
765774 storeBorrowLocations.clear ();
766775 Bits bits (locations.getNumLocations ());
776+ registerStoreBorrowsInBlock (block);
767777 checkBlock (block, bits);
768778 });
769779}
0 commit comments