Skip to content
Permalink
Browse files

rustc_codegen_llvm: rewrite debuginfo::get_function_signature to use …

…FnAbi.
  • Loading branch information
eddyb committed Oct 29, 2019
1 parent 902433b commit 8a8749b29780d18f57b81cf25f91b7960ccc64d3
Showing with 12 additions and 33 deletions.
  1. +12 −33 src/librustc_codegen_llvm/debuginfo/mod.rs
@@ -16,7 +16,7 @@ use rustc::hir::CodegenFnAttrFlags;
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
use rustc::ty::subst::{SubstsRef, GenericArgKind};

use crate::abi::{Abi, FnAbi};
use crate::abi::FnAbi;
use crate::common::CodegenCx;
use crate::builder::Builder;
use crate::value::Value;
@@ -308,13 +308,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let file_metadata = file_metadata(self, &loc.file.name, def_id.krate);

let function_type_metadata = unsafe {
// FIXME(eddyb) avoid this `Instance::fn_sig` call, by
// rewriting `get_function_signature` to use `fn_abi` instead.
let sig = self.tcx().normalize_erasing_late_bound_regions(
ty::ParamEnv::reveal_all(),
&instance.fn_sig(self.tcx()),
);
let fn_signature = get_function_signature(self, sig);
let fn_signature = get_function_signature(self, fn_abi);
llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(self), file_metadata, fn_signature)
};

@@ -396,28 +390,22 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {

return Some(fn_debug_context);

// FIXME(eddyb) rewrite this to be based on `FnAbi` instead of `FnSig`.
fn get_function_signature<'ll, 'tcx>(
cx: &CodegenCx<'ll, 'tcx>,
sig: ty::FnSig<'tcx>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
) -> &'ll DIArray {
if cx.sess().opts.debuginfo == DebugInfo::Limited {
return create_DIArray(DIB(cx), &[]);
}

let mut signature = Vec::with_capacity(sig.inputs().len() + 1);
let mut signature = Vec::with_capacity(fn_abi.args.len() + 1);

// Return type -- llvm::DIBuilder wants this at index 0
signature.push(match sig.output().kind {
ty::Tuple(ref tys) if tys.is_empty() => None,
_ => Some(type_metadata(cx, sig.output(), syntax_pos::DUMMY_SP))
});

let inputs = if sig.abi == Abi::RustCall {
&sig.inputs()[..sig.inputs().len() - 1]
signature.push(if fn_abi.ret.is_ignore() {
None
} else {
sig.inputs()
};
Some(type_metadata(cx, fn_abi.ret.layout.ty, syntax_pos::DUMMY_SP))
});

// Arguments types
if cx.sess().target.target.options.is_like_msvc {
@@ -431,7 +419,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
// and a function `fn bar(x: [(); 7])` as `fn bar(x: *const ())`.
// This transformed type is wrong, but these function types are
// already inaccurate due to ABI adjustments (see #42800).
signature.extend(inputs.iter().map(|&t| {
signature.extend(fn_abi.args.iter().map(|arg| {
let t = arg.layout.ty;
let t = match t.kind {
ty::Array(ct, _)
if (ct == cx.tcx.types.u8) || cx.layout_of(ct).is_zst() => {
@@ -442,21 +431,11 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
Some(type_metadata(cx, t, syntax_pos::DUMMY_SP))
}));
} else {
signature.extend(inputs.iter().map(|t| {
Some(type_metadata(cx, t, syntax_pos::DUMMY_SP))
signature.extend(fn_abi.args.iter().map(|arg| {
Some(type_metadata(cx, arg.layout.ty, syntax_pos::DUMMY_SP))
}));
}

if sig.abi == Abi::RustCall && !sig.inputs().is_empty() {
if let ty::Tuple(args) = sig.inputs()[sig.inputs().len() - 1].kind {
signature.extend(
args.iter().map(|argument_type| {
Some(type_metadata(cx, argument_type.expect_ty(), syntax_pos::DUMMY_SP))
})
);
}
}

create_DIArray(DIB(cx), &signature[..])
}

0 comments on commit 8a8749b

Please sign in to comment.
You can’t perform that action at this time.