Skip to content

Debug Info: Don't reset the debug scope after leaving the outermost s… #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,7 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
if (IGM.DebugInfo) {
// Set the debug info location for I, if applicable.
SILLocation ILoc = I.getLoc();
auto DS = I.getDebugScope();
// Handle cleanup locations.
if (ILoc.getKind() == SILLocation::CleanupKind) {
// Cleanup locations point to the decl of the the value that
Expand All @@ -1591,13 +1592,13 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
if (!KeepCurrentLocation) {
assert(BB->getTerminator());
ILoc = BB->getTerminator()->getLoc();
DS = BB->getTerminator()->getDebugScope();
}
} else if (InCleanupBlock) {
KeepCurrentLocation = false;
InCleanupBlock = false;
}

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

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

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

// Function argument handling.
Expand Down
6 changes: 3 additions & 3 deletions lib/SILGen/SILGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
DebugScopeStack.pop_back();
if (DebugScopeStack.size())
B.setCurrentDebugScope(DebugScopeStack.back());
else {
B.setCurrentDebugScope(F.getDebugScope());
}
// Don't reset the debug scope after leaving the outermost scope,
// because the debugger is not expecting the function epilogue to
// be in a different scope.
}

//===--------------------------------------------------------------------===//
Expand Down
13 changes: 8 additions & 5 deletions test/DebugInfo/return.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ class X {
public func ifelseexpr() -> Int64 {
var x = X(i:0);
// CHECK: [[META:%.*]] = call %swift.type* @_TMaC6return1X()
// CHECK: [[X:%.*]] = call %C6return1X* @_TFC6return1XCfT1iVs5Int64_S0_(i64 0, %swift.type* [[META]])
// CHECK: [[X:%.*]] = call %C6return1X* @_TFC6return1XCfT1iVs5Int64_S0_(
// CHECK-SAME: i64 0, %swift.type* [[META]])
// CHECK: @swift_release to void (%C6return1X*)*)(%C6return1X* [[X]])
if true {
x.x++;
} else {
x.x--;
}
// CHECK: @swift_release to void (%C6return1X*)*)(%C6return1X* [[X]])
// CHECK: @swift_release to void (%C6return1X*)*)(%C6return1X* [[X]]) {{.*}}, !dbg ![[RELEASE:.*]]
// CHECK: ret{{.*}}, !dbg ![[RET:.*]]
// CHECK: ![[RELEASE]] = !DILocation(line: [[@LINE+1]],
return x.x; // CHECK: ![[RET]] = !DILocation(line: [[@LINE]],
// CHECK: @swift_release to void (%C6return1X*)*)(%C6return1X* [[X]])
// CHECK-SAME: , !dbg ![[RELEASE:.*]]

// The ret instruction should be in the same scope as the return expression.
// CHECK: ret{{.*}}, !dbg ![[RELEASE]]
return x.x; // CHECK: ![[RELEASE]] = !DILocation(line: [[@LINE]], column: 3
}