rustc_codegen_llvm: use safe references for Metadata and DI*.
This commit is contained in:
parent
6d0d82ce10
commit
eed48f560f
12 changed files with 410 additions and 376 deletions
|
@ -39,7 +39,6 @@ use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet};
|
|||
use libc::c_uint;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::ffi::CString;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
use syntax_pos::{self, Span, Pos};
|
||||
use syntax::ast;
|
||||
|
@ -71,15 +70,15 @@ pub struct CrateDebugContext<'a, 'tcx> {
|
|||
llcontext: &'a llvm::Context,
|
||||
llmod: &'a llvm::Module,
|
||||
builder: &'a DIBuilder,
|
||||
created_files: RefCell<FxHashMap<(Symbol, Symbol), DIFile>>,
|
||||
created_enum_disr_types: RefCell<FxHashMap<(DefId, layout::Primitive), DIType>>,
|
||||
created_files: RefCell<FxHashMap<(Symbol, Symbol), &'a DIFile>>,
|
||||
created_enum_disr_types: RefCell<FxHashMap<(DefId, layout::Primitive), &'a DIType>>,
|
||||
|
||||
type_map: RefCell<TypeMap<'tcx>>,
|
||||
namespace_map: RefCell<DefIdMap<DIScope>>,
|
||||
type_map: RefCell<TypeMap<'a, 'tcx>>,
|
||||
namespace_map: RefCell<DefIdMap<&'a DIScope>>,
|
||||
|
||||
// This collection is used to assert that composite types (structs, enums,
|
||||
// ...) have their members only set once:
|
||||
composite_types_completed: RefCell<FxHashSet<DIType>>,
|
||||
composite_types_completed: RefCell<FxHashSet<&'a DIType>>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> CrateDebugContext<'a, 'tcx> {
|
||||
|
@ -101,14 +100,14 @@ impl<'a, 'tcx> CrateDebugContext<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum FunctionDebugContext {
|
||||
RegularContext(FunctionDebugContextData),
|
||||
pub enum FunctionDebugContext<'ll> {
|
||||
RegularContext(FunctionDebugContextData<'ll>),
|
||||
DebugInfoDisabled,
|
||||
FunctionWithoutDebugInfo,
|
||||
}
|
||||
|
||||
impl FunctionDebugContext {
|
||||
pub fn get_ref<'a>(&'a self, span: Span) -> &'a FunctionDebugContextData {
|
||||
impl FunctionDebugContext<'ll> {
|
||||
pub fn get_ref<'a>(&'a self, span: Span) -> &'a FunctionDebugContextData<'ll> {
|
||||
match *self {
|
||||
FunctionDebugContext::RegularContext(ref data) => data,
|
||||
FunctionDebugContext::DebugInfoDisabled => {
|
||||
|
@ -130,8 +129,8 @@ impl FunctionDebugContext {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct FunctionDebugContextData {
|
||||
fn_metadata: DISubprogram,
|
||||
pub struct FunctionDebugContextData<'ll> {
|
||||
fn_metadata: &'ll DISubprogram,
|
||||
source_locations_enabled: Cell<bool>,
|
||||
pub defining_crate: CrateNum,
|
||||
}
|
||||
|
@ -201,11 +200,13 @@ pub fn finalize(cx: &CodegenCx) {
|
|||
/// for debug info creation. The function may also return another variant of the
|
||||
/// FunctionDebugContext enum which indicates why no debuginfo should be created
|
||||
/// for the function.
|
||||
pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
sig: ty::FnSig<'tcx>,
|
||||
llfn: ValueRef,
|
||||
mir: &mir::Mir) -> FunctionDebugContext {
|
||||
pub fn create_function_debug_context(
|
||||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
sig: ty::FnSig<'tcx>,
|
||||
llfn: ValueRef,
|
||||
mir: &mir::Mir,
|
||||
) -> FunctionDebugContext<'ll> {
|
||||
if cx.sess().opts.debuginfo == NoDebugInfo {
|
||||
return FunctionDebugContext::DebugInfoDisabled;
|
||||
}
|
||||
|
@ -302,8 +303,10 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
|
||||
return FunctionDebugContext::RegularContext(fn_debug_context);
|
||||
|
||||
fn get_function_signature<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
||||
sig: ty::FnSig<'tcx>) -> DIArray {
|
||||
fn get_function_signature(
|
||||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
sig: ty::FnSig<'tcx>,
|
||||
) -> &'ll DIArray {
|
||||
if cx.sess().opts.debuginfo == LimitedDebugInfo {
|
||||
return create_DIArray(DIB(cx), &[]);
|
||||
}
|
||||
|
@ -313,7 +316,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
// Return type -- llvm::DIBuilder wants this at index 0
|
||||
signature.push(match sig.output().sty {
|
||||
ty::TyTuple(ref tys) if tys.is_empty() => None,
|
||||
_ => NonNull::new(type_metadata(cx, sig.output(), syntax_pos::DUMMY_SP))
|
||||
_ => Some(type_metadata(cx, sig.output(), syntax_pos::DUMMY_SP))
|
||||
});
|
||||
|
||||
let inputs = if sig.abi == Abi::RustCall {
|
||||
|
@ -342,11 +345,11 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
}
|
||||
_ => t
|
||||
};
|
||||
NonNull::new(type_metadata(cx, t, syntax_pos::DUMMY_SP))
|
||||
Some(type_metadata(cx, t, syntax_pos::DUMMY_SP))
|
||||
}));
|
||||
} else {
|
||||
signature.extend(inputs.iter().map(|t| {
|
||||
NonNull::new(type_metadata(cx, t, syntax_pos::DUMMY_SP))
|
||||
Some(type_metadata(cx, t, syntax_pos::DUMMY_SP))
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -354,7 +357,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
if let ty::TyTuple(args) = sig.inputs()[sig.inputs().len() - 1].sty {
|
||||
signature.extend(
|
||||
args.iter().map(|argument_type| {
|
||||
NonNull::new(type_metadata(cx, argument_type, syntax_pos::DUMMY_SP))
|
||||
Some(type_metadata(cx, argument_type, syntax_pos::DUMMY_SP))
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -363,13 +366,13 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
return create_DIArray(DIB(cx), &signature[..]);
|
||||
}
|
||||
|
||||
fn get_template_parameters<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
||||
generics: &ty::Generics,
|
||||
substs: &Substs<'tcx>,
|
||||
file_metadata: DIFile,
|
||||
name_to_append_suffix_to: &mut String)
|
||||
-> DIArray
|
||||
{
|
||||
fn get_template_parameters(
|
||||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
generics: &ty::Generics,
|
||||
substs: &Substs<'tcx>,
|
||||
file_metadata: &'ll DIFile,
|
||||
name_to_append_suffix_to: &mut String,
|
||||
) -> &'ll DIArray {
|
||||
if substs.types().next().is_none() {
|
||||
return create_DIArray(DIB(cx), &[]);
|
||||
}
|
||||
|
@ -399,14 +402,15 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
|
||||
let name = CString::new(name.as_str().as_bytes()).unwrap();
|
||||
Some(unsafe {
|
||||
NonNull::new(llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
|
||||
Some(llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
|
||||
DIB(cx),
|
||||
None,
|
||||
name.as_ptr(),
|
||||
actual_type_metadata,
|
||||
file_metadata,
|
||||
0,
|
||||
0))
|
||||
0,
|
||||
))
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
@ -429,9 +433,10 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
names
|
||||
}
|
||||
|
||||
fn get_containing_scope<'cx, 'tcx>(cx: &CodegenCx<'cx, 'tcx>,
|
||||
instance: Instance<'tcx>)
|
||||
-> DIScope {
|
||||
fn get_containing_scope(
|
||||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
) -> &'ll DIScope {
|
||||
// First, let's see if this is a method within an inherent impl. Because
|
||||
// if yes, we want to make the result subroutine DIE a child of the
|
||||
// subroutine's self-type.
|
||||
|
@ -473,10 +478,10 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
|
||||
pub fn declare_local(
|
||||
bx: &Builder<'a, 'll, 'tcx>,
|
||||
dbg_context: &FunctionDebugContext,
|
||||
dbg_context: &FunctionDebugContext<'ll>,
|
||||
variable_name: ast::Name,
|
||||
variable_type: Ty<'tcx>,
|
||||
scope_metadata: DIScope,
|
||||
scope_metadata: &'ll DIScope,
|
||||
variable_access: VariableAccess,
|
||||
variable_kind: VariableKind,
|
||||
span: Span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue