From 19707b0ff2c0beb80f77eaa7274f4588a506309d Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 3 Mar 2022 14:43:17 +0100 Subject: debuginfo: Refactor debuginfo generation for types -- Address outstanding FIXMEs. --- .../src/debuginfo/metadata/enums/mod.rs | 23 ++++++++++++++-------- .../src/debuginfo/metadata/enums/native.rs | 6 +++--- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'compiler/rustc_codegen_llvm/src/debuginfo/metadata') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs index e41f11b34c8..19f0ce54250 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -110,8 +110,6 @@ fn tag_base_type<'ll, 'tcx>( _ => 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() { // A single-variant enum has no discriminant. Variants::Single { .. } => { @@ -119,6 +117,7 @@ fn tag_base_type<'ll, 'tcx>( } Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, .. } => { + // Niche tags are always normalized to unsized integers of the correct size. match tag.value { Primitive::Int(t, _) => t, Primitive::F32 => Integer::I32, @@ -134,12 +133,19 @@ fn tag_base_type<'ll, 'tcx>( } Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, .. } => { + // Direct tags preserve the sign. 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>( cx: &CodegenCx<'ll, 'tcx>, type_name: &str, @@ -147,13 +153,14 @@ fn build_enumeration_type_di_node<'ll, 'tcx>( variants: &mut dyn Iterator, Cow<'tcx, str>)>, containing_scope: &'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> = variants .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 { Some(llvm::LLVMRustDIBuilderCreateEnumerator( DIB(cx), diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs index 12b8cfb4812..f1935e0ec31 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -410,9 +410,9 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>( variant_member_info.variant_name.len(), file_di_node, line_number, - enum_type_and_layout.size.bits(), // FIXME: Unused? - enum_type_and_layout.align.abi.bits() as u32, // FIXME: Unused? - Size::ZERO.bits(), // FIXME: Unused? + enum_type_and_layout.size.bits(), + enum_type_and_layout.align.abi.bits() as u32, + Size::ZERO.bits(), discr_value.map(|v| cx.const_u64(v)), DIFlags::FlagZero, variant_member_info.variant_struct_type_di_node, -- cgit 1.4.1-3-g733a5