Skip to content

Commit c6ddf3c

Browse files
committed
Merge pull request #6 from adrian-prantl/master
Debug Info: Don't reset the debug scope after leaving the outermost s…
2 parents d432286 + f40d28f commit c6ddf3c

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
15681568
if (IGM.DebugInfo) {
15691569
// Set the debug info location for I, if applicable.
15701570
SILLocation ILoc = I.getLoc();
1571+
auto DS = I.getDebugScope();
15711572
// Handle cleanup locations.
15721573
if (ILoc.getKind() == SILLocation::CleanupKind) {
15731574
// Cleanup locations point to the decl of the the value that
@@ -1591,13 +1592,13 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
15911592
if (!KeepCurrentLocation) {
15921593
assert(BB->getTerminator());
15931594
ILoc = BB->getTerminator()->getLoc();
1595+
DS = BB->getTerminator()->getDebugScope();
15941596
}
15951597
} else if (InCleanupBlock) {
15961598
KeepCurrentLocation = false;
15971599
InCleanupBlock = false;
15981600
}
15991601

1600-
auto DS = I.getDebugScope();
16011602
assert((!DS || (DS->SILFn == CurSILFn || DS->InlinedCallSite)) &&
16021603
"insn was not inlined, but belongs to a different function");
16031604

@@ -1612,7 +1613,8 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
16121613

16131614
// Ignore scope-less instructions and have IRBuilder reuse the
16141615
// previous location and scope.
1615-
if (DS && !KeepCurrentLocation)
1616+
if (DS && !KeepCurrentLocation &&
1617+
!(ILoc.isInPrologue() && ILoc.getKind() == SILLocation::CleanupKind))
16161618
IGM.DebugInfo->setCurrentLoc(Builder, DS, ILoc);
16171619

16181620
// Function argument handling.

lib/SILGen/SILGenFunction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
502502
DebugScopeStack.pop_back();
503503
if (DebugScopeStack.size())
504504
B.setCurrentDebugScope(DebugScopeStack.back());
505-
else {
506-
B.setCurrentDebugScope(F.getDebugScope());
507-
}
505+
// Don't reset the debug scope after leaving the outermost scope,
506+
// because the debugger is not expecting the function epilogue to
507+
// be in a different scope.
508508
}
509509

510510
//===--------------------------------------------------------------------===//

test/DebugInfo/return.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ class X {
99
public func ifelseexpr() -> Int64 {
1010
var x = X(i:0);
1111
// CHECK: [[META:%.*]] = call %swift.type* @_TMaC6return1X()
12-
// CHECK: [[X:%.*]] = call %C6return1X* @_TFC6return1XCfT1iVs5Int64_S0_(i64 0, %swift.type* [[META]])
12+
// CHECK: [[X:%.*]] = call %C6return1X* @_TFC6return1XCfT1iVs5Int64_S0_(
13+
// CHECK-SAME: i64 0, %swift.type* [[META]])
1314
// CHECK: @swift_release to void (%C6return1X*)*)(%C6return1X* [[X]])
1415
if true {
1516
x.x++;
1617
} else {
1718
x.x--;
1819
}
1920
// CHECK: @swift_release to void (%C6return1X*)*)(%C6return1X* [[X]])
20-
// CHECK: @swift_release to void (%C6return1X*)*)(%C6return1X* [[X]]) {{.*}}, !dbg ![[RELEASE:.*]]
21-
// CHECK: ret{{.*}}, !dbg ![[RET:.*]]
22-
// CHECK: ![[RELEASE]] = !DILocation(line: [[@LINE+1]],
23-
return x.x; // CHECK: ![[RET]] = !DILocation(line: [[@LINE]],
21+
// CHECK: @swift_release to void (%C6return1X*)*)(%C6return1X* [[X]])
22+
// CHECK-SAME: , !dbg ![[RELEASE:.*]]
23+
24+
// The ret instruction should be in the same scope as the return expression.
25+
// CHECK: ret{{.*}}, !dbg ![[RELEASE]]
26+
return x.x; // CHECK: ![[RELEASE]] = !DILocation(line: [[@LINE]], column: 3
2427
}
2528

0 commit comments

Comments
 (0)