@@ -57,18 +57,32 @@ private extension Instruction {
5757private extension Argument {
5858 func verify( _ context: FunctionPassContext ) {
5959 if let phi = Phi ( self ) , phi. value. ownership == . guaranteed {
60- var forwardingBorrowedFromFound = false
61- for use in phi. value. uses {
62- require ( use. instruction is BorrowedFromInst ,
63- " guaranteed phi: \( self ) \n has non borrowed-from use: \( use) " )
64- if use. index == 0 {
65- require ( !forwardingBorrowedFromFound, " phi \( self ) has multiple forwarding borrowed-from uses " )
66- forwardingBorrowedFromFound = true
67- }
60+
61+ phi. verifyBorrowedFromUse ( )
62+
63+ require ( phi. isReborrow == phi. hasBorrowEndingUse ||
64+ // In a dead-end block an end_borrow might have been deleted.
65+ // TODO: this check is not needed anymore once we have complete OSSA lifetimes.
66+ ( isReborrow && context. deadEndBlocks. isDeadEnd ( parentBlock) ) ,
67+ " \( self ) has stale reborrow flag " ) ;
68+ }
69+ }
70+
71+ }
72+
73+ private extension Phi {
74+ func verifyBorrowedFromUse( ) {
75+ var forwardingBorrowedFromFound = false
76+ for use in value. uses {
77+ require ( use. instruction is BorrowedFromInst ,
78+ " guaranteed phi: \( self ) \n has non borrowed-from use: \( use) " )
79+ if use. index == 0 {
80+ require ( !forwardingBorrowedFromFound, " phi \( self ) has multiple forwarding borrowed-from uses " )
81+ forwardingBorrowedFromFound = true
6882 }
69- require ( forwardingBorrowedFromFound,
70- " missing forwarding borrowed-from user of guaranteed phi \( phi) " )
7183 }
84+ require ( forwardingBorrowedFromFound,
85+ " missing forwarding borrowed-from user of guaranteed phi \( self ) " )
7286 }
7387}
7488
0 commit comments