Skip to content

Commit 4f0cde1

Browse files
committed
Define return type for functions in debuginfo
1 parent 0634aed commit 4f0cde1

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/base.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1111
use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
1212

1313
use crate::constant::ConstantCx;
14-
use crate::debuginfo::FunctionDebugContext;
14+
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
1515
use crate::prelude::*;
1616
use crate::pretty_clif::CommentWriter;
1717

@@ -26,6 +26,7 @@ pub(crate) struct CodegenedFunction {
2626
pub(crate) fn codegen_fn<'tcx>(
2727
tcx: TyCtxt<'tcx>,
2828
cx: &mut crate::CodegenCx,
29+
type_dbg: &mut TypeDebugContext<'tcx>,
2930
cached_func: Function,
3031
module: &mut dyn Module,
3132
instance: Instance<'tcx>,
@@ -69,8 +70,10 @@ pub(crate) fn codegen_fn<'tcx>(
6970
let pointer_type = target_config.pointer_type();
7071
let clif_comments = crate::pretty_clif::CommentWriter::new(tcx, instance);
7172

73+
let fn_abi = RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty());
74+
7275
let func_debug_cx = if let Some(debug_context) = &mut cx.debug_context {
73-
Some(debug_context.define_function(tcx, instance, &symbol_name, mir.span))
76+
Some(debug_context.define_function(tcx, type_dbg, instance, fn_abi, &symbol_name, mir.span))
7477
} else {
7578
None
7679
};
@@ -87,7 +90,7 @@ pub(crate) fn codegen_fn<'tcx>(
8790
instance,
8891
symbol_name,
8992
mir,
90-
fn_abi: RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty()),
93+
fn_abi,
9194

9295
bcx,
9396
block_map,

src/debuginfo/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_hir::def::DefKind;
2020
use rustc_hir::def_id::DefIdMap;
2121
use rustc_session::Session;
2222
use rustc_span::{SourceFileHash, StableSourceFileId};
23+
use rustc_target::abi::call::FnAbi;
2324

2425
pub(crate) use self::emit::{DebugReloc, DebugRelocName};
2526
pub(crate) use self::types::TypeDebugContext;
@@ -188,7 +189,9 @@ impl DebugContext {
188189
pub(crate) fn define_function<'tcx>(
189190
&mut self,
190191
tcx: TyCtxt<'tcx>,
192+
type_dbg: &mut TypeDebugContext<'tcx>,
191193
instance: Instance<'tcx>,
194+
fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
192195
linkage_name: &str,
193196
function_span: Span,
194197
) -> FunctionDebugContext {
@@ -240,7 +243,14 @@ impl DebugContext {
240243
entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id)));
241244
entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(line));
242245

246+
if !fn_abi.ret.is_ignore() {
247+
let return_dw_ty = self.debug_type(tcx, type_dbg, fn_abi.ret.layout.ty);
248+
let entry = self.dwarf.unit.get_mut(entry_id);
249+
entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(return_dw_ty));
250+
}
251+
243252
if tcx.is_reachable_non_generic(instance.def_id()) {
253+
let entry = self.dwarf.unit.get_mut(entry_id);
244254
entry.set(gimli::DW_AT_external, AttributeValue::FlagPresent);
245255
}
246256

src/driver/aot.rs

+1
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ fn module_codegen(
470470
let codegened_function = crate::base::codegen_fn(
471471
tcx,
472472
&mut cx,
473+
&mut type_dbg,
473474
Function::new(),
474475
&mut module,
475476
inst,

src/driver/jit.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_middle::mir::mono::MonoItem;
1212
use rustc_session::Session;
1313
use rustc_span::Symbol;
1414

15+
use crate::debuginfo::TypeDebugContext;
1516
use crate::{prelude::*, BackendConfig};
1617
use crate::{CodegenCx, CodegenMode};
1718

@@ -229,7 +230,14 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
229230
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
230231

231232
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
232-
let codegened_func = crate::base::codegen_fn(tcx, cx, cached_func, module, instance);
233+
let codegened_func = crate::base::codegen_fn(
234+
tcx,
235+
cx,
236+
&mut TypeDebugContext::default(),
237+
cached_func,
238+
module,
239+
instance,
240+
);
233241

234242
crate::base::compile_fn(cx, cached_context, module, codegened_func);
235243
});

0 commit comments

Comments
 (0)