debuginfo: Refactor debuginfo generation for types -- Address outstanding FIXMEs.

This commit is contained in:
Michael Woerister 2022-03-03 14:43:17 +01:00
parent 07a1194edf
commit 19707b0ff2
3 changed files with 19 additions and 20 deletions

View File

@ -1120,11 +1120,7 @@ fn build_closure_env_di_node<'ll, 'tcx>(
), ),
// Fields: // Fields:
|cx, owner| build_upvar_field_di_nodes(cx, closure_env_type, owner), |cx, owner| build_upvar_field_di_nodes(cx, closure_env_type, owner),
// Generics: NO_GENERICS,
|_| {
// FIXME(mw): Should we specify generic parameters for closures?
smallvec![]
},
) )
} }
@ -1178,10 +1174,6 @@ fn build_union_type_di_node<'ll, 'tcx>(
) )
} }
//=-----------------------------------------------------------------------------
// Enums
//=-----------------------------------------------------------------------------
// FIXME(eddyb) maybe precompute this? Right now it's computed once // FIXME(eddyb) maybe precompute this? Right now it's computed once
// per generator monomorphization, but it doesn't depend on substs. // per generator monomorphization, but it doesn't depend on substs.
fn generator_layout_and_saved_local_names<'tcx>( fn generator_layout_and_saved_local_names<'tcx>(

View File

@ -110,8 +110,6 @@ fn tag_base_type<'ll, 'tcx>(
_ => false, _ => false,
}); });
// FIXME(mw): Why are niche and regular tags treated differently? Because we want to preserve
// the sign?
match enum_type_and_layout.layout.variants() { match enum_type_and_layout.layout.variants() {
// A single-variant enum has no discriminant. // A single-variant enum has no discriminant.
Variants::Single { .. } => { Variants::Single { .. } => {
@ -119,6 +117,7 @@ fn tag_base_type<'ll, 'tcx>(
} }
Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, .. } => { Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, .. } => {
// Niche tags are always normalized to unsized integers of the correct size.
match tag.value { match tag.value {
Primitive::Int(t, _) => t, Primitive::Int(t, _) => t,
Primitive::F32 => Integer::I32, Primitive::F32 => Integer::I32,
@ -134,12 +133,19 @@ fn tag_base_type<'ll, 'tcx>(
} }
Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, .. } => { Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, .. } => {
// Direct tags preserve the sign.
tag.value.to_ty(cx.tcx) tag.value.to_ty(cx.tcx)
} }
} }
} }
/// This is a helper function. FIXME: elaborate docs. /// Build a DW_TAG_enumeration_type debuginfo node, with the given base type and variants.
/// This is a helper function and does not register anything in the type map by itself.
///
/// `variants` is an iterator of (discr-value, variant-name).
///
// NOTE: Handling of discriminant values is somewhat inconsistent. They can appear as u128,
// u64, and i64. Here everything gets mapped to i64 because that's what LLVM's API expects.
fn build_enumeration_type_di_node<'ll, 'tcx>( fn build_enumeration_type_di_node<'ll, 'tcx>(
cx: &CodegenCx<'ll, 'tcx>, cx: &CodegenCx<'ll, 'tcx>,
type_name: &str, type_name: &str,
@ -147,13 +153,14 @@ fn build_enumeration_type_di_node<'ll, 'tcx>(
variants: &mut dyn Iterator<Item = (Discr<'tcx>, Cow<'tcx, str>)>, variants: &mut dyn Iterator<Item = (Discr<'tcx>, Cow<'tcx, str>)>,
containing_scope: &'ll DIType, containing_scope: &'ll DIType,
) -> &'ll DIType { ) -> &'ll DIType {
let is_unsigned = match base_type.kind() {
ty::Int(_) => false,
ty::Uint(_) => true,
_ => bug!("build_enumeration_type_di_node() called with non-integer tag type."),
};
let enumerator_di_nodes: SmallVec<Option<&'ll DIType>> = variants let enumerator_di_nodes: SmallVec<Option<&'ll DIType>> = variants
.map(|(discr, variant_name)| { .map(|(discr, variant_name)| {
let is_unsigned = match discr.ty.kind() {
ty::Int(_) => false,
ty::Uint(_) => true,
_ => bug!("build_enumeration_type_di_node() called with non-integer tag type."),
};
unsafe { unsafe {
Some(llvm::LLVMRustDIBuilderCreateEnumerator( Some(llvm::LLVMRustDIBuilderCreateEnumerator(
DIB(cx), DIB(cx),

View File

@ -410,9 +410,9 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
variant_member_info.variant_name.len(), variant_member_info.variant_name.len(),
file_di_node, file_di_node,
line_number, line_number,
enum_type_and_layout.size.bits(), // FIXME: Unused? enum_type_and_layout.size.bits(),
enum_type_and_layout.align.abi.bits() as u32, // FIXME: Unused? enum_type_and_layout.align.abi.bits() as u32,
Size::ZERO.bits(), // FIXME: Unused? Size::ZERO.bits(),
discr_value.map(|v| cx.const_u64(v)), discr_value.map(|v| cx.const_u64(v)),
DIFlags::FlagZero, DIFlags::FlagZero,
variant_member_info.variant_struct_type_di_node, variant_member_info.variant_struct_type_di_node,