Skip to content

Commit 3136d2e

Browse files
committed
[DebugInfo] [IRGen] Use instruction column number for variables
The source location for the variable should be the value in VarInfo if set, otherwise it should use the location of the instruction. Both ways should be consistent, and as we use column number if VarInfo is set, we have to do it if isnt, too.
1 parent 0ac6d36 commit 3136d2e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3180,7 +3180,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
31803180

31813181
// Create the descriptor for the variable.
31823182
unsigned DVarLine = DInstLine;
3183-
uint16_t DVarCol = 0;
3183+
uint16_t DVarCol = DInstLoc.Column;
31843184
if (VarInfo.Loc) {
31853185
auto DVarLoc = getStartLocation(VarInfo.Loc);
31863186
DVarLine = DVarLoc.Line;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %target-swiftc_driver -g -emit-ir %s | %FileCheck %s
2+
sil_stage canonical
3+
4+
import Builtin
5+
import Swift
6+
7+
sil_scope 2 { loc "simple.swift":1:2 parent @test_debug_value : $@convention(thin) (Builtin.Int64) -> () }
8+
9+
// CHECK-LABEL: @test_debug_value
10+
// CHECK-SAME: !dbg ![[FUNC_DI:[0-9]+]]
11+
sil hidden @test_debug_value : $@convention(thin) (Builtin.Int64) -> () {
12+
bb0(%0 : $Builtin.Int64):
13+
// CHECK: @llvm.dbg.declare(metadata ptr
14+
// CHECK-SAME: metadata ![[VAR_DI:[0-9]+]]
15+
// CHECK-SAME: ), !dbg ![[LOC_DI:[0-9]+]]
16+
debug_value %0 : $Builtin.Int64, var, name "x", loc "simple.swift":1:16, scope 2
17+
%zero = integer_literal $Builtin.Int64, 0
18+
debug_value %zero : $Builtin.Int64, var, (name "x", loc "simple.swift":1:16, scope 2), loc "simple.swift":3:4, scope 2
19+
%1 = tuple ()
20+
return %1 : $()
21+
}
22+
23+
// One debug_value uses the VarInfo way, the other uses the instruction way.
24+
// They should both resolve to the same variable, so we should only have one x.
25+
26+
// CHECK: !DISubprogram(name: "test_debug_value"
27+
// CHECK-SAME: retainedNodes: ![[RETAINED:[0-9]+]]
28+
29+
// Only one variable should be retained
30+
// CHECK: ![[RETAINED]] = !{![[VAR_DI]]}
31+
32+
// CHECK-NOT: !DILocalVariable(name: "x"
33+
// CHECK: ![[VAR_DI]] = !DILocalVariable(name: "x"
34+
// CHECK-SAME: line: 1
35+
// CHECK-NOT: !DILocalVariable(name: "x"

0 commit comments

Comments
 (0)