From 2f00b6affda7b25cb2721422d7adad39154ce9d1 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Thu, 10 Nov 2022 12:12:02 -0500 Subject: [PATCH 01/25] Require `type_map::stub` callers to supply file information This change attaches file information (`DIFile` reference and line number) to struct debug info nodes. Before: ``` ; foo.ll ... !5 = !DIFile(filename: "", directory: "") ... !16 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyType", scope: !2, file: !5, size: 32, align: 32, elements: !17, templateParams: !19, identifier: "4cb373851db92e732c4cb5651b886dd0") ... ``` After: ``` ; foo.ll ... !3 = !DIFile(filename: "foo.rs", directory: "/home/matt/src/rust98678", checksumkind: CSK_SHA1, checksum: "bcb9f08512c8f3b8181ef4726012bc6807bc9be4") ... !16 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyType", scope: !2, file: !3, line: 3, size: 32, align: 32, elements: !17, templateParams: !19, identifier: "9e5968c7af39c148acb253912b7f409f") ... ``` Fixes #98678 --- .../src/debuginfo/metadata.rs | 25 +++++++++++++++++++ .../src/debuginfo/metadata/enums/cpp_like.rs | 6 +++++ .../src/debuginfo/metadata/enums/mod.rs | 10 +++++++- .../src/debuginfo/metadata/enums/native.rs | 4 +++ .../src/debuginfo/metadata/type_map.rs | 12 +++++---- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 151923a3bd28..6b5f53e40bd5 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -204,6 +204,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &ptr_type_debuginfo_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, cx.size_and_align_of(ptr_type), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -371,6 +373,8 @@ fn build_dyn_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, cx.size_and_align_of(dyn_type), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -841,6 +845,8 @@ fn build_foreign_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &compute_debuginfo_type_name(cx.tcx, t, false), + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, cx.size_and_align_of(t), Some(get_namespace_for_item(cx, def_id)), DIFlags::FlagZero, @@ -1044,6 +1050,15 @@ fn build_struct_type_di_node<'ll, 'tcx>( let struct_type_and_layout = cx.layout_of(struct_type); let variant_def = adt_def.non_enum_variant(); + let tcx = cx.tcx; + let struct_span = tcx.def_span(adt_def.did()); + let (file_metadata, line_number) = if !struct_span.is_dummy() { + let loc = cx.lookup_debug_loc(struct_span.lo()); + (file_metadata(cx, &loc.file), loc.line) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; + type_map::build_type_with_children( cx, type_map::stub( @@ -1051,6 +1066,8 @@ fn build_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &compute_debuginfo_type_name(cx.tcx, struct_type, false), + file_metadata, + line_number, size_and_align_of(struct_type_and_layout), Some(containing_scope), visibility_di_flags(cx, adt_def.did(), adt_def.did()), @@ -1154,6 +1171,8 @@ fn build_tuple_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, size_and_align_of(tuple_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -1200,6 +1219,8 @@ fn build_closure_env_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, cx.size_and_align_of(closure_env_type), Some(containing_scope), DIFlags::FlagZero, @@ -1231,6 +1252,8 @@ fn build_union_type_di_node<'ll, 'tcx>( Stub::Union, unique_type_id, &type_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, size_and_align_of(union_ty_and_layout), Some(containing_scope), DIFlags::FlagZero, @@ -1423,6 +1446,8 @@ fn build_vtable_type_di_node<'ll, 'tcx>( Stub::VTableTy { vtable_holder }, unique_type_id, &vtable_type_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, (size, pointer_align), NO_SCOPE_METADATA, DIFlags::FlagArtificial, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 100b046cee21..a33347aa2832 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -199,6 +199,8 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &enum_type_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, cx.size_and_align_of(enum_type), NO_SCOPE_METADATA, visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()), @@ -274,6 +276,8 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &coroutine_type_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, size_and_align_of(coroutine_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -481,6 +485,8 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( variant_index, ), &variant_struct_wrapper_type_name(variant_index), + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_or_coroutine_type_and_layout), Some(enum_or_coroutine_type_di_node), 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 b3d4a6642a16..4402f2894545 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -204,6 +204,8 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( variant_index, ), variant_def.name.as_str(), + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_type_and_layout), Some(enum_type_di_node), @@ -286,6 +288,8 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &variant_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, size_and_align_of(coroutine_type_and_layout), Some(coroutine_type_di_node), DIFlags::FlagZero, @@ -351,7 +355,11 @@ enum DiscrResult { impl DiscrResult { fn opt_single_val(&self) -> Option { - if let Self::Value(d) = *self { Some(d) } else { None } + if let Self::Value(d) = *self { + Some(d) + } else { + None + } } } 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 d4006691d377..07c3784efe73 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -62,6 +62,8 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &enum_type_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, size_and_align_of(enum_type_and_layout), Some(containing_scope), visibility_flags, @@ -141,6 +143,8 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &coroutine_type_name, + unknown_file_metadata(cx), + UNKNOWN_LINE_NUMBER, size_and_align_of(coroutine_type_and_layout), Some(containing_scope), DIFlags::FlagZero, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs index 5120b63d173b..f8f8cf914bae 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -11,7 +11,7 @@ use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; use super::{SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata}; use crate::common::{AsCCharPtr, CodegenCx}; use crate::debuginfo::utils::{DIB, create_DIArray, debug_context}; -use crate::llvm::debuginfo::{DIFlags, DIScope, DIType}; +use crate::llvm::debuginfo::{DIFile, DIFlags, DIScope, DIType}; use crate::llvm::{self}; mod private { @@ -174,6 +174,8 @@ pub(super) fn stub<'ll, 'tcx>( kind: Stub<'ll>, unique_type_id: UniqueTypeId<'tcx>, name: &str, + file_metadata: &'ll DIFile, + line_number: u32, (size, align): (Size, Align), containing_scope: Option<&'ll DIScope>, flags: DIFlags, @@ -193,8 +195,8 @@ pub(super) fn stub<'ll, 'tcx>( containing_scope, name.as_c_char_ptr(), name.len(), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + file_metadata, + line_number, size.bits(), align.bits() as u32, flags, @@ -213,8 +215,8 @@ pub(super) fn stub<'ll, 'tcx>( containing_scope, name.as_c_char_ptr(), name.len(), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + file_metadata, + line_number, size.bits(), align.bits() as u32, flags, From 5b23c38dd56b2695c5af9b801ad14f795d138b1c Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Wed, 16 Nov 2022 14:50:31 -0500 Subject: [PATCH 02/25] Add codegen test to validate IR for debuginfo --- tests/codegen/issue-98678.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/codegen/issue-98678.rs diff --git a/tests/codegen/issue-98678.rs b/tests/codegen/issue-98678.rs new file mode 100644 index 000000000000..72ccbddc59b8 --- /dev/null +++ b/tests/codegen/issue-98678.rs @@ -0,0 +1,11 @@ +// This test verifies the accuracy of emitted file and line debuginfo metadata. +// +// compile-flags: -C debuginfo=2 +#![crate_type = "lib"] + +// CHECK: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}src/test/codegen/issue-98678.rs{{".*}}) + +// CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub struct MyType; + +pub fn foo(_: MyType) {} From 94669d9d47e3a594f4179a2aca9997fa1aeea7ad Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Wed, 16 Nov 2022 15:37:31 -0500 Subject: [PATCH 03/25] Add file and line metadata for closures --- .../rustc_codegen_llvm/src/debuginfo/metadata.rs | 12 ++++++++++-- tests/codegen/issue-98678.rs | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 6b5f53e40bd5..ebc452286b6e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1212,6 +1212,14 @@ fn build_closure_env_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, def_id); let type_name = compute_debuginfo_type_name(cx.tcx, closure_env_type, false); + let closure_span = cx.tcx.def_span(def_id); + let (file_metadata, line_number) = if !closure_span.is_dummy() { + let loc = cx.lookup_debug_loc(closure_span.lo()); + (file_metadata(cx, &loc.file), loc.line) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; + type_map::build_type_with_children( cx, type_map::stub( @@ -1219,8 +1227,8 @@ fn build_closure_env_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + file_metadata, + line_number, cx.size_and_align_of(closure_env_type), Some(containing_scope), DIFlags::FlagZero, diff --git a/tests/codegen/issue-98678.rs b/tests/codegen/issue-98678.rs index 72ccbddc59b8..a6143117b9fd 100644 --- a/tests/codegen/issue-98678.rs +++ b/tests/codegen/issue-98678.rs @@ -8,4 +8,8 @@ // CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], pub struct MyType; -pub fn foo(_: MyType) {} +pub fn foo(_: MyType) { + // CHECK: !DICompositeType({{.*"[{]}}closure_env#0{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + let closure = |x| x; + closure(0); +} From f3da8281853bce792a6a4220ccb432500b6b1da5 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Wed, 16 Nov 2022 21:31:30 -0500 Subject: [PATCH 04/25] Refactor `type_map::stub` parameters Push span lookup into `type_map::stub` and pass the `DefId` instead of doing the lookup outside and passing in the location metadata. --- .../src/debuginfo/metadata.rs | 41 ++++--------------- .../src/debuginfo/metadata/enums/cpp_like.rs | 14 ++++--- .../src/debuginfo/metadata/enums/mod.rs | 24 +++++------ .../src/debuginfo/metadata/enums/native.rs | 6 +-- .../src/debuginfo/metadata/type_map.rs | 19 +++++++-- tests/codegen/issue-98678.rs | 23 ++++++++++- 6 files changed, 65 insertions(+), 62 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index ebc452286b6e..b8fbedb9d67a 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -204,8 +204,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &ptr_type_debuginfo_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, cx.size_and_align_of(ptr_type), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -373,8 +372,7 @@ fn build_dyn_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, cx.size_and_align_of(dyn_type), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -845,8 +843,7 @@ fn build_foreign_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &compute_debuginfo_type_name(cx.tcx, t, false), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, cx.size_and_align_of(t), Some(get_namespace_for_item(cx, def_id)), DIFlags::FlagZero, @@ -1050,15 +1047,6 @@ fn build_struct_type_di_node<'ll, 'tcx>( let struct_type_and_layout = cx.layout_of(struct_type); let variant_def = adt_def.non_enum_variant(); - let tcx = cx.tcx; - let struct_span = tcx.def_span(adt_def.did()); - let (file_metadata, line_number) = if !struct_span.is_dummy() { - let loc = cx.lookup_debug_loc(struct_span.lo()); - (file_metadata(cx, &loc.file), loc.line) - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - }; - type_map::build_type_with_children( cx, type_map::stub( @@ -1066,8 +1054,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &compute_debuginfo_type_name(cx.tcx, struct_type, false), - file_metadata, - line_number, + Some(adt_def.did()), size_and_align_of(struct_type_and_layout), Some(containing_scope), visibility_di_flags(cx, adt_def.did(), adt_def.did()), @@ -1171,8 +1158,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, size_and_align_of(tuple_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -1212,14 +1198,6 @@ fn build_closure_env_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, def_id); let type_name = compute_debuginfo_type_name(cx.tcx, closure_env_type, false); - let closure_span = cx.tcx.def_span(def_id); - let (file_metadata, line_number) = if !closure_span.is_dummy() { - let loc = cx.lookup_debug_loc(closure_span.lo()); - (file_metadata(cx, &loc.file), loc.line) - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - }; - type_map::build_type_with_children( cx, type_map::stub( @@ -1227,8 +1205,7 @@ fn build_closure_env_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - file_metadata, - line_number, + Some(def_id), cx.size_and_align_of(closure_env_type), Some(containing_scope), DIFlags::FlagZero, @@ -1260,8 +1237,7 @@ fn build_union_type_di_node<'ll, 'tcx>( Stub::Union, unique_type_id, &type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + Some(union_def_id), size_and_align_of(union_ty_and_layout), Some(containing_scope), DIFlags::FlagZero, @@ -1454,8 +1430,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>( Stub::VTableTy { vtable_holder }, unique_type_id, &vtable_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, (size, pointer_align), NO_SCOPE_METADATA, DIFlags::FlagArtificial, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index a33347aa2832..751880b0cb7d 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -199,8 +199,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &enum_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + Some(enum_adt_def.did()), cx.size_and_align_of(enum_type), NO_SCOPE_METADATA, visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()), @@ -276,8 +275,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &coroutine_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, size_and_align_of(coroutine_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -332,6 +330,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>( variant_index, Cow::from(enum_adt_def.variant(variant_index).name.as_str()), )), + enum_adt_def.did(), ); let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node( @@ -394,6 +393,7 @@ fn build_union_fields_for_enum<'ll, 'tcx>( let variant_name = Cow::from(enum_adt_def.variant(variant_index).name.as_str()); (variant_index, variant_name) }), + enum_adt_def.did(), ); let visibility_flags = visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()); @@ -451,6 +451,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, containing_scope: &'ll DIType, variants: impl Iterator)>, + enum_def_id: rustc_span::def_id::DefId, ) -> &'ll DIType { // Create an enumerator for each variant. super::build_enumeration_type_di_node( @@ -458,6 +459,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>( "VariantNames", variant_names_enum_base_type(cx), variants.map(|(variant_index, variant_name)| (variant_name, variant_index.as_u32().into())), + enum_def_id, containing_scope, ) } @@ -485,8 +487,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( variant_index, ), &variant_struct_wrapper_type_name(variant_index), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_or_coroutine_type_and_layout), Some(enum_or_coroutine_type_di_node), @@ -690,6 +691,7 @@ fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>( variant_range .clone() .map(|variant_index| (variant_index, CoroutineArgs::variant_name(variant_index))), + coroutine_def_id, ); let discriminants: IndexVec = { 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 4402f2894545..2a6a21061a3a 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -16,8 +16,8 @@ use super::{SmallVec, size_and_align_of}; use crate::common::{AsCCharPtr, CodegenCx}; use crate::debuginfo::metadata::type_map::{self, Stub}; use crate::debuginfo::metadata::{ - UNKNOWN_LINE_NUMBER, build_field_di_node, build_generic_type_param_di_nodes, type_di_node, - unknown_file_metadata, + UNKNOWN_LINE_NUMBER, build_field_di_node, build_generic_type_param_di_nodes, + file_metadata_from_def_id, type_di_node, unknown_file_metadata, }; use crate::debuginfo::utils::{DIB, create_DIArray, get_namespace_for_item}; use crate::llvm::debuginfo::{DIFlags, DIType}; @@ -77,6 +77,7 @@ fn build_c_style_enum_di_node<'ll, 'tcx>( let name = Cow::from(enum_adt_def.variant(variant_index).name.as_str()); (name, discr.val) }), + enum_adt_def.did(), containing_scope, ), already_stored_in_typemap: false, @@ -92,6 +93,7 @@ fn build_enumeration_type_di_node<'ll, 'tcx>( type_name: &str, base_type: Ty<'tcx>, enumerators: impl Iterator, u128)>, + def_id: rustc_span::def_id::DefId, containing_scope: &'ll DIType, ) -> &'ll DIType { let is_unsigned = match base_type.kind() { @@ -115,14 +117,16 @@ fn build_enumeration_type_di_node<'ll, 'tcx>( }) .collect(); + let (file_metadata, line_number) = file_metadata_from_def_id(cx, Some(def_id)); + unsafe { llvm::LLVMRustDIBuilderCreateEnumerationType( DIB(cx), containing_scope, type_name.as_c_char_ptr(), type_name.len(), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + file_metadata, + line_number, size.bits(), align.bits() as u32, create_DIArray(DIB(cx), &enumerator_di_nodes[..]), @@ -204,8 +208,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( variant_index, ), variant_def.name.as_str(), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_type_and_layout), Some(enum_type_di_node), @@ -288,8 +291,7 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &variant_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, size_and_align_of(coroutine_type_and_layout), Some(coroutine_type_di_node), DIFlags::FlagZero, @@ -355,11 +357,7 @@ enum DiscrResult { impl DiscrResult { fn opt_single_val(&self) -> Option { - if let Self::Value(d) = *self { - Some(d) - } else { - None - } + if let Self::Value(d) = *self { Some(d) } else { None } } } 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 07c3784efe73..7e7de7101cf9 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -62,8 +62,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &enum_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + Some(enum_adt_def.did()), size_and_align_of(enum_type_and_layout), Some(containing_scope), visibility_flags, @@ -143,8 +142,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &coroutine_type_name, - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + None, size_and_align_of(coroutine_type_and_layout), Some(containing_scope), DIFlags::FlagZero, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs index f8f8cf914bae..70cc476c93e4 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -8,10 +8,10 @@ use rustc_macros::HashStable; use rustc_middle::bug; use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; -use super::{SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata}; +use super::{SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, unknown_file_metadata}; use crate::common::{AsCCharPtr, CodegenCx}; use crate::debuginfo::utils::{DIB, create_DIArray, debug_context}; -use crate::llvm::debuginfo::{DIFile, DIFlags, DIScope, DIType}; +use crate::llvm::debuginfo::{DIFlags, DIScope, DIType}; use crate::llvm::{self}; mod private { @@ -174,8 +174,7 @@ pub(super) fn stub<'ll, 'tcx>( kind: Stub<'ll>, unique_type_id: UniqueTypeId<'tcx>, name: &str, - file_metadata: &'ll DIFile, - line_number: u32, + def_id: Option, (size, align): (Size, Align), containing_scope: Option<&'ll DIScope>, flags: DIFlags, @@ -183,6 +182,18 @@ pub(super) fn stub<'ll, 'tcx>( let empty_array = create_DIArray(DIB(cx), &[]); let unique_type_id_str = unique_type_id.generate_unique_id_string(cx.tcx); + let (file_metadata, line_number) = if let Some(def_id) = def_id { + let span = cx.tcx.def_span(def_id); + if !span.is_dummy() { + let loc = cx.lookup_debug_loc(span.lo()); + (file_metadata(cx, &loc.file), loc.line) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + } + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; + let metadata = match kind { Stub::Struct | Stub::VTableTy { .. } => { let vtable_holder = match kind { diff --git a/tests/codegen/issue-98678.rs b/tests/codegen/issue-98678.rs index a6143117b9fd..60283a9dd306 100644 --- a/tests/codegen/issue-98678.rs +++ b/tests/codegen/issue-98678.rs @@ -3,12 +3,31 @@ // compile-flags: -C debuginfo=2 #![crate_type = "lib"] -// CHECK: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}src/test/codegen/issue-98678.rs{{".*}}) +// The use of CHECK-DAG here is because the C++-like enum is emitted before the `DIFile` node + +// CHECK-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}src/test/codegen/issue-98678.rs{{".*}}) + +// CHECK-DAG: !DICompositeType({{.*"}}MyCppLikeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], +#[repr(C)] +pub enum MyCppLikeEnum { + One, +} // CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], pub struct MyType; -pub fn foo(_: MyType) { +// CHECK: !DICompositeType({{.*"}}MyUnion{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub union MyUnion { + i: i32, // TODO fields are still wrong + f: f32, +} + +// CHECK: !DICompositeType({{.*"}}MyNativeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub enum MyNativeEnum { + One, +} + +pub fn foo(_: MyType, _: MyUnion, _: MyNativeEnum, _: MyCppLikeEnum) { // CHECK: !DICompositeType({{.*"[{]}}closure_env#0{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], let closure = |x| x; closure(0); From c07797a85479143c711582f5548aa78d65a1dce0 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Wed, 16 Nov 2022 23:12:44 -0500 Subject: [PATCH 05/25] Add file and line metadata for coroutines --- .../src/debuginfo/metadata/enums/cpp_like.rs | 5 ++++- .../src/debuginfo/metadata/enums/native.rs | 2 +- tests/codegen/issue-98678.rs | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 751880b0cb7d..3dd274fbd780 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -263,6 +263,9 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let coroutine_type = unique_type_id.expect_ty(); + let &ty::Coroutine(coroutine_def_id, _, _) = coroutine_type.kind() else { + bug!("build_coroutine_di_node() called with non-coroutine type: `{:?}`", coroutine_type) + }; let coroutine_type_and_layout = cx.layout_of(coroutine_type); let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false); @@ -275,7 +278,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &coroutine_type_name, - None, + Some(coroutine_def_id), size_and_align_of(coroutine_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, 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 7e7de7101cf9..4bd7852b55e0 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -142,7 +142,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &coroutine_type_name, - None, + Some(coroutine_def_id), size_and_align_of(coroutine_type_and_layout), Some(containing_scope), DIFlags::FlagZero, diff --git a/tests/codegen/issue-98678.rs b/tests/codegen/issue-98678.rs index 60283a9dd306..2858452670bd 100644 --- a/tests/codegen/issue-98678.rs +++ b/tests/codegen/issue-98678.rs @@ -2,6 +2,7 @@ // // compile-flags: -C debuginfo=2 #![crate_type = "lib"] +#![feature(generators, stmt_expr_attributes)] // The use of CHECK-DAG here is because the C++-like enum is emitted before the `DIFile` node @@ -31,4 +32,8 @@ pub fn foo(_: MyType, _: MyUnion, _: MyNativeEnum, _: MyCppLikeEnum) { // CHECK: !DICompositeType({{.*"[{]}}closure_env#0{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], let closure = |x| x; closure(0); + + // CHECK: !DICompositeType({{.*"[{]}}generator_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + let generator = #[coroutine] + || yield 1; } From af6b0deaf38f482c25f4553da24a83e3a18c48cb Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Fri, 18 Nov 2022 13:41:53 -0500 Subject: [PATCH 06/25] Add file and line metadata for struct/union members --- .../src/debuginfo/metadata.rs | 37 ++++++++++++++----- .../src/debuginfo/metadata/enums/cpp_like.rs | 5 +++ .../src/debuginfo/metadata/enums/mod.rs | 3 ++ tests/codegen/issue-98678.rs | 9 ++++- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index b8fbedb9d67a..e9865dee61f9 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -261,6 +261,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( layout.fields.offset(abi::WIDE_PTR_ADDR), DIFlags::FlagZero, data_ptr_type_di_node, + None, ), build_field_di_node( cx, @@ -270,6 +271,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>( layout.fields.offset(abi::WIDE_PTR_EXTRA), DIFlags::FlagZero, type_di_node(cx, extra_field.ty), + None, ), ] }, @@ -994,15 +996,17 @@ fn build_field_di_node<'ll, 'tcx>( offset: Size, flags: DIFlags, type_di_node: &'ll DIType, + def_id: Option, ) -> &'ll DIType { + let (file_metadata, line_number) = file_metadata_from_def_id(cx, def_id); unsafe { llvm::LLVMRustDIBuilderCreateMemberType( DIB(cx), owner, name.as_c_char_ptr(), name.len(), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + file_metadata, + line_number, size_and_align.0.bits(), size_and_align.1.bits() as u32, offset.bits(), @@ -1082,6 +1086,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( struct_type_and_layout.fields.offset(i), visibility_di_flags(cx, f.did, adt_def.did()), type_di_node(cx, field_layout.ty), + Some(f.did), ) }) .collect() @@ -1133,6 +1138,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>( layout.fields.offset(index), DIFlags::FlagZero, type_di_node(cx, up_var_ty), + None, ) }) .collect() @@ -1177,6 +1183,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>( tuple_type_and_layout.fields.offset(index), DIFlags::FlagZero, type_di_node(cx, component_type), + None, ) }) .collect() @@ -1258,6 +1265,7 @@ fn build_union_type_di_node<'ll, 'tcx>( Size::ZERO, DIFlags::FlagZero, type_di_node(cx, field_layout.ty), + Some(f.did), ) }) .collect() @@ -1333,14 +1341,7 @@ pub(crate) fn build_global_var_di_node<'ll>( // We may want to remove the namespace scope if we're in an extern block (see // https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952). let var_scope = get_namespace_for_item(cx, def_id); - let span = hygiene::walk_chain_collapsed(tcx.def_span(def_id), DUMMY_SP); - - let (file_metadata, line_number) = if !span.is_dummy() { - let loc = cx.lookup_debug_loc(span.lo()); - (file_metadata(cx, &loc.file), loc.line) - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - }; + let (file_metadata, line_number) = file_metadata_from_def_id(cx, Some(def_id)); let is_local_to_unit = is_node_local_to_unit(cx, def_id); @@ -1468,6 +1469,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>( field_offset, DIFlags::FlagZero, field_type_di_node, + None, )) }) .collect() @@ -1619,3 +1621,18 @@ fn tuple_field_name(field_index: usize) -> Cow<'static, str> { .map(|s| Cow::from(*s)) .unwrap_or_else(|| Cow::from(format!("__{field_index}"))) } + +pub(crate) fn file_metadata_from_def_id<'ll>( + cx: &CodegenCx<'ll, '_>, + def_id: Option, +) -> (&'ll DIFile, c_uint) { + if let Some(def_id) = def_id + && let span = hygiene::walk_chain_collapsed(cx.tcx.def_span(def_id), DUMMY_SP) + && !span.is_dummy() + { + let loc = cx.lookup_debug_loc(span.lo()); + (file_metadata(cx, &loc.file), loc.line) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + } +} diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 3dd274fbd780..6be72bb5055e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -360,6 +360,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>( Size::ZERO, visibility_flags, variant_struct_type_wrapper_di_node, + None, ), unsafe { llvm::LLVMRustDIBuilderCreateStaticMemberType( @@ -540,6 +541,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( Size::ZERO, DIFlags::FlagZero, variant_struct_type_di_node, + None, )); let build_assoc_const = @@ -842,6 +844,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( lo_offset, di_flags, type_di_node, + None, )); unions_fields.push(build_field_di_node( @@ -852,6 +855,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( hi_offset, DIFlags::FlagZero, type_di_node, + None, )); } else { unions_fields.push(build_field_di_node( @@ -862,6 +866,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( enum_type_and_layout.fields.offset(tag_field), di_flags, tag_base_type_di_node, + None, )); } 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 2a6a21061a3a..9b4e992a729d 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -236,6 +236,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( variant_layout.fields.offset(field_index), di_flags, type_di_node(cx, field_layout.ty), + None, ) }) .collect::>() @@ -318,6 +319,7 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>( variant_layout.fields.offset(field_index), DIFlags::FlagZero, type_di_node(cx, field_type), + None, ) }) .collect(); @@ -337,6 +339,7 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>( coroutine_type_and_layout.fields.offset(index), DIFlags::FlagZero, type_di_node(cx, upvar_ty), + None, ) }) .collect(); diff --git a/tests/codegen/issue-98678.rs b/tests/codegen/issue-98678.rs index 2858452670bd..f67a1e1908d3 100644 --- a/tests/codegen/issue-98678.rs +++ b/tests/codegen/issue-98678.rs @@ -15,11 +15,16 @@ pub enum MyCppLikeEnum { } // CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], -pub struct MyType; +pub struct MyType { + // CHECK: !DIDerivedType({{.*"}}i{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + i: i32, +} // CHECK: !DICompositeType({{.*"}}MyUnion{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], pub union MyUnion { - i: i32, // TODO fields are still wrong + // CHECK: !DIDerivedType({{.*"}}i{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + i: i32, + // CHECK: !DIDerivedType({{.*"}}f{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], f: f32, } From aa485fc2a1924c71036fa465e7bac6918ab6b275 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 19 Nov 2022 14:44:13 -0500 Subject: [PATCH 07/25] Add file and line metadata for enum variant and fields --- .../src/debuginfo/metadata/enums/cpp_like.rs | 9 ++++++++- .../src/debuginfo/metadata/enums/mod.rs | 2 +- .../src/debuginfo/metadata/enums/native.rs | 17 +++++++++++++---- .../src/debuginfo/metadata/type_map.rs | 12 +----------- tests/codegen/issue-98678.rs | 6 ++++-- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 6be72bb5055e..489530df3a15 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -338,6 +338,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>( let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node( cx, + enum_adt_def, enum_type_and_layout, enum_type_di_node, variant_index, @@ -470,6 +471,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>( fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, + enum_adt_def: AdtDef<'tcx>, enum_or_coroutine_type_and_layout: TyAndLayout<'tcx>, enum_or_coroutine_type_di_node: &'ll DIType, variant_index: VariantIdx, @@ -491,7 +493,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( variant_index, ), &variant_struct_wrapper_type_name(variant_index), - None, + Some(enum_adt_def.variant(variant_index).def_id), // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_or_coroutine_type_and_layout), Some(enum_or_coroutine_type_di_node), @@ -778,8 +780,13 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( let field_name = variant_union_field_name(variant_member_info.variant_index); let (size, align) = size_and_align_of(enum_type_and_layout); + let ty::Adt(enum_adt_def, _) = enum_type_and_layout.ty.kind() else { + unreachable!(); + }; + let variant_struct_type_wrapper = build_variant_struct_wrapper_type_di_node( cx, + *enum_adt_def, enum_type_and_layout, enum_type_di_node, variant_member_info.variant_index, 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 9b4e992a729d..9974dac5a1de 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -208,7 +208,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( variant_index, ), variant_def.name.as_str(), - None, + Some(variant_def.def_id), // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_type_and_layout), Some(enum_type_di_node), 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 4bd7852b55e0..4a7981ddc882 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -14,7 +14,8 @@ use crate::common::{AsCCharPtr, CodegenCx}; use crate::debuginfo::metadata::type_map::{self, Stub, StubInfo, UniqueTypeId}; use crate::debuginfo::metadata::{ DINodeCreationResult, NO_GENERICS, SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, - size_and_align_of, type_di_node, unknown_file_metadata, visibility_di_flags, + file_metadata_from_def_id, size_and_align_of, type_di_node, unknown_file_metadata, + visibility_di_flags, }; use crate::debuginfo::utils::{DIB, create_DIArray, get_namespace_for_item}; use crate::llvm::debuginfo::{DIFile, DIFlags, DIType}; @@ -85,7 +86,10 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( enum_type_and_layout.for_variant(cx, variant_index), visibility_flags, ), - source_info: None, + source_info: Some(file_metadata_from_def_id( + cx, + Some(enum_adt_def.variant(variant_index).def_id), + )), }) .collect(); @@ -93,6 +97,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( cx, enum_type_and_layout, enum_type_di_node, + enum_adt_def.did(), &variant_member_infos[..], )] }, @@ -203,6 +208,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( cx, coroutine_type_and_layout, coroutine_type_di_node, + coroutine_def_id, &variant_struct_type_di_nodes[..], )] }, @@ -230,6 +236,7 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, enum_type_and_layout: TyAndLayout<'tcx>, enum_type_di_node: &'ll DIType, + enum_type_def_id: rustc_span::def_id::DefId, variant_member_infos: &[VariantMemberInfo<'_, 'll>], ) -> &'ll DIType { let tag_member_di_node = @@ -238,6 +245,8 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>( let variant_part_unique_type_id = UniqueTypeId::for_enum_variant_part(cx.tcx, enum_type_and_layout.ty); + let (file_metadata, line_number) = file_metadata_from_def_id(cx, Some(enum_type_def_id)); + let stub = StubInfo::new( cx, variant_part_unique_type_id, @@ -248,8 +257,8 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>( enum_type_di_node, variant_part_name.as_c_char_ptr(), variant_part_name.len(), - unknown_file_metadata(cx), - UNKNOWN_LINE_NUMBER, + file_metadata, + line_number, enum_type_and_layout.size.bits(), enum_type_and_layout.align.abi.bits() as u32, DIFlags::FlagZero, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs index 70cc476c93e4..1cd86d732eb0 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -182,17 +182,7 @@ pub(super) fn stub<'ll, 'tcx>( let empty_array = create_DIArray(DIB(cx), &[]); let unique_type_id_str = unique_type_id.generate_unique_id_string(cx.tcx); - let (file_metadata, line_number) = if let Some(def_id) = def_id { - let span = cx.tcx.def_span(def_id); - if !span.is_dummy() { - let loc = cx.lookup_debug_loc(span.lo()); - (file_metadata(cx, &loc.file), loc.line) - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - } - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - }; + let (file_metadata, line_number) = super::file_metadata_from_def_id(cx, def_id); let metadata = match kind { Stub::Struct | Stub::VTableTy { .. } => { diff --git a/tests/codegen/issue-98678.rs b/tests/codegen/issue-98678.rs index f67a1e1908d3..ab4e085a317a 100644 --- a/tests/codegen/issue-98678.rs +++ b/tests/codegen/issue-98678.rs @@ -6,7 +6,7 @@ // The use of CHECK-DAG here is because the C++-like enum is emitted before the `DIFile` node -// CHECK-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}src/test/codegen/issue-98678.rs{{".*}}) +// CHECK-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678.rs{{".*}}) // CHECK-DAG: !DICompositeType({{.*"}}MyCppLikeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], #[repr(C)] @@ -28,8 +28,10 @@ pub union MyUnion { f: f32, } -// CHECK: !DICompositeType({{.*"}}MyNativeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +// CHECK: !DICompositeType({{.*"}}MyNativeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], +// CHECK: !DICompositeType({{.*}}DW_TAG_variant_part{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], pub enum MyNativeEnum { + // CHECK: !DIDerivedType({{.*"}}One{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], One, } From 27b1b01daa99cd3cb9338e120cc1a26ca31f8833 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Wed, 23 Nov 2022 00:02:00 -0500 Subject: [PATCH 08/25] Refactor `type_stub` from `DefId` to tuple --- .../src/debuginfo/metadata.rs | 10 ++++++---- .../src/debuginfo/metadata/enums/cpp_like.rs | 20 ++++++++----------- .../src/debuginfo/metadata/enums/mod.rs | 2 +- .../src/debuginfo/metadata/enums/native.rs | 4 ++-- .../src/debuginfo/metadata/type_map.rs | 12 ++++++++--- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index e9865dee61f9..6099b8ddd422 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1058,7 +1058,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &compute_debuginfo_type_name(cx.tcx, struct_type, false), - Some(adt_def.did()), + Some(file_metadata_from_def_id(cx, Some(adt_def.did()))), size_and_align_of(struct_type_and_layout), Some(containing_scope), visibility_di_flags(cx, adt_def.did(), adt_def.did()), @@ -1212,7 +1212,7 @@ fn build_closure_env_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - Some(def_id), + Some(file_metadata_from_def_id(cx, Some(def_id))), cx.size_and_align_of(closure_env_type), Some(containing_scope), DIFlags::FlagZero, @@ -1244,7 +1244,7 @@ fn build_union_type_di_node<'ll, 'tcx>( Stub::Union, unique_type_id, &type_name, - Some(union_def_id), + Some(file_metadata_from_def_id(cx, Some(union_def_id))), size_and_align_of(union_ty_and_layout), Some(containing_scope), DIFlags::FlagZero, @@ -1622,10 +1622,12 @@ fn tuple_field_name(field_index: usize) -> Cow<'static, str> { .unwrap_or_else(|| Cow::from(format!("__{field_index}"))) } +pub(crate) type DefinitionLocation<'ll> = (&'ll DIFile, c_uint); + pub(crate) fn file_metadata_from_def_id<'ll>( cx: &CodegenCx<'ll, '_>, def_id: Option, -) -> (&'ll DIFile, c_uint) { +) -> DefinitionLocation<'ll> { if let Some(def_id) = def_id && let span = hygiene::walk_chain_collapsed(cx.tcx.def_span(def_id), DUMMY_SP) && !span.is_dummy() diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 489530df3a15..62e0f9d92be6 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -16,8 +16,8 @@ use crate::debuginfo::metadata::enums::DiscrResult; use crate::debuginfo::metadata::type_map::{self, Stub, UniqueTypeId}; use crate::debuginfo::metadata::{ DINodeCreationResult, NO_GENERICS, NO_SCOPE_METADATA, SmallVec, UNKNOWN_LINE_NUMBER, - build_field_di_node, file_metadata, size_and_align_of, type_di_node, unknown_file_metadata, - visibility_di_flags, + build_field_di_node, file_metadata, file_metadata_from_def_id, size_and_align_of, type_di_node, + unknown_file_metadata, visibility_di_flags, }; use crate::debuginfo::utils::DIB; use crate::llvm::debuginfo::{DIFile, DIFlags, DIType}; @@ -199,7 +199,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &enum_type_name, - Some(enum_adt_def.did()), + Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))), cx.size_and_align_of(enum_type), NO_SCOPE_METADATA, visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()), @@ -278,7 +278,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &coroutine_type_name, - Some(coroutine_def_id), + Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))), size_and_align_of(coroutine_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -338,7 +338,6 @@ fn build_single_variant_union_fields<'ll, 'tcx>( let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node( cx, - enum_adt_def, enum_type_and_layout, enum_type_di_node, variant_index, @@ -348,6 +347,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>( tag_base_type_di_node, tag_base_type, DiscrResult::NoDiscriminant, + None, ); smallvec![ @@ -471,7 +471,6 @@ fn build_variant_names_type_di_node<'ll, 'tcx>( fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, - enum_adt_def: AdtDef<'tcx>, enum_or_coroutine_type_and_layout: TyAndLayout<'tcx>, enum_or_coroutine_type_di_node: &'ll DIType, variant_index: VariantIdx, @@ -481,6 +480,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( tag_base_type_di_node: &'ll DIType, tag_base_type: Ty<'tcx>, discr: DiscrResult, + source_info: Option<(&'ll DIFile, c_uint)>, ) -> &'ll DIType { type_map::build_type_with_children( cx, @@ -493,7 +493,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>( variant_index, ), &variant_struct_wrapper_type_name(variant_index), - Some(enum_adt_def.variant(variant_index).def_id), + source_info, // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_or_coroutine_type_and_layout), Some(enum_or_coroutine_type_di_node), @@ -780,13 +780,8 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( let field_name = variant_union_field_name(variant_member_info.variant_index); let (size, align) = size_and_align_of(enum_type_and_layout); - let ty::Adt(enum_adt_def, _) = enum_type_and_layout.ty.kind() else { - unreachable!(); - }; - let variant_struct_type_wrapper = build_variant_struct_wrapper_type_di_node( cx, - *enum_adt_def, enum_type_and_layout, enum_type_di_node, variant_member_info.variant_index, @@ -796,6 +791,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( tag_base_type_di_node, tag_base_type, variant_member_info.discr, + variant_member_info.source_info, ); // We use LLVMRustDIBuilderCreateMemberType() member type directly because 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 9974dac5a1de..754395257ee6 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -208,7 +208,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( variant_index, ), variant_def.name.as_str(), - Some(variant_def.def_id), + Some(file_metadata_from_def_id(cx, Some(variant_def.def_id))), // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_type_and_layout), Some(enum_type_di_node), 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 4a7981ddc882..604e9bab0778 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -63,7 +63,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &enum_type_name, - Some(enum_adt_def.did()), + Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))), size_and_align_of(enum_type_and_layout), Some(containing_scope), visibility_flags, @@ -147,7 +147,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &coroutine_type_name, - Some(coroutine_def_id), + Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))), size_and_align_of(coroutine_type_and_layout), Some(containing_scope), DIFlags::FlagZero, diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs index 1cd86d732eb0..a6b399d76696 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -8,7 +8,9 @@ use rustc_macros::HashStable; use rustc_middle::bug; use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; -use super::{SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, unknown_file_metadata}; +use super::{ + DefinitionLocation, SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, unknown_file_metadata, +}; use crate::common::{AsCCharPtr, CodegenCx}; use crate::debuginfo::utils::{DIB, create_DIArray, debug_context}; use crate::llvm::debuginfo::{DIFlags, DIScope, DIType}; @@ -174,7 +176,7 @@ pub(super) fn stub<'ll, 'tcx>( kind: Stub<'ll>, unique_type_id: UniqueTypeId<'tcx>, name: &str, - def_id: Option, + def_location: Option>, (size, align): (Size, Align), containing_scope: Option<&'ll DIScope>, flags: DIFlags, @@ -182,7 +184,11 @@ pub(super) fn stub<'ll, 'tcx>( let empty_array = create_DIArray(DIB(cx), &[]); let unique_type_id_str = unique_type_id.generate_unique_id_string(cx.tcx); - let (file_metadata, line_number) = super::file_metadata_from_def_id(cx, def_id); + let (file_metadata, line_number) = if let Some(def_location) = def_location { + (def_location.0, def_location.1) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; let metadata = match kind { Stub::Struct | Stub::VTableTy { .. } => { From cc4f214a785643198dbaf34d21b2b0836ff3dda6 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 21 Jan 2023 13:57:16 -0500 Subject: [PATCH 09/25] Split metadata testing into multiple files This helps with the fact that the order in which debuginfo is emitted differs between platforms, and is probably not guaranteed to be stable in general. --- .../codegen/issue-98678-closure-generator.rs | 18 ++++++++ tests/codegen/issue-98678-cpp-like-enum.rs | 17 +++++++ tests/codegen/issue-98678-native-enum.rs | 16 +++++++ tests/codegen/issue-98678-struct-union.rs | 23 ++++++++++ tests/codegen/issue-98678.rs | 46 ------------------- 5 files changed, 74 insertions(+), 46 deletions(-) create mode 100644 tests/codegen/issue-98678-closure-generator.rs create mode 100644 tests/codegen/issue-98678-cpp-like-enum.rs create mode 100644 tests/codegen/issue-98678-native-enum.rs create mode 100644 tests/codegen/issue-98678-struct-union.rs delete mode 100644 tests/codegen/issue-98678.rs diff --git a/tests/codegen/issue-98678-closure-generator.rs b/tests/codegen/issue-98678-closure-generator.rs new file mode 100644 index 000000000000..b24f6e21c93e --- /dev/null +++ b/tests/codegen/issue-98678-closure-generator.rs @@ -0,0 +1,18 @@ +// This test verifies the accuracy of emitted file and line debuginfo metadata for closures and +// generators. +// +// compile-flags: -C debuginfo=2 +#![crate_type = "lib"] +#![feature(generators, stmt_expr_attributes)] + +// CHECK: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-closure-generator.rs{{".*}}) + +pub fn foo() { + // CHECK: !DICompositeType({{.*"[{]}}closure_env#0{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + let closure = |x| x; + closure(0); + + // CHECK: !DICompositeType({{.*"[{]}}generator_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + let generator = #[coroutine] + || yield 1; +} diff --git a/tests/codegen/issue-98678-cpp-like-enum.rs b/tests/codegen/issue-98678-cpp-like-enum.rs new file mode 100644 index 000000000000..30ea6cd9577a --- /dev/null +++ b/tests/codegen/issue-98678-cpp-like-enum.rs @@ -0,0 +1,17 @@ +// This test verifies the accuracy of emitted file and line debuginfo metadata for C++-like +// enumerations. +// +// compile-flags: -C debuginfo=2 +#![crate_type = "lib"] + +// The use of CHECK-DAG here is because the C++-like enum is emitted before the `DIFile` node + +// CHECK-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-cpp-like-enum.rs{{".*}}) + +// CHECK-DAG: !DICompositeType({{.*"}}MyCppLikeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], +#[repr(C)] +pub enum MyCppLikeEnum { + One, +} + +pub fn foo(_: MyCppLikeEnum) {} diff --git a/tests/codegen/issue-98678-native-enum.rs b/tests/codegen/issue-98678-native-enum.rs new file mode 100644 index 000000000000..073cc60f77a4 --- /dev/null +++ b/tests/codegen/issue-98678-native-enum.rs @@ -0,0 +1,16 @@ +// This test verifies the accuracy of emitted file and line debuginfo metadata for native +// enumerations. +// +// compile-flags: -C debuginfo=2 +#![crate_type = "lib"] + +// CHECK: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-native-enum.rs{{".*}}) + +// CHECK: !DICompositeType({{.*"}}MyNativeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], +// CHECK: !DICompositeType({{.*}}DW_TAG_variant_part{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub enum MyNativeEnum { + // CHECK: !DIDerivedType({{.*"}}One{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + One, +} + +pub fn foo(_: MyNativeEnum) {} diff --git a/tests/codegen/issue-98678-struct-union.rs b/tests/codegen/issue-98678-struct-union.rs new file mode 100644 index 000000000000..4b6106eb1da8 --- /dev/null +++ b/tests/codegen/issue-98678-struct-union.rs @@ -0,0 +1,23 @@ +// This test verifies the accuracy of emitted file and line debuginfo metadata for structs and +// unions. +// +// compile-flags: -C debuginfo=2 +#![crate_type = "lib"] + +// CHECK: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-struct-union.rs{{".*}}) + +// CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub struct MyType { + // CHECK: !DIDerivedType({{.*"}}i{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + i: i32, +} + +// CHECK: !DICompositeType({{.*"}}MyUnion{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub union MyUnion { + // CHECK: !DIDerivedType({{.*"}}i{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + i: i32, + // CHECK: !DIDerivedType({{.*"}}f{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + f: f32, +} + +pub fn foo(_: MyType, _: MyUnion) {} diff --git a/tests/codegen/issue-98678.rs b/tests/codegen/issue-98678.rs deleted file mode 100644 index ab4e085a317a..000000000000 --- a/tests/codegen/issue-98678.rs +++ /dev/null @@ -1,46 +0,0 @@ -// This test verifies the accuracy of emitted file and line debuginfo metadata. -// -// compile-flags: -C debuginfo=2 -#![crate_type = "lib"] -#![feature(generators, stmt_expr_attributes)] - -// The use of CHECK-DAG here is because the C++-like enum is emitted before the `DIFile` node - -// CHECK-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678.rs{{".*}}) - -// CHECK-DAG: !DICompositeType({{.*"}}MyCppLikeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], -#[repr(C)] -pub enum MyCppLikeEnum { - One, -} - -// CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], -pub struct MyType { - // CHECK: !DIDerivedType({{.*"}}i{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - i: i32, -} - -// CHECK: !DICompositeType({{.*"}}MyUnion{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], -pub union MyUnion { - // CHECK: !DIDerivedType({{.*"}}i{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - i: i32, - // CHECK: !DIDerivedType({{.*"}}f{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - f: f32, -} - -// CHECK: !DICompositeType({{.*"}}MyNativeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], -// CHECK: !DICompositeType({{.*}}DW_TAG_variant_part{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], -pub enum MyNativeEnum { - // CHECK: !DIDerivedType({{.*"}}One{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - One, -} - -pub fn foo(_: MyType, _: MyUnion, _: MyNativeEnum, _: MyCppLikeEnum) { - // CHECK: !DICompositeType({{.*"[{]}}closure_env#0{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - let closure = |x| x; - closure(0); - - // CHECK: !DICompositeType({{.*"[{]}}generator_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - let generator = #[coroutine] - || yield 1; -} From 937a00b78cd5ddda46b1917666f3fc5477814476 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 21 Jan 2023 14:00:35 -0500 Subject: [PATCH 10/25] Separate NONMSVC and MSVC checks --- tests/codegen/issue-98678-closure-generator.rs | 9 ++++++--- tests/codegen/issue-98678-cpp-like-enum.rs | 5 ++--- tests/codegen/issue-98678-native-enum.rs | 12 ++++++++---- tests/codegen/issue-98678-struct-union.rs | 3 ++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/codegen/issue-98678-closure-generator.rs b/tests/codegen/issue-98678-closure-generator.rs index b24f6e21c93e..e5272d560a94 100644 --- a/tests/codegen/issue-98678-closure-generator.rs +++ b/tests/codegen/issue-98678-closure-generator.rs @@ -5,14 +5,17 @@ #![crate_type = "lib"] #![feature(generators, stmt_expr_attributes)] -// CHECK: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-closure-generator.rs{{".*}}) +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-closure-generator.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-closure-generator.rs{{".*}}) pub fn foo() { - // CHECK: !DICompositeType({{.*"[{]}}closure_env#0{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + // NONMSVC: !DICompositeType({{.*"}}{closure_env#0}{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // MSVC-DAG: !DICompositeType({{.*"}}closure_env$0{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], let closure = |x| x; closure(0); - // CHECK: !DICompositeType({{.*"[{]}}generator_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + // NONMSVC: !DICompositeType({{.*"[{]}}generator_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // MSVC-DAG: !DICompositeType({{.*".*foo::}}generator_env$1>{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], let generator = #[coroutine] || yield 1; } diff --git a/tests/codegen/issue-98678-cpp-like-enum.rs b/tests/codegen/issue-98678-cpp-like-enum.rs index 30ea6cd9577a..fe6dfe8dc874 100644 --- a/tests/codegen/issue-98678-cpp-like-enum.rs +++ b/tests/codegen/issue-98678-cpp-like-enum.rs @@ -4,9 +4,8 @@ // compile-flags: -C debuginfo=2 #![crate_type = "lib"] -// The use of CHECK-DAG here is because the C++-like enum is emitted before the `DIFile` node - -// CHECK-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-cpp-like-enum.rs{{".*}}) +// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-cpp-like-enum.rs{{".*}}) +// MSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-cpp-like-enum.rs{{".*}}) // CHECK-DAG: !DICompositeType({{.*"}}MyCppLikeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], #[repr(C)] diff --git a/tests/codegen/issue-98678-native-enum.rs b/tests/codegen/issue-98678-native-enum.rs index 073cc60f77a4..295e83f25a93 100644 --- a/tests/codegen/issue-98678-native-enum.rs +++ b/tests/codegen/issue-98678-native-enum.rs @@ -4,12 +4,16 @@ // compile-flags: -C debuginfo=2 #![crate_type = "lib"] -// CHECK: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-native-enum.rs{{".*}}) +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-native-enum.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-native-enum.rs{{".*}}) -// CHECK: !DICompositeType({{.*"}}MyNativeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], -// CHECK: !DICompositeType({{.*}}DW_TAG_variant_part{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +// NONMSVC: !DICompositeType({{.*"}}MyNativeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 4]], +// MSVC: !DICompositeType({{.*::}}MyNativeEnum>{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 3]], +// NONMSVC: !DICompositeType({{.*}}DW_TAG_variant_part{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], +// COM: MSVC: currently no DW_TAG_variant_part from MSVC pub enum MyNativeEnum { - // CHECK: !DIDerivedType({{.*"}}One{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + // NONMSVC: !DIDerivedType({{.*"}}One{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // MSVC: !DICompositeType({{.*"}}One{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], One, } diff --git a/tests/codegen/issue-98678-struct-union.rs b/tests/codegen/issue-98678-struct-union.rs index 4b6106eb1da8..904eea8d16f0 100644 --- a/tests/codegen/issue-98678-struct-union.rs +++ b/tests/codegen/issue-98678-struct-union.rs @@ -4,7 +4,8 @@ // compile-flags: -C debuginfo=2 #![crate_type = "lib"] -// CHECK: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-struct-union.rs{{".*}}) +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-struct-union.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-struct-union.rs{{".*}}) // CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], pub struct MyType { From f92fc886f447c29242e0fa7856dbfc810801ed62 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 21 Jan 2023 14:02:34 -0500 Subject: [PATCH 11/25] Allow check lines to exceed normal length limit --- tests/codegen/issue-98678-closure-generator.rs | 2 ++ tests/codegen/issue-98678-cpp-like-enum.rs | 2 ++ tests/codegen/issue-98678-native-enum.rs | 2 ++ tests/codegen/issue-98678-struct-union.rs | 2 ++ 4 files changed, 8 insertions(+) diff --git a/tests/codegen/issue-98678-closure-generator.rs b/tests/codegen/issue-98678-closure-generator.rs index e5272d560a94..140515e7a9e0 100644 --- a/tests/codegen/issue-98678-closure-generator.rs +++ b/tests/codegen/issue-98678-closure-generator.rs @@ -5,6 +5,8 @@ #![crate_type = "lib"] #![feature(generators, stmt_expr_attributes)] +// ignore-tidy-linelength + // NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-closure-generator.rs{{".*}}) // MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-closure-generator.rs{{".*}}) diff --git a/tests/codegen/issue-98678-cpp-like-enum.rs b/tests/codegen/issue-98678-cpp-like-enum.rs index fe6dfe8dc874..fb3da3d8dbc8 100644 --- a/tests/codegen/issue-98678-cpp-like-enum.rs +++ b/tests/codegen/issue-98678-cpp-like-enum.rs @@ -4,6 +4,8 @@ // compile-flags: -C debuginfo=2 #![crate_type = "lib"] +// ignore-tidy-linelength + // NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-cpp-like-enum.rs{{".*}}) // MSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-cpp-like-enum.rs{{".*}}) diff --git a/tests/codegen/issue-98678-native-enum.rs b/tests/codegen/issue-98678-native-enum.rs index 295e83f25a93..0a520c185578 100644 --- a/tests/codegen/issue-98678-native-enum.rs +++ b/tests/codegen/issue-98678-native-enum.rs @@ -4,6 +4,8 @@ // compile-flags: -C debuginfo=2 #![crate_type = "lib"] +// ignore-tidy-linelength + // NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-native-enum.rs{{".*}}) // MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-native-enum.rs{{".*}}) diff --git a/tests/codegen/issue-98678-struct-union.rs b/tests/codegen/issue-98678-struct-union.rs index 904eea8d16f0..36f37c0e826e 100644 --- a/tests/codegen/issue-98678-struct-union.rs +++ b/tests/codegen/issue-98678-struct-union.rs @@ -4,6 +4,8 @@ // compile-flags: -C debuginfo=2 #![crate_type = "lib"] +// ignore-tidy-linelength + // NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-struct-union.rs{{".*}}) // MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-struct-union.rs{{".*}}) From aa1a16a359345502bc4bf2186accf6871dc06b2d Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 21 Jan 2023 16:04:42 -0500 Subject: [PATCH 12/25] Add test for async function and async block --- tests/codegen/issue-98678-async.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/codegen/issue-98678-async.rs diff --git a/tests/codegen/issue-98678-async.rs b/tests/codegen/issue-98678-async.rs new file mode 100644 index 000000000000..e937cfaddc67 --- /dev/null +++ b/tests/codegen/issue-98678-async.rs @@ -0,0 +1,25 @@ +// This test verifies the accuracy of emitted file and line debuginfo metadata for async blocks and +// async functions. +// +// edition: 2021 +// compile-flags: -C debuginfo=2 +#![crate_type = "lib"] + +// ignore-tidy-linelength + +// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-async.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-async.rs{{".*}}) + +// NONMSVC-DAG: !DISubprogram(name: "foo",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], +// MSVC-DAG: !DISubprogram(name: "foo",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub async fn foo() -> u8 { 5 } + +pub fn bar() -> impl std::future::Future { + // NONMSVC: !DICompositeType({{.*"}}{async_block_env#0}{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // MSVC-DAG: !DICompositeType({{.*"}}enum2${{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + async { + let x: u8 = foo().await; + x + 5 + } + +} From fc59f2c28cd72fe9976c1310b243720f9d1acdea Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 21 Jan 2023 19:06:13 -0500 Subject: [PATCH 13/25] Refactor and expand enum test --- tests/codegen/issue-98678-cpp-like-enum.rs | 18 ---------- tests/codegen/issue-98678-enum.rs | 41 ++++++++++++++++++++++ tests/codegen/issue-98678-native-enum.rs | 22 ------------ 3 files changed, 41 insertions(+), 40 deletions(-) delete mode 100644 tests/codegen/issue-98678-cpp-like-enum.rs create mode 100644 tests/codegen/issue-98678-enum.rs delete mode 100644 tests/codegen/issue-98678-native-enum.rs diff --git a/tests/codegen/issue-98678-cpp-like-enum.rs b/tests/codegen/issue-98678-cpp-like-enum.rs deleted file mode 100644 index fb3da3d8dbc8..000000000000 --- a/tests/codegen/issue-98678-cpp-like-enum.rs +++ /dev/null @@ -1,18 +0,0 @@ -// This test verifies the accuracy of emitted file and line debuginfo metadata for C++-like -// enumerations. -// -// compile-flags: -C debuginfo=2 -#![crate_type = "lib"] - -// ignore-tidy-linelength - -// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-cpp-like-enum.rs{{".*}}) -// MSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-cpp-like-enum.rs{{".*}}) - -// CHECK-DAG: !DICompositeType({{.*"}}MyCppLikeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], -#[repr(C)] -pub enum MyCppLikeEnum { - One, -} - -pub fn foo(_: MyCppLikeEnum) {} diff --git a/tests/codegen/issue-98678-enum.rs b/tests/codegen/issue-98678-enum.rs new file mode 100644 index 000000000000..a5bc6688b304 --- /dev/null +++ b/tests/codegen/issue-98678-enum.rs @@ -0,0 +1,41 @@ +// This test verifies the accuracy of emitted file and line debuginfo metadata enums. +// +// compile-flags: -C debuginfo=2 +#![crate_type = "lib"] + +// ignore-tidy-linelength + +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-enum.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-enum.rs{{".*}}) + +// NONMSVC: !DICompositeType({{.*"}}SingleCase{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], +// MSVC: !DICompositeType({{.*"}}enum2${{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub enum SingleCase { + // NONMSVC: !DIDerivedType(tag: DW_TAG_member, name: "One",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "One",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + One, +} + +// NONMSVC: !DICompositeType({{.*"}}MultipleDataCases{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], +// MSVC: !DICompositeType({{.*"}}enum2${{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub enum MultipleDataCases { + // NONMSVC: !DIDerivedType(tag: DW_TAG_member, name: "Case1",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Case1",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + Case1(u32), + // NONMSVC: !DIDerivedType(tag: DW_TAG_member, name: "Case2",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Case2",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + Case2(i64), +} + +// NONMSVC: !DICompositeType({{.*"}}NicheLayout{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], +// MSVC: !DICompositeType({{.*"}}enum2${{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], +pub enum NicheLayout { + // NONMSVC: !DIDerivedType(tag: DW_TAG_member, name: "Something",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Something",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + Something(&'static u32), + // NONMSVC: !DIDerivedType(tag: DW_TAG_member, name: "Nothing",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Nothing",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + Nothing, +} + +pub fn foo(_: SingleCase, _: MultipleDataCases, _: NicheLayout) {} diff --git a/tests/codegen/issue-98678-native-enum.rs b/tests/codegen/issue-98678-native-enum.rs deleted file mode 100644 index 0a520c185578..000000000000 --- a/tests/codegen/issue-98678-native-enum.rs +++ /dev/null @@ -1,22 +0,0 @@ -// This test verifies the accuracy of emitted file and line debuginfo metadata for native -// enumerations. -// -// compile-flags: -C debuginfo=2 -#![crate_type = "lib"] - -// ignore-tidy-linelength - -// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-native-enum.rs{{".*}}) -// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-native-enum.rs{{".*}}) - -// NONMSVC: !DICompositeType({{.*"}}MyNativeEnum{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 4]], -// MSVC: !DICompositeType({{.*::}}MyNativeEnum>{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 3]], -// NONMSVC: !DICompositeType({{.*}}DW_TAG_variant_part{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], -// COM: MSVC: currently no DW_TAG_variant_part from MSVC -pub enum MyNativeEnum { - // NONMSVC: !DIDerivedType({{.*"}}One{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], - // MSVC: !DICompositeType({{.*"}}One{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - One, -} - -pub fn foo(_: MyNativeEnum) {} From b6659b062141c0902acedbc9d8e500cc17433453 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 29 Jul 2023 22:39:44 -0400 Subject: [PATCH 14/25] Move tests into issues directory --- tests/codegen/{ => issues}/issue-98678-async.rs | 0 tests/codegen/{ => issues}/issue-98678-closure-generator.rs | 0 tests/codegen/{ => issues}/issue-98678-enum.rs | 0 tests/codegen/{ => issues}/issue-98678-struct-union.rs | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename tests/codegen/{ => issues}/issue-98678-async.rs (100%) rename tests/codegen/{ => issues}/issue-98678-closure-generator.rs (100%) rename tests/codegen/{ => issues}/issue-98678-enum.rs (100%) rename tests/codegen/{ => issues}/issue-98678-struct-union.rs (100%) diff --git a/tests/codegen/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs similarity index 100% rename from tests/codegen/issue-98678-async.rs rename to tests/codegen/issues/issue-98678-async.rs diff --git a/tests/codegen/issue-98678-closure-generator.rs b/tests/codegen/issues/issue-98678-closure-generator.rs similarity index 100% rename from tests/codegen/issue-98678-closure-generator.rs rename to tests/codegen/issues/issue-98678-closure-generator.rs diff --git a/tests/codegen/issue-98678-enum.rs b/tests/codegen/issues/issue-98678-enum.rs similarity index 100% rename from tests/codegen/issue-98678-enum.rs rename to tests/codegen/issues/issue-98678-enum.rs diff --git a/tests/codegen/issue-98678-struct-union.rs b/tests/codegen/issues/issue-98678-struct-union.rs similarity index 100% rename from tests/codegen/issue-98678-struct-union.rs rename to tests/codegen/issues/issue-98678-struct-union.rs From a4833a80893612a8e97b65777caa1c5f87d38c2c Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 29 Jul 2023 23:48:54 -0400 Subject: [PATCH 15/25] Move additional source location info behind -Z option --- .../src/debuginfo/metadata.rs | 37 ++++++++++++-- .../src/debuginfo/metadata/enums/cpp_like.rs | 49 +++++++++++++++---- .../src/debuginfo/metadata/enums/mod.rs | 24 +++++++-- .../src/debuginfo/metadata/enums/native.rs | 15 +++++- compiler/rustc_interface/src/tests.rs | 1 + compiler/rustc_session/src/options.rs | 2 + tests/codegen/issues/issue-98678-async.rs | 11 +++-- .../issues/issue-98678-closure-generator.rs | 6 +-- tests/codegen/issues/issue-98678-enum.rs | 6 +-- .../issues/issue-98678-struct-union.rs | 6 +-- 10 files changed, 123 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 6099b8ddd422..10264af65f40 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -998,7 +998,12 @@ fn build_field_di_node<'ll, 'tcx>( type_di_node: &'ll DIType, def_id: Option, ) -> &'ll DIType { - let (file_metadata, line_number) = file_metadata_from_def_id(cx, def_id); + let (file_metadata, line_number) = + if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + file_metadata_from_def_id(cx, def_id) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; unsafe { llvm::LLVMRustDIBuilderCreateMemberType( DIB(cx), @@ -1050,6 +1055,11 @@ fn build_struct_type_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, adt_def.did()); let struct_type_and_layout = cx.layout_of(struct_type); let variant_def = adt_def.non_enum_variant(); + let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(file_metadata_from_def_id(cx, Some(adt_def.did()))) + } else { + None + }; type_map::build_type_with_children( cx, @@ -1058,7 +1068,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &compute_debuginfo_type_name(cx.tcx, struct_type, false), - Some(file_metadata_from_def_id(cx, Some(adt_def.did()))), + def_location, size_and_align_of(struct_type_and_layout), Some(containing_scope), visibility_di_flags(cx, adt_def.did(), adt_def.did()), @@ -1078,6 +1088,12 @@ fn build_struct_type_di_node<'ll, 'tcx>( Cow::Borrowed(f.name.as_str()) }; let field_layout = struct_type_and_layout.field(cx, i); + let def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo + { + Some(f.did) + } else { + None + }; build_field_di_node( cx, owner, @@ -1086,7 +1102,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( struct_type_and_layout.fields.offset(i), visibility_di_flags(cx, f.did, adt_def.did()), type_di_node(cx, field_layout.ty), - Some(f.did), + def_id, ) }) .collect() @@ -1236,6 +1252,11 @@ fn build_union_type_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, union_def_id); let union_ty_and_layout = cx.layout_of(union_type); let type_name = compute_debuginfo_type_name(cx.tcx, union_type, false); + let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(file_metadata_from_def_id(cx, Some(union_def_id))) + } else { + None + }; type_map::build_type_with_children( cx, @@ -1244,7 +1265,7 @@ fn build_union_type_di_node<'ll, 'tcx>( Stub::Union, unique_type_id, &type_name, - Some(file_metadata_from_def_id(cx, Some(union_def_id))), + def_location, size_and_align_of(union_ty_and_layout), Some(containing_scope), DIFlags::FlagZero, @@ -1257,6 +1278,12 @@ fn build_union_type_di_node<'ll, 'tcx>( .enumerate() .map(|(i, f)| { let field_layout = union_ty_and_layout.field(cx, i); + let def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo + { + Some(f.did) + } else { + None + }; build_field_di_node( cx, owner, @@ -1265,7 +1292,7 @@ fn build_union_type_di_node<'ll, 'tcx>( Size::ZERO, DIFlags::FlagZero, type_di_node(cx, field_layout.ty), - Some(f.did), + def_id, ) }) .collect() diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 62e0f9d92be6..83a0af851bd9 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -192,6 +192,12 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( assert!(!wants_c_like_enum_debuginfo(cx.tcx, enum_type_and_layout)); + let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))) + } else { + None + }; + type_map::build_type_with_children( cx, type_map::stub( @@ -199,7 +205,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &enum_type_name, - Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))), + def_location, cx.size_and_align_of(enum_type), NO_SCOPE_METADATA, visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()), @@ -263,8 +269,13 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let coroutine_type = unique_type_id.expect_ty(); - let &ty::Coroutine(coroutine_def_id, _, _) = coroutine_type.kind() else { - bug!("build_coroutine_di_node() called with non-coroutine type: `{:?}`", coroutine_type) + let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let &ty::Coroutine(coroutine_def_id, _) = coroutine_type.kind() else { + bug!("build_coroutine_di_node() called with non-coroutine type: `{:?}`", coroutine_type) + }; + Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))) + } else { + None }; let coroutine_type_and_layout = cx.layout_of(coroutine_type); let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false); @@ -278,7 +289,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( type_map::Stub::Union, unique_type_id, &coroutine_type_name, - Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))), + def_location, size_and_align_of(coroutine_type_and_layout), NO_SCOPE_METADATA, DIFlags::FlagZero, @@ -326,6 +337,12 @@ fn build_single_variant_union_fields<'ll, 'tcx>( let tag_base_type_di_node = type_di_node(cx, tag_base_type); let tag_base_type_align = cx.align_of(tag_base_type); + let enum_adt_def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(enum_adt_def.did()) + } else { + None + }; + let variant_names_type_di_node = build_variant_names_type_di_node( cx, enum_type_di_node, @@ -333,7 +350,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>( variant_index, Cow::from(enum_adt_def.variant(variant_index).name.as_str()), )), - enum_adt_def.did(), + enum_adt_def_id, ); let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node( @@ -391,6 +408,12 @@ fn build_union_fields_for_enum<'ll, 'tcx>( ) -> SmallVec<&'ll DIType> { let tag_base_type = tag_base_type(cx.tcx, enum_type_and_layout); + let enum_adt_def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(enum_adt_def.did()) + } else { + None + }; + let variant_names_type_di_node = build_variant_names_type_di_node( cx, enum_type_di_node, @@ -398,7 +421,7 @@ fn build_union_fields_for_enum<'ll, 'tcx>( let variant_name = Cow::from(enum_adt_def.variant(variant_index).name.as_str()); (variant_index, variant_name) }), - enum_adt_def.did(), + enum_adt_def_id, ); let visibility_flags = visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()); @@ -456,7 +479,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, containing_scope: &'ll DIType, variants: impl Iterator)>, - enum_def_id: rustc_span::def_id::DefId, + enum_def_id: Option, ) -> &'ll DIType { // Create an enumerator for each variant. super::build_enumeration_type_di_node( @@ -698,7 +721,11 @@ fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>( variant_range .clone() .map(|variant_index| (variant_index, CoroutineArgs::variant_name(variant_index))), - coroutine_def_id, + if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(coroutine_def_id) + } else { + None + }, ); let discriminants: IndexVec = { @@ -791,7 +818,11 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( tag_base_type_di_node, tag_base_type, variant_member_info.discr, - variant_member_info.source_info, + if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + variant_member_info.source_info + } else { + None + }, ); // We use LLVMRustDIBuilderCreateMemberType() member type directly because 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 754395257ee6..16ae8dc37e53 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -68,6 +68,11 @@ fn build_c_style_enum_di_node<'ll, 'tcx>( enum_type_and_layout: TyAndLayout<'tcx>, ) -> DINodeCreationResult<'ll> { let containing_scope = get_namespace_for_item(cx, enum_adt_def.did()); + let enum_adt_def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(enum_adt_def.did()) + } else { + None + }; DINodeCreationResult { di_node: build_enumeration_type_di_node( cx, @@ -77,7 +82,7 @@ fn build_c_style_enum_di_node<'ll, 'tcx>( let name = Cow::from(enum_adt_def.variant(variant_index).name.as_str()); (name, discr.val) }), - enum_adt_def.did(), + enum_adt_def_id, containing_scope, ), already_stored_in_typemap: false, @@ -93,7 +98,7 @@ fn build_enumeration_type_di_node<'ll, 'tcx>( type_name: &str, base_type: Ty<'tcx>, enumerators: impl Iterator, u128)>, - def_id: rustc_span::def_id::DefId, + def_id: Option, containing_scope: &'ll DIType, ) -> &'ll DIType { let is_unsigned = match base_type.kind() { @@ -117,7 +122,12 @@ fn build_enumeration_type_di_node<'ll, 'tcx>( }) .collect(); - let (file_metadata, line_number) = file_metadata_from_def_id(cx, Some(def_id)); + let (file_metadata, line_number) = + if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + file_metadata_from_def_id(cx, def_id) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; unsafe { llvm::LLVMRustDIBuilderCreateEnumerationType( @@ -197,6 +207,12 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( ) -> &'ll DIType { assert_eq!(variant_layout.ty, enum_type_and_layout.ty); + let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(file_metadata_from_def_id(cx, Some(variant_def.def_id))) + } else { + None + }; + type_map::build_type_with_children( cx, type_map::stub( @@ -208,7 +224,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( variant_index, ), variant_def.name.as_str(), - Some(file_metadata_from_def_id(cx, Some(variant_def.def_id))), + def_location, // NOTE: We use size and align of enum_type, not from variant_layout: size_and_align_of(enum_type_and_layout), Some(enum_type_di_node), 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 604e9bab0778..0d289d8995d5 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -140,6 +140,12 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false); + let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))) + } else { + None + }; + type_map::build_type_with_children( cx, type_map::stub( @@ -147,7 +153,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &coroutine_type_name, - Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))), + def_location, size_and_align_of(coroutine_type_and_layout), Some(containing_scope), DIFlags::FlagZero, @@ -245,7 +251,12 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>( let variant_part_unique_type_id = UniqueTypeId::for_enum_variant_part(cx.tcx, enum_type_and_layout.ty); - let (file_metadata, line_number) = file_metadata_from_def_id(cx, Some(enum_type_def_id)); + let (file_metadata, line_number) = + if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + file_metadata_from_def_id(cx, Some(enum_type_def_id)) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; let stub = StubInfo::new( cx, diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index ce90ceeda561..732c2e3aa148 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -709,6 +709,7 @@ fn test_unstable_options_tracking_hash() { untracked!(macro_backtrace, true); untracked!(meta_stats, true); untracked!(mir_include_spans, MirIncludeSpans::On); + untracked!(more_source_locations_in_debuginfo, true); untracked!(nll_facts, true); untracked!(no_analysis, true); untracked!(no_leak_check, true); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 087ba0522ebe..883894f473c2 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1907,6 +1907,8 @@ options! { #[rustc_lint_opt_deny_field_access("use `Session::mir_opt_level` instead of this field")] mir_opt_level: Option = (None, parse_opt_number, [TRACKED], "MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"), + more_source_locations_in_debuginfo: bool = (false, parse_bool, [UNTRACKED], + "include additional source file and line number information in debuginfo (default: no)"), move_size_limit: Option = (None, parse_opt_number, [TRACKED], "the size at which the `large_assignments` lint starts to be emitted"), mutable_noalias: bool = (true, parse_bool, [TRACKED], diff --git a/tests/codegen/issues/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs index e937cfaddc67..92e11d055694 100644 --- a/tests/codegen/issues/issue-98678-async.rs +++ b/tests/codegen/issues/issue-98678-async.rs @@ -2,17 +2,19 @@ // async functions. // // edition: 2021 -// compile-flags: -C debuginfo=2 +// compile-flags: -C debuginfo=2 -Z more-source-locations-in-debuginfo=true #![crate_type = "lib"] // ignore-tidy-linelength -// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-async.rs{{".*}}) -// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-async.rs{{".*}}) +// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-async.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-async.rs{{".*}}) // NONMSVC-DAG: !DISubprogram(name: "foo",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], // MSVC-DAG: !DISubprogram(name: "foo",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], -pub async fn foo() -> u8 { 5 } +pub async fn foo() -> u8 { + 5 +} pub fn bar() -> impl std::future::Future { // NONMSVC: !DICompositeType({{.*"}}{async_block_env#0}{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], @@ -21,5 +23,4 @@ pub fn bar() -> impl std::future::Future { let x: u8 = foo().await; x + 5 } - } diff --git a/tests/codegen/issues/issue-98678-closure-generator.rs b/tests/codegen/issues/issue-98678-closure-generator.rs index 140515e7a9e0..a12efd495f9b 100644 --- a/tests/codegen/issues/issue-98678-closure-generator.rs +++ b/tests/codegen/issues/issue-98678-closure-generator.rs @@ -1,14 +1,14 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for closures and // generators. // -// compile-flags: -C debuginfo=2 +// compile-flags: -C debuginfo=2 -Z more-source-locations-in-debuginfo #![crate_type = "lib"] #![feature(generators, stmt_expr_attributes)] // ignore-tidy-linelength -// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-closure-generator.rs{{".*}}) -// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-closure-generator.rs{{".*}}) +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-closure-generator.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-closure-generator.rs{{".*}}) pub fn foo() { // NONMSVC: !DICompositeType({{.*"}}{closure_env#0}{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], diff --git a/tests/codegen/issues/issue-98678-enum.rs b/tests/codegen/issues/issue-98678-enum.rs index a5bc6688b304..8005c6c24eee 100644 --- a/tests/codegen/issues/issue-98678-enum.rs +++ b/tests/codegen/issues/issue-98678-enum.rs @@ -1,12 +1,12 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata enums. // -// compile-flags: -C debuginfo=2 +// compile-flags: -C debuginfo=2 -Z more-source-locations-in-debuginfo #![crate_type = "lib"] // ignore-tidy-linelength -// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-enum.rs{{".*}}) -// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-enum.rs{{".*}}) +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-enum.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-enum.rs{{".*}}) // NONMSVC: !DICompositeType({{.*"}}SingleCase{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], // MSVC: !DICompositeType({{.*"}}enum2${{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], diff --git a/tests/codegen/issues/issue-98678-struct-union.rs b/tests/codegen/issues/issue-98678-struct-union.rs index 36f37c0e826e..3876ae46186e 100644 --- a/tests/codegen/issues/issue-98678-struct-union.rs +++ b/tests/codegen/issues/issue-98678-struct-union.rs @@ -1,13 +1,13 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for structs and // unions. // -// compile-flags: -C debuginfo=2 +// compile-flags: -C debuginfo=2 -Z more-source-locations-in-debuginfo #![crate_type = "lib"] // ignore-tidy-linelength -// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-struct-union.rs{{".*}}) -// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-struct-union.rs{{".*}}) +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-struct-union.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-struct-union.rs{{".*}}) // CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], pub struct MyType { From 4692d46a461502ed5732a80cd0848db50cfc678a Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sun, 30 Jul 2023 00:04:47 -0400 Subject: [PATCH 16/25] Add additional option checks --- .../src/debuginfo/metadata.rs | 8 +++- .../src/debuginfo/metadata/enums/native.rs | 39 +++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 10264af65f40..0a442f44a8db 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1221,6 +1221,12 @@ fn build_closure_env_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, def_id); let type_name = compute_debuginfo_type_name(cx.tcx, closure_env_type, false); + let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(file_metadata_from_def_id(cx, Some(def_id))) + } else { + None + }; + type_map::build_type_with_children( cx, type_map::stub( @@ -1228,7 +1234,7 @@ fn build_closure_env_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &type_name, - Some(file_metadata_from_def_id(cx, Some(def_id))), + def_location, cx.size_and_align_of(closure_env_type), Some(containing_scope), DIFlags::FlagZero, 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 0d289d8995d5..326aba7d2f3b 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -56,6 +56,12 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( assert!(!wants_c_like_enum_debuginfo(cx.tcx, enum_type_and_layout)); + let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))) + } else { + None + }; + type_map::build_type_with_children( cx, type_map::stub( @@ -63,7 +69,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( Stub::Struct, unique_type_id, &enum_type_name, - Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))), + def_location, size_and_align_of(enum_type_and_layout), Some(containing_scope), visibility_flags, @@ -86,18 +92,29 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( enum_type_and_layout.for_variant(cx, variant_index), visibility_flags, ), - source_info: Some(file_metadata_from_def_id( - cx, - Some(enum_adt_def.variant(variant_index).def_id), - )), + source_info: if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo + { + Some(file_metadata_from_def_id( + cx, + Some(enum_adt_def.variant(variant_index).def_id), + )) + } else { + None + }, }) .collect(); + let enum_adt_def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo + { + Some(enum_adt_def.did()) + } else { + None + }; smallvec![build_enum_variant_part_di_node( cx, enum_type_and_layout, enum_type_di_node, - enum_adt_def.did(), + enum_adt_def_id, &variant_member_infos[..], )] }, @@ -210,6 +227,12 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( }) .collect(); + let generator_def_id = + if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + Some(generator_def_id) + } else { + None + }; smallvec![build_enum_variant_part_di_node( cx, coroutine_type_and_layout, @@ -242,7 +265,7 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, enum_type_and_layout: TyAndLayout<'tcx>, enum_type_di_node: &'ll DIType, - enum_type_def_id: rustc_span::def_id::DefId, + enum_type_def_id: Option, variant_member_infos: &[VariantMemberInfo<'_, 'll>], ) -> &'ll DIType { let tag_member_di_node = @@ -253,7 +276,7 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>( let (file_metadata, line_number) = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { - file_metadata_from_def_id(cx, Some(enum_type_def_id)) + file_metadata_from_def_id(cx, enum_type_def_id) } else { (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) }; From 21c58b1b2ca37b6a09a1302b035a30878bffd96a Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Fri, 1 Mar 2024 23:33:46 -0500 Subject: [PATCH 17/25] Rename option and add doc --- .../src/debuginfo/metadata.rs | 24 +++++++------- .../src/debuginfo/metadata/enums/cpp_like.rs | 12 +++---- .../src/debuginfo/metadata/enums/mod.rs | 16 ++++----- .../src/debuginfo/metadata/enums/native.rs | 33 +++++++++---------- compiler/rustc_interface/src/tests.rs | 2 +- compiler/rustc_session/src/options.rs | 4 +-- .../debug_info_type_line_numbers.md | 7 ++++ tests/codegen/issues/issue-98678-async.rs | 2 +- .../issues/issue-98678-closure-generator.rs | 2 +- tests/codegen/issues/issue-98678-enum.rs | 2 +- .../issues/issue-98678-struct-union.rs | 2 +- 11 files changed, 54 insertions(+), 52 deletions(-) create mode 100644 src/doc/unstable-book/src/compiler-flags/debug_info_type_line_numbers.md diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 0a442f44a8db..d68da52be11e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -998,12 +998,12 @@ fn build_field_di_node<'ll, 'tcx>( type_di_node: &'ll DIType, def_id: Option, ) -> &'ll DIType { - let (file_metadata, line_number) = - if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { - file_metadata_from_def_id(cx, def_id) - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - }; + let (file_metadata, line_number) = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers + { + file_metadata_from_def_id(cx, def_id) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; unsafe { llvm::LLVMRustDIBuilderCreateMemberType( DIB(cx), @@ -1055,7 +1055,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, adt_def.did()); let struct_type_and_layout = cx.layout_of(struct_type); let variant_def = adt_def.non_enum_variant(); - let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let def_location = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(file_metadata_from_def_id(cx, Some(adt_def.did()))) } else { None @@ -1088,8 +1088,7 @@ fn build_struct_type_di_node<'ll, 'tcx>( Cow::Borrowed(f.name.as_str()) }; let field_layout = struct_type_and_layout.field(cx, i); - let def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo - { + let def_id = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(f.did) } else { None @@ -1221,7 +1220,7 @@ fn build_closure_env_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, def_id); let type_name = compute_debuginfo_type_name(cx.tcx, closure_env_type, false); - let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let def_location = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(file_metadata_from_def_id(cx, Some(def_id))) } else { None @@ -1258,7 +1257,7 @@ fn build_union_type_di_node<'ll, 'tcx>( let containing_scope = get_namespace_for_item(cx, union_def_id); let union_ty_and_layout = cx.layout_of(union_type); let type_name = compute_debuginfo_type_name(cx.tcx, union_type, false); - let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let def_location = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(file_metadata_from_def_id(cx, Some(union_def_id))) } else { None @@ -1284,8 +1283,7 @@ fn build_union_type_di_node<'ll, 'tcx>( .enumerate() .map(|(i, f)| { let field_layout = union_ty_and_layout.field(cx, i); - let def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo - { + let def_id = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(f.did) } else { None diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 83a0af851bd9..81a77ef4e988 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -192,7 +192,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( assert!(!wants_c_like_enum_debuginfo(cx.tcx, enum_type_and_layout)); - let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let def_location = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))) } else { None @@ -269,7 +269,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let coroutine_type = unique_type_id.expect_ty(); - let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let def_location = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { let &ty::Coroutine(coroutine_def_id, _) = coroutine_type.kind() else { bug!("build_coroutine_di_node() called with non-coroutine type: `{:?}`", coroutine_type) }; @@ -337,7 +337,7 @@ fn build_single_variant_union_fields<'ll, 'tcx>( let tag_base_type_di_node = type_di_node(cx, tag_base_type); let tag_base_type_align = cx.align_of(tag_base_type); - let enum_adt_def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let enum_adt_def_id = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(enum_adt_def.did()) } else { None @@ -408,7 +408,7 @@ fn build_union_fields_for_enum<'ll, 'tcx>( ) -> SmallVec<&'ll DIType> { let tag_base_type = tag_base_type(cx.tcx, enum_type_and_layout); - let enum_adt_def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let enum_adt_def_id = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(enum_adt_def.did()) } else { None @@ -721,7 +721,7 @@ fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>( variant_range .clone() .map(|variant_index| (variant_index, CoroutineArgs::variant_name(variant_index))), - if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(coroutine_def_id) } else { None @@ -818,7 +818,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>( tag_base_type_di_node, tag_base_type, variant_member_info.discr, - if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { variant_member_info.source_info } else { None 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 16ae8dc37e53..1486096ddcbb 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -68,7 +68,7 @@ fn build_c_style_enum_di_node<'ll, 'tcx>( enum_type_and_layout: TyAndLayout<'tcx>, ) -> DINodeCreationResult<'ll> { let containing_scope = get_namespace_for_item(cx, enum_adt_def.did()); - let enum_adt_def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let enum_adt_def_id = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(enum_adt_def.did()) } else { None @@ -122,12 +122,12 @@ fn build_enumeration_type_di_node<'ll, 'tcx>( }) .collect(); - let (file_metadata, line_number) = - if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { - file_metadata_from_def_id(cx, def_id) - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - }; + let (file_metadata, line_number) = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers + { + file_metadata_from_def_id(cx, def_id) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; unsafe { llvm::LLVMRustDIBuilderCreateEnumerationType( @@ -207,7 +207,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>( ) -> &'ll DIType { assert_eq!(variant_layout.ty, enum_type_and_layout.ty); - let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let def_location = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(file_metadata_from_def_id(cx, Some(variant_def.def_id))) } else { None 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 326aba7d2f3b..3b4c6ea0893c 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -56,7 +56,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( assert!(!wants_c_like_enum_debuginfo(cx.tcx, enum_type_and_layout)); - let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let def_location = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))) } else { None @@ -92,8 +92,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( enum_type_and_layout.for_variant(cx, variant_index), visibility_flags, ), - source_info: if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo - { + source_info: if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(file_metadata_from_def_id( cx, Some(enum_adt_def.variant(variant_index).def_id), @@ -104,8 +103,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( }) .collect(); - let enum_adt_def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo - { + let enum_adt_def_id = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(enum_adt_def.did()) } else { None @@ -157,7 +155,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false); - let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { + let def_location = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { Some(file_metadata_from_def_id(cx, Some(coroutine_def_id))) } else { None @@ -227,12 +225,11 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( }) .collect(); - let generator_def_id = - if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { - Some(generator_def_id) - } else { - None - }; + let coroutine_def_id = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { + Some(coroutine_def_id) + } else { + None + }; smallvec![build_enum_variant_part_di_node( cx, coroutine_type_and_layout, @@ -274,12 +271,12 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>( let variant_part_unique_type_id = UniqueTypeId::for_enum_variant_part(cx.tcx, enum_type_and_layout.ty); - let (file_metadata, line_number) = - if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo { - file_metadata_from_def_id(cx, enum_type_def_id) - } else { - (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) - }; + let (file_metadata, line_number) = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers + { + file_metadata_from_def_id(cx, enum_type_def_id) + } else { + (unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER) + }; let stub = StubInfo::new( cx, diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 732c2e3aa148..2b710c45bf49 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -709,7 +709,6 @@ fn test_unstable_options_tracking_hash() { untracked!(macro_backtrace, true); untracked!(meta_stats, true); untracked!(mir_include_spans, MirIncludeSpans::On); - untracked!(more_source_locations_in_debuginfo, true); untracked!(nll_facts, true); untracked!(no_analysis, true); untracked!(no_leak_check, true); @@ -773,6 +772,7 @@ fn test_unstable_options_tracking_hash() { tracked!(crate_attr, vec!["abc".to_string()]); tracked!(cross_crate_inline_threshold, InliningThreshold::Always); tracked!(debug_info_for_profiling, true); + tracked!(debug_info_type_line_numbers, true); tracked!(default_visibility, Some(rustc_target::spec::SymbolVisibility::Hidden)); tracked!(dep_info_omit_d_target, true); tracked!(direct_access_external_data, Some(true)); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 883894f473c2..ef83f40e250d 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1714,6 +1714,8 @@ options! { "threshold to allow cross crate inlining of functions"), debug_info_for_profiling: bool = (false, parse_bool, [TRACKED], "emit discriminators and other data necessary for AutoFDO"), + debug_info_type_line_numbers: bool = (false, parse_bool, [TRACKED], + "emit type and line information for additional data types (default: no)"), debuginfo_compression: DebugInfoCompression = (DebugInfoCompression::None, parse_debuginfo_compression, [TRACKED], "compress debug info sections (none, zlib, zstd, default: none)"), deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED], @@ -1907,8 +1909,6 @@ options! { #[rustc_lint_opt_deny_field_access("use `Session::mir_opt_level` instead of this field")] mir_opt_level: Option = (None, parse_opt_number, [TRACKED], "MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"), - more_source_locations_in_debuginfo: bool = (false, parse_bool, [UNTRACKED], - "include additional source file and line number information in debuginfo (default: no)"), move_size_limit: Option = (None, parse_opt_number, [TRACKED], "the size at which the `large_assignments` lint starts to be emitted"), mutable_noalias: bool = (true, parse_bool, [TRACKED], diff --git a/src/doc/unstable-book/src/compiler-flags/debug_info_type_line_numbers.md b/src/doc/unstable-book/src/compiler-flags/debug_info_type_line_numbers.md new file mode 100644 index 000000000000..bea667dcf44d --- /dev/null +++ b/src/doc/unstable-book/src/compiler-flags/debug_info_type_line_numbers.md @@ -0,0 +1,7 @@ +# `debug-info-type-line-numbers` + +--- + +This option causes additional type and line information to be emitted in debug +info to provide richer information to debuggers. This is currently off by +default as it causes some compilation scenarios to be noticeably slower. diff --git a/tests/codegen/issues/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs index 92e11d055694..5872d9b054ce 100644 --- a/tests/codegen/issues/issue-98678-async.rs +++ b/tests/codegen/issues/issue-98678-async.rs @@ -2,7 +2,7 @@ // async functions. // // edition: 2021 -// compile-flags: -C debuginfo=2 -Z more-source-locations-in-debuginfo=true +// compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true #![crate_type = "lib"] // ignore-tidy-linelength diff --git a/tests/codegen/issues/issue-98678-closure-generator.rs b/tests/codegen/issues/issue-98678-closure-generator.rs index a12efd495f9b..3c63cce99b69 100644 --- a/tests/codegen/issues/issue-98678-closure-generator.rs +++ b/tests/codegen/issues/issue-98678-closure-generator.rs @@ -1,7 +1,7 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for closures and // generators. // -// compile-flags: -C debuginfo=2 -Z more-source-locations-in-debuginfo +// compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true #![crate_type = "lib"] #![feature(generators, stmt_expr_attributes)] diff --git a/tests/codegen/issues/issue-98678-enum.rs b/tests/codegen/issues/issue-98678-enum.rs index 8005c6c24eee..eaa1a7a070b2 100644 --- a/tests/codegen/issues/issue-98678-enum.rs +++ b/tests/codegen/issues/issue-98678-enum.rs @@ -1,6 +1,6 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata enums. // -// compile-flags: -C debuginfo=2 -Z more-source-locations-in-debuginfo +// compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true #![crate_type = "lib"] // ignore-tidy-linelength diff --git a/tests/codegen/issues/issue-98678-struct-union.rs b/tests/codegen/issues/issue-98678-struct-union.rs index 3876ae46186e..7c56209e7f06 100644 --- a/tests/codegen/issues/issue-98678-struct-union.rs +++ b/tests/codegen/issues/issue-98678-struct-union.rs @@ -1,7 +1,7 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for structs and // unions. // -// compile-flags: -C debuginfo=2 -Z more-source-locations-in-debuginfo +// compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true #![crate_type = "lib"] // ignore-tidy-linelength From 8200068a1d2f8e3edb9c71508761d39a8e13edee Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Fri, 1 Mar 2024 23:56:03 -0500 Subject: [PATCH 18/25] Rename generator test file --- ...nerator.rs => issue-98678-closure-coroutine.rs} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename tests/codegen/issues/{issue-98678-closure-generator.rs => issue-98678-closure-coroutine.rs} (72%) diff --git a/tests/codegen/issues/issue-98678-closure-generator.rs b/tests/codegen/issues/issue-98678-closure-coroutine.rs similarity index 72% rename from tests/codegen/issues/issue-98678-closure-generator.rs rename to tests/codegen/issues/issue-98678-closure-coroutine.rs index 3c63cce99b69..2c95974d71f0 100644 --- a/tests/codegen/issues/issue-98678-closure-generator.rs +++ b/tests/codegen/issues/issue-98678-closure-coroutine.rs @@ -1,14 +1,14 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for closures and -// generators. +// coroutines. // // compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true #![crate_type = "lib"] -#![feature(generators, stmt_expr_attributes)] +#![feature(coroutines, stmt_expr_attributes)] // ignore-tidy-linelength -// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-closure-generator.rs{{".*}}) -// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-closure-generator.rs{{".*}}) +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-closure-coroutine.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-closure-coroutine.rs{{".*}}) pub fn foo() { // NONMSVC: !DICompositeType({{.*"}}{closure_env#0}{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], @@ -16,8 +16,8 @@ pub fn foo() { let closure = |x| x; closure(0); - // NONMSVC: !DICompositeType({{.*"[{]}}generator_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], - // MSVC-DAG: !DICompositeType({{.*".*foo::}}generator_env$1>{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - let generator = #[coroutine] + // NONMSVC: !DICompositeType({{.*"[{]}}coroutine_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // MSVC-DAG: !DICompositeType({{.*".*foo::}}coroutine_env$1>{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + let coroutine = #[coroutine] || yield 1; } From 73291114665aafbc5ddffeb209137567a58eac49 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 2 Mar 2024 00:36:35 -0500 Subject: [PATCH 19/25] Update compile flags formatting --- tests/codegen/issues/issue-98678-async.rs | 4 ++-- tests/codegen/issues/issue-98678-closure-coroutine.rs | 2 +- tests/codegen/issues/issue-98678-enum.rs | 2 +- tests/codegen/issues/issue-98678-struct-union.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/codegen/issues/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs index 5872d9b054ce..e5cc39861d5a 100644 --- a/tests/codegen/issues/issue-98678-async.rs +++ b/tests/codegen/issues/issue-98678-async.rs @@ -1,8 +1,8 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for async blocks and // async functions. // -// edition: 2021 -// compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true +//@ edition:2021 +//@ compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true #![crate_type = "lib"] // ignore-tidy-linelength diff --git a/tests/codegen/issues/issue-98678-closure-coroutine.rs b/tests/codegen/issues/issue-98678-closure-coroutine.rs index 2c95974d71f0..0d26c1d0b2ed 100644 --- a/tests/codegen/issues/issue-98678-closure-coroutine.rs +++ b/tests/codegen/issues/issue-98678-closure-coroutine.rs @@ -1,7 +1,7 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for closures and // coroutines. // -// compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true +//@ compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true #![crate_type = "lib"] #![feature(coroutines, stmt_expr_attributes)] diff --git a/tests/codegen/issues/issue-98678-enum.rs b/tests/codegen/issues/issue-98678-enum.rs index eaa1a7a070b2..fd89d27d2e86 100644 --- a/tests/codegen/issues/issue-98678-enum.rs +++ b/tests/codegen/issues/issue-98678-enum.rs @@ -1,6 +1,6 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata enums. // -// compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true +//@ compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true #![crate_type = "lib"] // ignore-tidy-linelength diff --git a/tests/codegen/issues/issue-98678-struct-union.rs b/tests/codegen/issues/issue-98678-struct-union.rs index 7c56209e7f06..9f7c0c6c9a6b 100644 --- a/tests/codegen/issues/issue-98678-struct-union.rs +++ b/tests/codegen/issues/issue-98678-struct-union.rs @@ -1,7 +1,7 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for structs and // unions. // -// compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true +//@ compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true #![crate_type = "lib"] // ignore-tidy-linelength From 613ddc199d2472348604e7da097c7875735c3c35 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Sat, 2 Mar 2024 02:05:29 -0500 Subject: [PATCH 20/25] Restructure `compile-flags` for tests Optimization needs to be explicitly disabled now. --- tests/codegen/issues/issue-98678-async.rs | 3 +-- tests/codegen/issues/issue-98678-closure-coroutine.rs | 11 +++++------ tests/codegen/issues/issue-98678-enum.rs | 3 +-- tests/codegen/issues/issue-98678-struct-union.rs | 3 +-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/codegen/issues/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs index e5cc39861d5a..df413537f015 100644 --- a/tests/codegen/issues/issue-98678-async.rs +++ b/tests/codegen/issues/issue-98678-async.rs @@ -2,8 +2,7 @@ // async functions. // //@ edition:2021 -//@ compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true -#![crate_type = "lib"] +//@ compile-flags: --crate-type=lib -Copt-level=0 -Cdebuginfo=2 -Zdebug-info-type-line-numbers=true // ignore-tidy-linelength diff --git a/tests/codegen/issues/issue-98678-closure-coroutine.rs b/tests/codegen/issues/issue-98678-closure-coroutine.rs index 0d26c1d0b2ed..15e4fbb7773c 100644 --- a/tests/codegen/issues/issue-98678-closure-coroutine.rs +++ b/tests/codegen/issues/issue-98678-closure-coroutine.rs @@ -1,8 +1,7 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for closures and // coroutines. // -//@ compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true -#![crate_type = "lib"] +//@ compile-flags: --crate-type=lib -Copt-level=0 -Cdebuginfo=2 -Zdebug-info-type-line-numbers=true #![feature(coroutines, stmt_expr_attributes)] // ignore-tidy-linelength @@ -11,13 +10,13 @@ // MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-closure-coroutine.rs{{".*}}) pub fn foo() { - // NONMSVC: !DICompositeType({{.*"}}{closure_env#0}{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // NONMSVC-DAG: !DICompositeType({{.*"}}{closure_env#0}{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], // MSVC-DAG: !DICompositeType({{.*"}}closure_env$0{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], let closure = |x| x; closure(0); - // NONMSVC: !DICompositeType({{.*"[{]}}coroutine_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], - // MSVC-DAG: !DICompositeType({{.*".*foo::}}coroutine_env$1>{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - let coroutine = #[coroutine] + // NONMSVC-DAG: !DISubprogram({{.*"[{]}}coroutine_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // MSVC-DAG: !DISubprogram({{.*".*foo::}}coroutine_env$1>{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + let _coroutine = #[coroutine] || yield 1; } diff --git a/tests/codegen/issues/issue-98678-enum.rs b/tests/codegen/issues/issue-98678-enum.rs index fd89d27d2e86..aec18c2132ca 100644 --- a/tests/codegen/issues/issue-98678-enum.rs +++ b/tests/codegen/issues/issue-98678-enum.rs @@ -1,7 +1,6 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata enums. // -//@ compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true -#![crate_type = "lib"] +//@ compile-flags: --crate-type=lib -Copt-level=0 -Cdebuginfo=2 -Zdebug-info-type-line-numbers=true // ignore-tidy-linelength diff --git a/tests/codegen/issues/issue-98678-struct-union.rs b/tests/codegen/issues/issue-98678-struct-union.rs index 9f7c0c6c9a6b..4c0189dd0464 100644 --- a/tests/codegen/issues/issue-98678-struct-union.rs +++ b/tests/codegen/issues/issue-98678-struct-union.rs @@ -1,8 +1,7 @@ // This test verifies the accuracy of emitted file and line debuginfo metadata for structs and // unions. // -//@ compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true -#![crate_type = "lib"] +//@ compile-flags: --crate-type=lib -Copt-level=0 -Cdebuginfo=2 -Zdebug-info-type-line-numbers=true // ignore-tidy-linelength From 64dd58216682257043552673c32eced30c8ce4d9 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Thu, 14 Mar 2024 13:43:25 -0500 Subject: [PATCH 21/25] Use -DAG to handle use of file before definition Also fixup the test assertion for msvc and unix --- tests/codegen/issues/issue-98678-closure-coroutine.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/codegen/issues/issue-98678-closure-coroutine.rs b/tests/codegen/issues/issue-98678-closure-coroutine.rs index 15e4fbb7773c..e628f04409b3 100644 --- a/tests/codegen/issues/issue-98678-closure-coroutine.rs +++ b/tests/codegen/issues/issue-98678-closure-coroutine.rs @@ -6,8 +6,8 @@ // ignore-tidy-linelength -// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-closure-coroutine.rs{{".*}}) -// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-closure-coroutine.rs{{".*}}) +// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-closure-coroutine.rs{{".*}}) +// MSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-closure-coroutine.rs{{".*}}) pub fn foo() { // NONMSVC-DAG: !DICompositeType({{.*"}}{closure_env#0}{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], @@ -15,8 +15,8 @@ pub fn foo() { let closure = |x| x; closure(0); - // NONMSVC-DAG: !DISubprogram({{.*"[{]}}coroutine_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], - // MSVC-DAG: !DISubprogram({{.*".*foo::}}coroutine_env$1>{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + // NONMSVC-DAG: !DICompositeType({{.*"[{]}}coroutine_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], + // MSVC-DAG: !DICompositeType({{.*".*foo::}}coroutine_env$1>{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], let _coroutine = #[coroutine] || yield 1; } From f9ac7aca5d233c2ada84685aaea8c98471867a10 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Wed, 6 Nov 2024 21:38:51 -0500 Subject: [PATCH 22/25] Add location info for f16 --- .../src/debuginfo/metadata.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index d68da52be11e..668ec59065d9 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -728,6 +728,14 @@ fn build_cpp_f16_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> DINodeCreation // `f16`'s value to be displayed using a Natvis visualiser in `intrinsic.natvis`. let float_ty = cx.tcx.types.f16; let bits_ty = cx.tcx.types.u16; + let def_location = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { + match float_ty.kind() { + ty::Adt(def, _) => Some(file_metadata_from_def_id(cx, Some(def.did()))), + _ => None, + } + } else { + None + }; type_map::build_type_with_children( cx, type_map::stub( @@ -735,12 +743,21 @@ fn build_cpp_f16_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> DINodeCreation Stub::Struct, UniqueTypeId::for_ty(cx.tcx, float_ty), "f16", + def_location, cx.size_and_align_of(float_ty), NO_SCOPE_METADATA, DIFlags::FlagZero, ), // Fields: |cx, float_di_node| { + let def_id = if cx.sess().opts.unstable_opts.debug_info_type_line_numbers { + match bits_ty.kind() { + ty::Adt(def, _) => Some(def.did()), + _ => None, + } + } else { + None + }; smallvec![build_field_di_node( cx, float_di_node, @@ -749,6 +766,7 @@ fn build_cpp_f16_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> DINodeCreation Size::ZERO, DIFlags::FlagZero, type_di_node(cx, bits_ty), + def_id, )] }, NO_GENERICS, From 8286299742e16b20ef7c6fbd65921cb19b79038a Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Wed, 6 Nov 2024 21:46:42 -0500 Subject: [PATCH 23/25] Clean up use requirements after rebasing --- .../src/debuginfo/metadata/enums/cpp_like.rs | 2 +- .../rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs | 1 + .../rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs | 2 +- .../rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs | 4 +--- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 81a77ef4e988..d374767f187d 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -4,7 +4,7 @@ use libc::c_uint; use rustc_abi::{Align, Endian, Size, TagEncoding, VariantIdx, Variants}; use rustc_codegen_ssa::debuginfo::type_names::compute_debuginfo_type_name; use rustc_codegen_ssa::debuginfo::{tag_base_type, wants_c_like_enum_debuginfo}; -use rustc_codegen_ssa::traits::ConstCodegenMethods; +use rustc_codegen_ssa::traits::{ConstCodegenMethods, MiscCodegenMethods}; use rustc_index::IndexVec; use rustc_middle::bug; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; 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 1486096ddcbb..65ab22ad89e8 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -3,6 +3,7 @@ use std::borrow::Cow; use rustc_abi::{FieldIdx, TagEncoding, VariantIdx, Variants}; use rustc_codegen_ssa::debuginfo::type_names::{compute_debuginfo_type_name, cpp_like_debuginfo}; use rustc_codegen_ssa::debuginfo::{tag_base_type, wants_c_like_enum_debuginfo}; +use rustc_codegen_ssa::traits::MiscCodegenMethods; use rustc_hir::def::CtorKind; use rustc_index::IndexSlice; use rustc_middle::bug; 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 3b4c6ea0893c..241bf167a81a 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -4,7 +4,7 @@ use libc::c_uint; use rustc_abi::{Size, TagEncoding, VariantIdx, Variants}; use rustc_codegen_ssa::debuginfo::type_names::compute_debuginfo_type_name; use rustc_codegen_ssa::debuginfo::{tag_base_type, wants_c_like_enum_debuginfo}; -use rustc_codegen_ssa::traits::ConstCodegenMethods; +use rustc_codegen_ssa::traits::{ConstCodegenMethods, MiscCodegenMethods}; use rustc_middle::bug; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::{self}; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs index a6b399d76696..2a3d50a8bff9 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs @@ -8,9 +8,7 @@ use rustc_macros::HashStable; use rustc_middle::bug; use rustc_middle::ty::{ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt}; -use super::{ - DefinitionLocation, SmallVec, UNKNOWN_LINE_NUMBER, file_metadata, unknown_file_metadata, -}; +use super::{DefinitionLocation, SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata}; use crate::common::{AsCCharPtr, CodegenCx}; use crate::debuginfo::utils::{DIB, create_DIArray, debug_context}; use crate::llvm::debuginfo::{DIFlags, DIScope, DIType}; From d1515937818b98c944ff85efd0f30dba8503102e Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:20:10 -0500 Subject: [PATCH 24/25] Fix relative lines in coroutine test --- tests/codegen/issues/issue-98678-closure-coroutine.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/codegen/issues/issue-98678-closure-coroutine.rs b/tests/codegen/issues/issue-98678-closure-coroutine.rs index e628f04409b3..0ae94700c5d5 100644 --- a/tests/codegen/issues/issue-98678-closure-coroutine.rs +++ b/tests/codegen/issues/issue-98678-closure-coroutine.rs @@ -15,8 +15,8 @@ pub fn foo() { let closure = |x| x; closure(0); - // NONMSVC-DAG: !DICompositeType({{.*"[{]}}coroutine_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], - // MSVC-DAG: !DICompositeType({{.*".*foo::}}coroutine_env$1>{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], + // NONMSVC-DAG: !DICompositeType({{.*"[{]}}coroutine_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 3]], + // MSVC-DAG: !DICompositeType({{.*".*foo::}}coroutine_env$1>{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], let _coroutine = #[coroutine] || yield 1; } From e9fbb6f27177d9e7579af064c18184114ed9cec9 Mon Sep 17 00:00:00 2001 From: Matt Weber <30441572+mweber15@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:59:34 -0500 Subject: [PATCH 25/25] Fix tests when using MinGW --- tests/codegen/issues/issue-98678-async.rs | 2 +- tests/codegen/issues/issue-98678-closure-coroutine.rs | 2 +- tests/codegen/issues/issue-98678-enum.rs | 2 +- tests/codegen/issues/issue-98678-struct-union.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/codegen/issues/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs index df413537f015..75f5d82eee55 100644 --- a/tests/codegen/issues/issue-98678-async.rs +++ b/tests/codegen/issues/issue-98678-async.rs @@ -6,7 +6,7 @@ // ignore-tidy-linelength -// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-async.rs{{".*}}) +// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*[/\\]}}issue-98678-async.rs{{".*}}) // MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-async.rs{{".*}}) // NONMSVC-DAG: !DISubprogram(name: "foo",{{.*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], diff --git a/tests/codegen/issues/issue-98678-closure-coroutine.rs b/tests/codegen/issues/issue-98678-closure-coroutine.rs index 0ae94700c5d5..0730e56bf315 100644 --- a/tests/codegen/issues/issue-98678-closure-coroutine.rs +++ b/tests/codegen/issues/issue-98678-closure-coroutine.rs @@ -6,7 +6,7 @@ // ignore-tidy-linelength -// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-closure-coroutine.rs{{".*}}) +// NONMSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*[/\\]}}issue-98678-closure-coroutine.rs{{".*}}) // MSVC-DAG: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-closure-coroutine.rs{{".*}}) pub fn foo() { diff --git a/tests/codegen/issues/issue-98678-enum.rs b/tests/codegen/issues/issue-98678-enum.rs index aec18c2132ca..62c6cded8664 100644 --- a/tests/codegen/issues/issue-98678-enum.rs +++ b/tests/codegen/issues/issue-98678-enum.rs @@ -4,7 +4,7 @@ // ignore-tidy-linelength -// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-enum.rs{{".*}}) +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*[/\\]}}issue-98678-enum.rs{{".*}}) // MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-enum.rs{{".*}}) // NONMSVC: !DICompositeType({{.*"}}SingleCase{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 2]], diff --git a/tests/codegen/issues/issue-98678-struct-union.rs b/tests/codegen/issues/issue-98678-struct-union.rs index 4c0189dd0464..bf2d6e731aa4 100644 --- a/tests/codegen/issues/issue-98678-struct-union.rs +++ b/tests/codegen/issues/issue-98678-struct-union.rs @@ -5,7 +5,7 @@ // ignore-tidy-linelength -// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/issue-98678-struct-union.rs{{".*}}) +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*[/\\]}}issue-98678-struct-union.rs{{".*}}) // MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\issue-98678-struct-union.rs{{".*}}) // CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]],