Skip to content

Commit e1a5472

Browse files
committed
Emit 1-based column numbers in debuginfo
The debuginfo column numbers are 1-based. The value 0 indicates that no column has been specified. Translate 0-based column numbers to 1-based when emitting debug information.
1 parent abc3073 commit e1a5472

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ fn make_mir_scope(
7979
parent_scope.scope_metadata.unwrap(),
8080
file_metadata,
8181
loc.line as c_uint,
82-
loc.col.to_usize() as c_uint,
82+
// Loc column is 0-based while debug one is 1-based.
83+
loc.col.to_usize() as c_uint + 1,
8384
))
8485
};
8586
debug_context.scopes[scope] = DebugScope {

src/librustc_codegen_llvm/debuginfo/source_loc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ impl CodegenCx<'ll, '_> {
1919
let col_used = if self.sess().target.target.options.is_like_msvc {
2020
UNKNOWN_COLUMN_NUMBER
2121
} else {
22-
loc.col.to_usize() as c_uint
22+
// Loc column is 0-based while debug one is 1-based.
23+
loc.col.to_usize() as c_uint + 1
2324
};
2425

2526
unsafe {

src/test/codegen/debug-column.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Verify that emitted debuginfo column nubmers are 1-based. Regression test for issue #65437.
2+
//
3+
// ignore-windows
4+
// compile-flags: -C debuginfo=2
5+
6+
fn main() {
7+
unsafe {
8+
// CHECK: call void @giraffe(), !dbg [[DBG:!.*]]
9+
// CHECK: [[DBG]] = !DILocation(line: 10, column: 9
10+
giraffe();
11+
}
12+
}
13+
14+
extern {
15+
fn giraffe();
16+
}

0 commit comments

Comments
 (0)