Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 78caecf

Browse files
committed
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.
1 parent a604303 commit 78caecf

File tree

1 file changed

+7
-2
lines changed
  • compiler/rustc_codegen_llvm/src/debuginfo

1 file changed

+7
-2
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_session::config::{self, DebugInfo};
2020
use rustc_session::Session;
2121
use rustc_span::symbol::Symbol;
2222
use rustc_span::{
23-
BytePos, Pos, SourceFile, SourceFileAndLine, SourceFileHash, Span, StableSourceFileId,
23+
BytePos, Pos, SourceFile, SourceFileAndLine, SourceFileHash, Span, StableSourceFileId, DUMMY_SP,
2424
};
2525
use rustc_target::abi::Size;
2626
use smallvec::SmallVec;
@@ -570,7 +570,12 @@ 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+
let (line, col) = if span == DUMMY_SP && !self.sess().target.is_like_msvc {
574+
(0, 0)
575+
} else {
576+
let DebugLoc { line, col, .. } = self.lookup_debug_loc(span.lo());
577+
(line, col)
578+
};
574579

575580
unsafe { llvm::LLVMRustDIBuilderCreateDebugLocation(line, col, scope, inlined_at) }
576581
}

0 commit comments

Comments
 (0)