about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-03-27 20:36:49 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-03-27 20:36:49 +0000
commit4f0cde1e51dbfb20a2260a0fc83a5c1359b4dc9d (patch)
treeb471cfd0a22d22d688b2a21d2796a04d884d385a
parent0634aedbb7a1fba46a7991527b9d5c4517fb6924 (diff)
downloadrust-4f0cde1e51dbfb20a2260a0fc83a5c1359b4dc9d.tar.gz
rust-4f0cde1e51dbfb20a2260a0fc83a5c1359b4dc9d.zip
Define return type for functions in debuginfo
-rw-r--r--src/base.rs9
-rw-r--r--src/debuginfo/mod.rs10
-rw-r--r--src/driver/aot.rs1
-rw-r--r--src/driver/jit.rs10
4 files changed, 26 insertions, 4 deletions
diff --git a/src/base.rs b/src/base.rs
index 049023f1560..b4ea4e10a3d 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -11,7 +11,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
 use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
 
 use crate::constant::ConstantCx;
-use crate::debuginfo::FunctionDebugContext;
+use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
 use crate::prelude::*;
 use crate::pretty_clif::CommentWriter;
 
@@ -26,6 +26,7 @@ pub(crate) struct CodegenedFunction {
 pub(crate) fn codegen_fn<'tcx>(
     tcx: TyCtxt<'tcx>,
     cx: &mut crate::CodegenCx,
+    type_dbg: &mut TypeDebugContext<'tcx>,
     cached_func: Function,
     module: &mut dyn Module,
     instance: Instance<'tcx>,
@@ -69,8 +70,10 @@ pub(crate) fn codegen_fn<'tcx>(
     let pointer_type = target_config.pointer_type();
     let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
 
+    let fn_abi = RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty());
+
     let func_debug_cx = if let Some(debug_context) = &mut cx.debug_context {
-        Some(debug_context.define_function(tcx, instance, &symbol_name, mir.span))
+        Some(debug_context.define_function(tcx, type_dbg, instance, fn_abi, &symbol_name, mir.span))
     } else {
         None
     };
@@ -87,7 +90,7 @@ pub(crate) fn codegen_fn<'tcx>(
         instance,
         symbol_name,
         mir,
-        fn_abi: RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty()),
+        fn_abi,
 
         bcx,
         block_map,
diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs
index 2bab897dbcd..1bb0e590513 100644
--- a/src/debuginfo/mod.rs
+++ b/src/debuginfo/mod.rs
@@ -20,6 +20,7 @@ use rustc_hir::def::DefKind;
 use rustc_hir::def_id::DefIdMap;
 use rustc_session::Session;
 use rustc_span::{SourceFileHash, StableSourceFileId};
+use rustc_target::abi::call::FnAbi;
 
 pub(crate) use self::emit::{DebugReloc, DebugRelocName};
 pub(crate) use self::types::TypeDebugContext;
@@ -188,7 +189,9 @@ impl DebugContext {
     pub(crate) fn define_function<'tcx>(
         &mut self,
         tcx: TyCtxt<'tcx>,
+        type_dbg: &mut TypeDebugContext<'tcx>,
         instance: Instance<'tcx>,
+        fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
         linkage_name: &str,
         function_span: Span,
     ) -> FunctionDebugContext {
@@ -240,7 +243,14 @@ impl DebugContext {
         entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id)));
         entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(line));
 
+        if !fn_abi.ret.is_ignore() {
+            let return_dw_ty = self.debug_type(tcx, type_dbg, fn_abi.ret.layout.ty);
+            let entry = self.dwarf.unit.get_mut(entry_id);
+            entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(return_dw_ty));
+        }
+
         if tcx.is_reachable_non_generic(instance.def_id()) {
+            let entry = self.dwarf.unit.get_mut(entry_id);
             entry.set(gimli::DW_AT_external, AttributeValue::FlagPresent);
         }
 
diff --git a/src/driver/aot.rs b/src/driver/aot.rs
index e5caceab345..75268341a4f 100644
--- a/src/driver/aot.rs
+++ b/src/driver/aot.rs
@@ -470,6 +470,7 @@ fn module_codegen(
                         let codegened_function = crate::base::codegen_fn(
                             tcx,
                             &mut cx,
+                            &mut type_dbg,
                             Function::new(),
                             &mut module,
                             inst,
diff --git a/src/driver/jit.rs b/src/driver/jit.rs
index 6b2b946db02..6dbc3f19127 100644
--- a/src/driver/jit.rs
+++ b/src/driver/jit.rs
@@ -12,6 +12,7 @@ use rustc_middle::mir::mono::MonoItem;
 use rustc_session::Session;
 use rustc_span::Symbol;
 
+use crate::debuginfo::TypeDebugContext;
 use crate::{prelude::*, BackendConfig};
 use crate::{CodegenCx, CodegenMode};
 
@@ -229,7 +230,14 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
             crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
 
         let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
-        let codegened_func = crate::base::codegen_fn(tcx, cx, cached_func, module, instance);
+        let codegened_func = crate::base::codegen_fn(
+            tcx,
+            cx,
+            &mut TypeDebugContext::default(),
+            cached_func,
+            module,
+            instance,
+        );
 
         crate::base::compile_fn(cx, cached_context, module, codegened_func);
     });