@@ -838,12 +838,13 @@ extension ExtendableScope {
838
838
// Collect the original end instructions and extend the range to to cover them. The resulting access scope
839
839
// must cover the original scope because it may protect other memory operations.
840
840
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)
842
843
for end in endsToErase {
843
844
assert ( range. inclusiveRangeContains ( end) )
844
- unusedEnds . insert ( end)
845
+ unreusedEnds . insert ( end)
845
846
}
846
- defer { unusedEnds . deinitialize ( ) }
847
+ defer { unreusedEnds . deinitialize ( ) }
847
848
for end in range. ends {
848
849
let location = end. location. asAutoGenerated
849
850
switch end {
@@ -861,9 +862,9 @@ extension ExtendableScope {
861
862
default :
862
863
break
863
864
}
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) )
867
868
continue
868
869
}
869
870
Builder . insert ( after: end, location: location, context) {
@@ -875,7 +876,7 @@ extension ExtendableScope {
875
876
let builder = Builder ( before: exitInst, location: location, context)
876
877
range. insert ( createEndInstruction ( builder, context) )
877
878
}
878
- return endsToErase. filter { unusedEnds . contains ( $0) }
879
+ return endsToErase. filter { unreusedEnds . contains ( $0) }
879
880
}
880
881
881
882
/// Create a scope-ending instruction at 'builder's insertion point.
0 commit comments