about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2020-02-10 22:30:51 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2020-10-21 04:43:57 +0300
commitfa2b381ec83556111a99750bcc7688521d7e8b0d (patch)
tree1eac177420f887852e79f82f457eeea49dfffdfd /compiler/rustc_codegen_llvm/src
parent9d57c417fc1bac25b0274a34ae581c2e18a9d44e (diff)
downloadrust-fa2b381ec83556111a99750bcc7688521d7e8b0d.tar.gz
rust-fa2b381ec83556111a99750bcc7688521d7e8b0d.zip
rustc_codegen_llvm: move DISubprogram creation to a dbg_scope_fn method.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/common.rs1
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs14
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/mod.rs57
-rw-r--r--compiler/rustc_codegen_llvm/src/llvm/ffi.rs2
4 files changed, 40 insertions, 34 deletions
diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs
index 0992410a728..2cd745ec420 100644
--- a/compiler/rustc_codegen_llvm/src/common.rs
+++ b/compiler/rustc_codegen_llvm/src/common.rs
@@ -80,6 +80,7 @@ impl Funclet<'ll> {
 
 impl BackendTypes for CodegenCx<'ll, 'tcx> {
     type Value = &'ll Value;
+    // FIXME(eddyb) replace this with a `Function` "subclass" of `Value`.
     type Function = &'ll Value;
 
     type BasicBlock = &'ll BasicBlock;
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
index 4c352c7ae0c..11855675ccf 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
@@ -5,7 +5,7 @@ use rustc_codegen_ssa::traits::*;
 
 use crate::common::CodegenCx;
 use crate::llvm;
-use crate::llvm::debuginfo::{DIScope, DISubprogram};
+use crate::llvm::debuginfo::DIScope;
 use rustc_middle::mir::{Body, SourceScope};
 use rustc_session::config::DebugInfo;
 
@@ -16,7 +16,7 @@ use rustc_index::vec::Idx;
 pub fn compute_mir_scopes(
     cx: &CodegenCx<'ll, '_>,
     mir: &Body<'_>,
-    fn_metadata: &'ll DISubprogram,
+    fn_dbg_scope: &'ll DIScope,
     debug_context: &mut FunctionDebugContext<&'ll DIScope>,
 ) {
     // Find all the scopes with variables defined in them.
@@ -37,16 +37,16 @@ pub fn compute_mir_scopes(
     // Instantiate all scopes.
     for idx in 0..mir.source_scopes.len() {
         let scope = SourceScope::new(idx);
-        make_mir_scope(cx, &mir, fn_metadata, &has_variables, debug_context, scope);
+        make_mir_scope(cx, &mir, fn_dbg_scope, &has_variables, debug_context, scope);
     }
 }
 
 fn make_mir_scope(
     cx: &CodegenCx<'ll, '_>,
     mir: &Body<'_>,
-    fn_metadata: &'ll DISubprogram,
+    fn_dbg_scope: &'ll DIScope,
     has_variables: &BitSet<SourceScope>,
-    debug_context: &mut FunctionDebugContext<&'ll DISubprogram>,
+    debug_context: &mut FunctionDebugContext<&'ll DIScope>,
     scope: SourceScope,
 ) {
     if debug_context.scopes[scope].is_valid() {
@@ -55,13 +55,13 @@ fn make_mir_scope(
 
     let scope_data = &mir.source_scopes[scope];
     let parent_scope = if let Some(parent) = scope_data.parent_scope {
-        make_mir_scope(cx, mir, fn_metadata, has_variables, debug_context, parent);
+        make_mir_scope(cx, mir, fn_dbg_scope, has_variables, debug_context, parent);
         debug_context.scopes[parent]
     } else {
         // The root is the function itself.
         let loc = cx.lookup_debug_loc(mir.span.lo());
         debug_context.scopes[scope] = DebugScope {
-            scope_metadata: Some(fn_metadata),
+            scope_metadata: Some(fn_dbg_scope),
             file_start_pos: loc.file.start_pos,
             file_end_pos: loc.file.end_pos,
         };
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
index 32752fa61ba..3f47c62ccae 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
@@ -235,16 +235,36 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
             return None;
         }
 
-        let span = mir.span;
+        // Initialize fn debug context (including scopes).
+        // FIXME(eddyb) figure out a way to not need `Option` for `scope_metadata`.
+        let empty_scope = DebugScope {
+            scope_metadata: None,
+            file_start_pos: BytePos(0),
+            file_end_pos: BytePos(0),
+        };
+        let mut fn_debug_context =
+            FunctionDebugContext { scopes: IndexVec::from_elem(empty_scope, &mir.source_scopes) };
 
-        // This can be the case for functions inlined from another crate
-        if span.is_dummy() {
-            // FIXME(simulacrum): Probably can't happen; remove.
-            return None;
-        }
+        // Fill in all the scopes, with the information from the MIR body.
+        compute_mir_scopes(
+            self,
+            mir,
+            self.dbg_scope_fn(instance, fn_abi, Some(llfn)),
+            &mut fn_debug_context,
+        );
+
+        Some(fn_debug_context)
+    }
 
+    fn dbg_scope_fn(
+        &self,
+        instance: Instance<'tcx>,
+        fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
+        maybe_definition_llfn: Option<&'ll Value>,
+    ) -> &'ll DIScope {
         let def_id = instance.def_id();
         let containing_scope = get_containing_scope(self, instance);
+        let span = self.tcx.def_span(def_id);
         let loc = self.lookup_debug_loc(span.lo());
         let file_metadata = file_metadata(self, &loc.file);
 
@@ -291,8 +311,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
             }
         }
 
-        let fn_metadata = unsafe {
-            llvm::LLVMRustDIBuilderCreateFunction(
+        unsafe {
+            return llvm::LLVMRustDIBuilderCreateFunction(
                 DIB(self),
                 containing_scope,
                 name.as_ptr().cast(),
@@ -305,26 +325,11 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
                 scope_line.unwrap_or(UNKNOWN_LINE_NUMBER),
                 flags,
                 spflags,
-                llfn,
+                maybe_definition_llfn,
                 template_parameters,
                 None,
-            )
-        };
-
-        // Initialize fn debug context (including scopes).
-        // FIXME(eddyb) figure out a way to not need `Option` for `scope_metadata`.
-        let null_scope = DebugScope {
-            scope_metadata: None,
-            file_start_pos: BytePos(0),
-            file_end_pos: BytePos(0),
-        };
-        let mut fn_debug_context =
-            FunctionDebugContext { scopes: IndexVec::from_elem(null_scope, &mir.source_scopes) };
-
-        // Fill in all the scopes, with the information from the MIR body.
-        compute_mir_scopes(self, mir, fn_metadata, &mut fn_debug_context);
-
-        return Some(fn_debug_context);
+            );
+        }
 
         fn get_function_signature<'ll, 'tcx>(
             cx: &CodegenCx<'ll, 'tcx>,
diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
index 4c1fee0106a..8305f654e03 100644
--- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
@@ -1854,7 +1854,7 @@ extern "C" {
         ScopeLine: c_uint,
         Flags: DIFlags,
         SPFlags: DISPFlags,
-        Fn: &'a Value,
+        MaybeFn: Option<&'a Value>,
         TParam: &'a DIArray,
         Decl: Option<&'a DIDescriptor>,
     ) -> &'a DISubprogram;