@@ -838,12 +838,13 @@ extension ExtendableScope {
838838 // Collect the original end instructions and extend the range to to cover them. The resulting access scope
839839 // must cover the original scope because it may protect other memory operations.
840840 let endsToErase = self . endInstructions
841- var unusedEnds = InstructionSet ( context)
841+ // Track range ending instructions that have not been reused for later deletion.
842+ var unreusedEnds = InstructionSet ( context)
842843 for end in endsToErase {
843844 assert ( range. inclusiveRangeContains ( end) )
844- unusedEnds . insert ( end)
845+ unreusedEnds . insert ( end)
845846 }
846- defer { unusedEnds . deinitialize ( ) }
847+ defer { unreusedEnds . deinitialize ( ) }
847848 for end in range. ends {
848849 let location = end. location. asAutoGenerated
849850 switch end {
@@ -861,9 +862,9 @@ extension ExtendableScope {
861862 default :
862863 break
863864 }
864- if unusedEnds . contains ( end) {
865- unusedEnds . erase ( end)
866- assert ( !unusedEnds . contains ( end) )
865+ if unreusedEnds . contains ( end) {
866+ unreusedEnds . erase ( end)
867+ assert ( !unreusedEnds . contains ( end) )
867868 continue
868869 }
869870 Builder . insert ( after: end, location: location, context) {
@@ -875,7 +876,7 @@ extension ExtendableScope {
875876 let builder = Builder ( before: exitInst, location: location, context)
876877 range. insert ( createEndInstruction ( builder, context) )
877878 }
878- return endsToErase. filter { unusedEnds . contains ( $0) }
879+ return endsToErase. filter { unreusedEnds . contains ( $0) }
879880 }
880881
881882 /// Create a scope-ending instruction at 'builder's insertion point.
0 commit comments