Skip to content

Commit 5bb9f70

Browse files
authored
Unrolled build for rust-lang#128627
Rollup merge of rust-lang#128627 - khuey:DUMMY_SP-line-no, r=nnethercote Special case DUMMY_SP to emit line 0/column 0 locations on DWARF platforms. Line 0 has a special meaning in DWARF. From the version 5 spec: The compiler may emit the value 0 in cases where an instruction cannot be attributed to any source line. DUMMY_SP spans cannot be attributed to any line. However, because rustc internally stores line numbers starting at zero, lookup_debug_loc() adjusts every line number by one. Special casing DUMMY_SP to actually emit line 0 ensures rustc communicates to the debugger that there's no meaningful source code for this instruction, rather than telling the debugger to jump to line 1 randomly.
2 parents 982c6f8 + 4e9725c commit 5bb9f70

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,17 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
570570
inlined_at: Option<&'ll DILocation>,
571571
span: Span,
572572
) -> &'ll DILocation {
573-
let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());
573+
// When emitting debugging information, DWARF (i.e. everything but MSVC)
574+
// treats line 0 as a magic value meaning that the code could not be
575+
// attributed to any line in the source. That's also exactly what dummy
576+
// spans are. Make that equivalence here, rather than passing dummy spans
577+
// to lookup_debug_loc, which will return line 1 for them.
578+
let (line, col) = if span.is_dummy() && !self.sess().target.is_like_msvc {
579+
(0, 0)
580+
} else {
581+
let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());
582+
(line, col)
583+
};
574584

575585
unsafe { llvm::LLVMRustDIBuilderCreateDebugLocation(line, col, scope, inlined_at) }
576586
}

Diff for: tests/debuginfo/dummy_span.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//@ min-lldb-version: 310
2+
3+
//@ compile-flags:-g
4+
5+
// === GDB TESTS ===================================================================================
6+
7+
// gdb-command:run 7
8+
9+
// gdb-command:next
10+
// gdb-command:next
11+
// gdb-check:[...]#loc1[...]
12+
// gdb-command:next
13+
// gdb-check:[...]#loc2[...]
14+
15+
// === LLDB TESTS ==================================================================================
16+
17+
// lldb-command:run 7
18+
19+
// lldb-command:next
20+
// lldb-command:next
21+
// lldb-command:frame select
22+
// lldb-check:[...]#loc1[...]
23+
// lldb-command:next
24+
// lldb-command:frame select
25+
// lldb-check:[...]#loc2[...]
26+
27+
use std::env;
28+
use std::num::ParseIntError;
29+
30+
fn main() -> Result<(), ParseIntError> {
31+
let args = env::args();
32+
let number_str = args.skip(1).next().unwrap();
33+
let number = number_str.parse::<i32>()?;
34+
zzz(); // #break
35+
if number % 7 == 0 {
36+
// This generates code with a dummy span for
37+
// some reason. If that ever changes this
38+
// test will not test what it wants to test.
39+
return Ok(()); // #loc1
40+
}
41+
println!("{}", number);
42+
Ok(())
43+
} // #loc2
44+
45+
fn zzz() { () }

0 commit comments

Comments
 (0)