Skip to content

Commit 1385fc4

Browse files
committed
rustc_codegen_llvm: remove InternalDebugLocation and simplify dbg_var_addr.
1 parent d6ccbf6 commit 1385fc4

File tree

5 files changed

+35
-73
lines changed

5 files changed

+35
-73
lines changed

src/librustc_codegen_llvm/debuginfo/mod.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_codegen_ssa::mir::debuginfo::VariableKind::*;
55

66
use self::metadata::{file_metadata, type_metadata, TypeMap};
77
use self::namespace::mangled_name_of_instance;
8-
use self::source_loc::InternalDebugLocation::{self, UnknownLocation};
98
use self::type_names::compute_debuginfo_type_name;
109
use self::utils::{create_DIArray, is_node_local_to_unit, span_start, DIB};
1110

@@ -38,7 +37,7 @@ use std::ffi::CString;
3837
use rustc::ty::layout::{self, HasTyCtxt, LayoutOf, Size};
3938
use rustc_codegen_ssa::traits::*;
4039
use rustc_span::symbol::Symbol;
41-
use rustc_span::{self, BytePos, Pos, Span};
40+
use rustc_span::{self, BytePos, Span};
4241
use smallvec::SmallVec;
4342
use syntax::ast;
4443

@@ -148,20 +147,18 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
148147
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
149148
fn dbg_var_addr(
150149
&mut self,
151-
dbg_context: &FunctionDebugContext<&'ll DIScope>,
152150
dbg_var: &'ll DIVariable,
153151
scope_metadata: &'ll DIScope,
154152
variable_alloca: Self::Value,
155153
direct_offset: Size,
156154
indirect_offsets: &[Size],
157155
span: Span,
158156
) {
159-
assert!(!dbg_context.source_locations_enabled);
160157
let cx = self.cx();
161158

162-
let loc = span_start(cx, span);
163-
164159
// Convert the direct and indirect offsets to address ops.
160+
// FIXME(eddyb) use `const`s instead of getting the values via FFI,
161+
// the values should match the ones in the DWARF standard anyway.
165162
let op_deref = || unsafe { llvm::LLVMRustDIBuilderCreateOpDeref() };
166163
let op_plus_uconst = || unsafe { llvm::LLVMRustDIBuilderCreateOpPlusUconst() };
167164
let mut addr_ops = SmallVec::<[_; 8]>::new();
@@ -178,28 +175,22 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> {
178175
}
179176
}
180177

181-
// FIXME(eddyb) maybe this information could be extracted from `var`,
178+
// FIXME(eddyb) maybe this information could be extracted from `dbg_var`,
182179
// to avoid having to pass it down in both places?
183-
source_loc::set_debug_location(
184-
self,
185-
InternalDebugLocation::new(scope_metadata, loc.line, loc.col.to_usize()),
186-
);
180+
// NB: `var` doesn't seem to know about the column, so that's a limitation.
181+
let dbg_loc = cx.create_debug_loc(scope_metadata, span);
187182
unsafe {
188-
let debug_loc = llvm::LLVMGetCurrentDebugLocation(self.llbuilder);
189183
// FIXME(eddyb) replace `llvm.dbg.declare` with `llvm.dbg.addr`.
190-
let instr = llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
184+
llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
191185
DIB(cx),
192186
variable_alloca,
193187
dbg_var,
194188
addr_ops.as_ptr(),
195189
addr_ops.len() as c_uint,
196-
debug_loc,
190+
dbg_loc,
197191
self.llbb(),
198192
);
199-
200-
llvm::LLVMSetInstDebugLocation(self.llbuilder, instr);
201193
}
202-
source_loc::set_debug_location(self, UnknownLocation);
203194
}
204195

205196
fn set_source_location(
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use self::InternalDebugLocation::*;
2-
31
use super::metadata::UNKNOWN_COLUMN_NUMBER;
42
use super::utils::{debug_context, span_start};
53
use rustc_codegen_ssa::mir::debuginfo::FunctionDebugContext;
64

75
use crate::builder::Builder;
8-
use crate::llvm;
6+
use crate::common::CodegenCx;
97
use crate::llvm::debuginfo::DIScope;
8+
use crate::llvm::{self, Value};
109
use log::debug;
1110
use rustc_codegen_ssa::traits::*;
1211

@@ -24,56 +23,37 @@ pub fn set_source_location<D>(
2423
) {
2524
let dbg_loc = if debug_context.source_locations_enabled {
2625
debug!("set_source_location: {}", bx.sess().source_map().span_to_string(span));
27-
let loc = span_start(bx.cx(), span);
28-
InternalDebugLocation::new(scope, loc.line, loc.col.to_usize())
26+
Some(bx.cx().create_debug_loc(scope, span))
2927
} else {
30-
UnknownLocation
28+
None
3129
};
32-
set_debug_location(bx, dbg_loc);
33-
}
3430

35-
#[derive(Copy, Clone, PartialEq)]
36-
pub enum InternalDebugLocation<'ll> {
37-
KnownLocation { scope: &'ll DIScope, line: usize, col: usize },
38-
UnknownLocation,
39-
}
40-
41-
impl InternalDebugLocation<'ll> {
42-
pub fn new(scope: &'ll DIScope, line: usize, col: usize) -> Self {
43-
KnownLocation { scope, line, col }
31+
unsafe {
32+
llvm::LLVMSetCurrentDebugLocation(bx.llbuilder, dbg_loc);
4433
}
4534
}
4635

47-
pub fn set_debug_location(bx: &Builder<'_, 'll, '_>, debug_location: InternalDebugLocation<'ll>) {
48-
let metadata_node = match debug_location {
49-
KnownLocation { scope, line, col } => {
50-
// For MSVC, set the column number to zero.
51-
// Otherwise, emit it. This mimics clang behaviour.
52-
// See discussion in https://github.com/rust-lang/rust/issues/42921
53-
let col_used = if bx.sess().target.target.options.is_like_msvc {
54-
UNKNOWN_COLUMN_NUMBER
55-
} else {
56-
col as c_uint
57-
};
58-
debug!("setting debug location to {} {}", line, col);
59-
60-
unsafe {
61-
Some(llvm::LLVMRustDIBuilderCreateDebugLocation(
62-
debug_context(bx.cx()).llcontext,
63-
line as c_uint,
64-
col_used,
65-
scope,
66-
None,
67-
))
68-
}
69-
}
70-
UnknownLocation => {
71-
debug!("clearing debug location ");
72-
None
36+
impl CodegenCx<'ll, '_> {
37+
pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value {
38+
let loc = span_start(self, span);
39+
40+
// For MSVC, set the column number to zero.
41+
// Otherwise, emit it. This mimics clang behaviour.
42+
// See discussion in https://github.com/rust-lang/rust/issues/42921
43+
let col_used = if self.sess().target.target.options.is_like_msvc {
44+
UNKNOWN_COLUMN_NUMBER
45+
} else {
46+
loc.col.to_usize() as c_uint
47+
};
48+
49+
unsafe {
50+
llvm::LLVMRustDIBuilderCreateDebugLocation(
51+
debug_context(self).llcontext,
52+
loc.line as c_uint,
53+
col_used,
54+
scope,
55+
None,
56+
)
7357
}
74-
};
75-
76-
unsafe {
77-
llvm::LLVMSetCurrentDebugLocation(bx.llbuilder, metadata_node);
7858
}
7959
}

src/librustc_codegen_llvm/llvm/ffi.rs

-2
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,6 @@ extern "C" {
910910

911911
// Metadata
912912
pub fn LLVMSetCurrentDebugLocation(Builder: &Builder<'a>, L: Option<&'a Value>);
913-
pub fn LLVMGetCurrentDebugLocation(Builder: &Builder<'a>) -> &'a Value;
914-
pub fn LLVMSetInstDebugLocation(Builder: &Builder<'a>, Inst: &'a Value);
915913

916914
// Terminators
917915
pub fn LLVMBuildRetVoid(B: &Builder<'a>) -> &'a Value;

src/librustc_codegen_ssa/mir/debuginfo.rs

-6
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
210210
return;
211211
}
212212

213-
let debug_context = match &self.debug_context {
214-
Some(debug_context) => debug_context,
215-
None => return,
216-
};
217-
218213
// FIXME(eddyb) add debuginfo for unsized places too.
219214
let base = match local_ref {
220215
LocalRef::Place(place) => place,
@@ -264,7 +259,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
264259
if let Some(scope) = scope {
265260
if let Some(dbg_var) = var.dbg_var {
266261
bx.dbg_var_addr(
267-
debug_context,
268262
dbg_var,
269263
scope,
270264
base.llval,

src/librustc_codegen_ssa/traits/debuginfo.rs

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub trait DebugInfoBuilderMethods: BackendTypes {
4949
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).
5050
fn dbg_var_addr(
5151
&mut self,
52-
dbg_context: &FunctionDebugContext<Self::DIScope>,
5352
dbg_var: Self::DIVariable,
5453
scope_metadata: Self::DIScope,
5554
variable_alloca: Self::Value,

0 commit comments

Comments
 (0)