diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index 46f186191e3ab..c1a7bb5087824 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -51,7 +51,6 @@ mod utils; pub use self::create_scope_map::compute_mir_scopes; pub use self::metadata::create_global_var_metadata; pub use self::metadata::extend_scope_to_file; -pub use self::source_loc::set_source_location; #[allow(non_upper_case_globals)] const DW_TAG_auto_variable: c_uint = 0x100; @@ -193,13 +192,14 @@ impl DebugInfoBuilderMethods for Builder<'a, 'll, 'tcx> { } } - fn set_source_location( - &mut self, - debug_context: &mut FunctionDebugContext<&'ll DIScope>, - scope: &'ll DIScope, - span: Span, - ) { - set_source_location(debug_context, &self, scope, span) + fn set_source_location(&mut self, scope: &'ll DIScope, span: Span) { + debug!("set_source_location: {}", self.sess().source_map().span_to_string(span)); + + let dbg_loc = self.cx().create_debug_loc(scope, span); + + unsafe { + llvm::LLVMSetCurrentDebugLocation(self.llbuilder, dbg_loc); + } } fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) { gdb::insert_reference_to_gdb_debug_scripts_section_global(self) @@ -333,7 +333,6 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { }; let mut fn_debug_context = FunctionDebugContext { scopes: IndexVec::from_elem(null_scope, &mir.source_scopes), - source_locations_enabled: false, defining_crate: def_id.krate, }; diff --git a/src/librustc_codegen_llvm/debuginfo/source_loc.rs b/src/librustc_codegen_llvm/debuginfo/source_loc.rs index 78dc1ac250e6e..1f871c7d207a4 100644 --- a/src/librustc_codegen_llvm/debuginfo/source_loc.rs +++ b/src/librustc_codegen_llvm/debuginfo/source_loc.rs @@ -1,38 +1,14 @@ use super::metadata::UNKNOWN_COLUMN_NUMBER; use super::utils::{debug_context, span_start}; -use rustc_codegen_ssa::mir::debuginfo::FunctionDebugContext; -use crate::builder::Builder; use crate::common::CodegenCx; use crate::llvm::debuginfo::DIScope; use crate::llvm::{self, Value}; -use log::debug; use rustc_codegen_ssa::traits::*; use libc::c_uint; use rustc_span::{Pos, Span}; -/// Sets the current debug location at the beginning of the span. -/// -/// Maps to a call to llvm::LLVMSetCurrentDebugLocation(...). -pub fn set_source_location( - debug_context: &FunctionDebugContext, - bx: &Builder<'_, 'll, '_>, - scope: &'ll DIScope, - span: Span, -) { - let dbg_loc = if debug_context.source_locations_enabled { - debug!("set_source_location: {}", bx.sess().source_map().span_to_string(span)); - Some(bx.cx().create_debug_loc(scope, span)) - } else { - None - }; - - unsafe { - llvm::LLVMSetCurrentDebugLocation(bx.llbuilder, dbg_loc); - } -} - impl CodegenCx<'ll, '_> { pub fn create_debug_loc(&self, scope: &'ll DIScope, span: Span) -> &'ll Value { let loc = span_start(self, span); diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index 87a6449a8ea7a..146b7d3d76c5e 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -909,7 +909,7 @@ extern "C" { pub fn LLVMDisposeBuilder(Builder: &'a mut Builder<'a>); // Metadata - pub fn LLVMSetCurrentDebugLocation(Builder: &Builder<'a>, L: Option<&'a Value>); + pub fn LLVMSetCurrentDebugLocation(Builder: &Builder<'a>, L: &'a Value); // Terminators pub fn LLVMBuildRetVoid(B: &Builder<'a>) -> &'a Value; diff --git a/src/librustc_codegen_ssa/mir/debuginfo.rs b/src/librustc_codegen_ssa/mir/debuginfo.rs index 362bb18abb829..976a656a29b19 100644 --- a/src/librustc_codegen_ssa/mir/debuginfo.rs +++ b/src/librustc_codegen_ssa/mir/debuginfo.rs @@ -14,7 +14,6 @@ use super::{FunctionCx, LocalRef}; pub struct FunctionDebugContext { pub scopes: IndexVec>, - pub source_locations_enabled: bool, pub defining_crate: CrateNum, } @@ -53,11 +52,10 @@ impl DebugScope { } impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { - pub fn set_debug_loc(&mut self, bx: &mut Bx, source_info: mir::SourceInfo) { + pub fn set_debug_loc(&self, bx: &mut Bx, source_info: mir::SourceInfo) { let (scope, span) = self.debug_loc(source_info); - if let Some(debug_context) = &mut self.debug_context { - // FIXME(eddyb) get rid of this unwrap somehow. - bx.set_source_location(debug_context, scope.unwrap(), span); + if let Some(scope) = scope { + bx.set_source_location(scope, span); } } diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index 8a6284479c722..64ead19b35869 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -230,13 +230,6 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( bx.br(fx.blocks[mir::START_BLOCK]); } - // Up until here, IR instructions for this function have explicitly not been annotated with - // source code location, so we don't step into call setup code. From here on, source location - // emitting should be enabled. - if let Some(debug_context) = &mut fx.debug_context { - debug_context.source_locations_enabled = true; - } - let rpo = traversal::reverse_postorder(&mir_body); let mut visited = BitSet::new_empty(mir_body.basic_blocks().len()); diff --git a/src/librustc_codegen_ssa/traits/debuginfo.rs b/src/librustc_codegen_ssa/traits/debuginfo.rs index f1ba6d4daa809..3688ae51b3918 100644 --- a/src/librustc_codegen_ssa/traits/debuginfo.rs +++ b/src/librustc_codegen_ssa/traits/debuginfo.rs @@ -57,12 +57,7 @@ pub trait DebugInfoBuilderMethods: BackendTypes { indirect_offsets: &[Size], span: Span, ); - fn set_source_location( - &mut self, - debug_context: &mut FunctionDebugContext, - scope: Self::DIScope, - span: Span, - ); + fn set_source_location(&mut self, scope: Self::DIScope, span: Span); fn insert_reference_to_gdb_debug_scripts_section_global(&mut self); fn set_var_name(&mut self, value: Self::Value, name: &str); }