@@ -1647,8 +1647,7 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
1647
1647
bool InCleanupBlock = false ;
1648
1648
bool KeepCurrentLocation = false ;
1649
1649
1650
- for (auto InsnIter = BB->begin (); InsnIter != BB->end (); ++InsnIter) {
1651
- auto &I = *InsnIter;
1650
+ for (auto &I : *BB) {
1652
1651
if (IGM.DebugInfo ) {
1653
1652
// Set the debug info location for I, if applicable.
1654
1653
SILLocation ILoc = I.getLoc ();
@@ -1664,7 +1663,7 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
1664
1663
InCleanupBlock = true ;
1665
1664
// Scan ahead to see if this is the final cleanup block in
1666
1665
// this basic block.
1667
- auto It = InsnIter ;
1666
+ auto It = I. getIterator () ;
1668
1667
do ++It; while (It != BB->end () &&
1669
1668
It->getLoc ().is <CleanupLocation>());
1670
1669
// We are still in the middle of a basic block?
@@ -1694,9 +1693,14 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
1694
1693
// Set the builder's debug location.
1695
1694
if (DS && !KeepCurrentLocation)
1696
1695
IGM.DebugInfo ->setCurrentLoc (Builder, DS, ILoc);
1697
- else
1696
+ else {
1697
+ // Reuse the last scope for an easier-to-read line table.
1698
+ auto Prev = --I.getIterator ();
1699
+ if (Prev != BB->end ())
1700
+ DS = Prev->getDebugScope ();
1698
1701
// Use an artificial (line 0) location.
1699
1702
IGM.DebugInfo ->setCurrentLoc (Builder, DS);
1703
+ }
1700
1704
1701
1705
if (isa<TermInst>(&I))
1702
1706
emitDebugVariableRangeExtension (BB);
0 commit comments