Skip to content

Commit 9cc0a42

Browse files
committed
fix(debuginfo.rs): Cleanup of redundant code.
1. Revert to the original `lookup_debug_loc` of DebugLoc return type 2. Removed the commented code of scope lookup
1 parent 8c975d9 commit 9cc0a42

File tree

1 file changed

+35
-50
lines changed

1 file changed

+35
-50
lines changed

src/debuginfo.rs

+35-50
Original file line numberDiff line numberDiff line change
@@ -133,38 +133,7 @@ fn make_mir_scope<'gcc, 'tcx>(
133133

134134
let loc = cx.lookup_debug_loc(scope_data.span.lo());
135135

136-
/*
137-
// FIXME(?): Uncommented when the scope is supported.
138-
let file_metadata = file_metadata(cx, &loc.file);
139-
140-
let parent_dbg_scope = match scope_data.inlined {
141-
Some((callee, _)) => {
142-
// FIXME(eddyb) this would be `self.monomorphize(&callee)`
143-
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
144-
let callee = cx.tcx.instantiate_and_normalize_erasing_regions(
145-
instance.args,
146-
ty::ParamEnv::reveal_all(),
147-
ty::EarlyBinder::bind(callee),
148-
);
149-
debug_context.inlined_function_scopes.entry(callee).or_insert_with(|| {
150-
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
151-
cx.dbg_scope_fn(callee, callee_fn_abi, None)
152-
})
153-
}
154-
None => parent_scope.dbg_scope,
155-
};
156-
157-
let dbg_scope = unsafe {
158-
llvm::LLVMRustDIBuilderCreateLexicalBlock(
159-
DIB(cx),
160-
parent_dbg_scope,
161-
file_metadata,
162-
loc.line,
163-
loc.col,
164-
)
165-
};
166-
*/
167-
136+
// FIXME(tempdragon): Add the scope related code here if the scope is supported.
168137
let dbg_scope = ();
169138

170139
let inlined_at = scope_data.inlined.map(|(_, callsite_span)| {
@@ -180,36 +149,52 @@ fn make_mir_scope<'gcc, 'tcx>(
180149
debug_context.scopes[scope] = DebugScope {
181150
dbg_scope,
182151
inlined_at,
183-
file_start_pos: loc.0.start_pos,
184-
file_end_pos: loc.0.end_position(),
152+
file_start_pos: loc.file.start_pos,
153+
file_end_pos: loc.file.end_position(),
185154
};
186155
instantiated.insert(scope);
187156
}
188157

158+
/// A source code location used to generate debug information.
159+
// FIXME(eddyb) rename this to better indicate it's a duplicate of
160+
// `rustc_span::Loc` rather than `DILocation`, perhaps by making
161+
// `lookup_char_pos` return the right information instead.
162+
pub struct DebugLoc {
163+
/// Information about the original source file.
164+
pub file: Lrc<SourceFile>,
165+
/// The (1-based) line number.
166+
pub line: u32,
167+
/// The (1-based) column number.
168+
pub col: u32,
169+
}
170+
189171
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
190-
/// Look up the file, the 1-based indexing line number and column number.
191-
/// # Argument
192-
/// - `pos`: `BytePos`, the starting position of a piece of code
193-
/// # Source of Origin
194-
/// Copied from LLVM backend(with a return type from struct to tuple).
195-
/// No need to change since you may end up something like this.
196-
pub fn lookup_debug_loc(&self, pos: BytePos) -> (Lrc<SourceFile>, u32, u32) {
197-
match self.sess().source_map().lookup_line(pos) {
172+
/// Looks up debug source information about a `BytePos`.
173+
// FIXME(eddyb) rename this to better indicate it's a duplicate of
174+
// `lookup_char_pos` rather than `dbg_loc`, perhaps by making
175+
// `lookup_char_pos` return the right information instead.
176+
// Source of Origin: cg_llvm
177+
pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
178+
let (file, line, col) = match self.sess().source_map().lookup_line(pos) {
198179
Ok(SourceFileAndLine { sf: file, line }) => {
199180
let line_pos = file.lines()[line];
200181

201182
// Use 1-based indexing.
202183
let line = (line + 1) as u32;
203184
let col = (file.relative_position(pos) - line_pos).to_u32() + 1;
204-
(file,
205-
line,
206-
if ! self.sess().target.is_like_msvc {
207-
col } else {
208-
UNKNOWN_COLUMN_NUMBER
209-
}
210-
)
185+
186+
(file, line, col)
211187
}
212188
Err(file) => (file, UNKNOWN_LINE_NUMBER, UNKNOWN_COLUMN_NUMBER),
189+
};
190+
191+
// For MSVC, omit the column number.
192+
// Otherwise, emit it. This mimics clang behaviour.
193+
// See discussion in https://github.com/rust-lang/rust/issues/42921
194+
if self.sess().target.is_like_msvc {
195+
DebugLoc { file, line, col: UNKNOWN_COLUMN_NUMBER }
196+
} else {
197+
DebugLoc { file, line, col }
213198
}
214199
}
215200
}
@@ -293,7 +278,7 @@ impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
293278
span: Span,
294279
) -> Self::DILocation {
295280
let pos = span.lo();
296-
let (file, line, col) = self.lookup_debug_loc(pos);
281+
let DebugLoc{file, line, col} = self.lookup_debug_loc(pos);
297282
let loc = match &file.name {
298283
rustc_span::FileName::Real(name) => match name {
299284
rustc_span::RealFileName::LocalPath(name) => {

0 commit comments

Comments
 (0)