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: 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 (limited to 'tests/codegen') diff --git a/tests/codegen/issue-98678.rs b/tests/codegen/issue-98678.rs new file mode 100644 index 00000000000..72ccbddc59b --- /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) {} -- cgit 1.4.1-3-g733a5 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: Add file and line metadata for closures --- compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 12 ++++++++++-- tests/codegen/issue-98678.rs | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'tests/codegen') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 6b5f53e40bd..ebc452286b6 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 72ccbddc59b..a6143117b9f 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); +} -- cgit 1.4.1-3-g733a5 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: 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. --- .../rustc_codegen_llvm/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(-) (limited to 'tests/codegen') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index ebc452286b6..b8fbedb9d67 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 a33347aa283..751880b0cb7 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 4402f289454..2a6a21061a3 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 07c3784efe7..7e7de7101cf 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 f8f8cf914ba..70cc476c93e 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 a6143117b9f..60283a9dd30 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); -- cgit 1.4.1-3-g733a5 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: Add file and line metadata for coroutines --- compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs | 5 ++++- compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs | 2 +- tests/codegen/issue-98678.rs | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) (limited to 'tests/codegen') 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 751880b0cb7..3dd274fbd78 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 7e7de7101cf..4bd7852b55e 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 60283a9dd30..2858452670b 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; } -- cgit 1.4.1-3-g733a5 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: Add file and line metadata for struct/union members --- .../rustc_codegen_llvm/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(-) (limited to 'tests/codegen') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index b8fbedb9d67..e9865dee61f 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 3dd274fbd78..6be72bb5055 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 2a6a21061a3..9b4e992a729 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 2858452670b..f67a1e1908d 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, } -- cgit 1.4.1-3-g733a5 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: 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(-) (limited to 'tests/codegen') 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 6be72bb5055..489530df3a1 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 9b4e992a729..9974dac5a1d 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 4bd7852b55e..4a7981ddc88 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 70cc476c93e..1cd86d732eb 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 f67a1e1908d..ab4e085a317 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, } -- cgit 1.4.1-3-g733a5 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: 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. --- tests/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 (limited to 'tests/codegen') diff --git a/tests/codegen/issue-98678-closure-generator.rs b/tests/codegen/issue-98678-closure-generator.rs new file mode 100644 index 00000000000..b24f6e21c93 --- /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 00000000000..30ea6cd9577 --- /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 00000000000..073cc60f77a --- /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 00000000000..4b6106eb1da --- /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 ab4e085a317..00000000000 --- 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; -} -- cgit 1.4.1-3-g733a5 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: 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(-) (limited to 'tests/codegen') diff --git a/tests/codegen/issue-98678-closure-generator.rs b/tests/codegen/issue-98678-closure-generator.rs index b24f6e21c93..e5272d560a9 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 30ea6cd9577..fe6dfe8dc87 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 073cc60f77a..295e83f25a9 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 4b6106eb1da..904eea8d16f 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 { -- cgit 1.4.1-3-g733a5 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: 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(+) (limited to 'tests/codegen') diff --git a/tests/codegen/issue-98678-closure-generator.rs b/tests/codegen/issue-98678-closure-generator.rs index e5272d560a9..140515e7a9e 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 fe6dfe8dc87..fb3da3d8dbc 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 295e83f25a9..0a520c18557 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 904eea8d16f..36f37c0e826 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{{".*}}) -- cgit 1.4.1-3-g733a5 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: 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 (limited to 'tests/codegen') diff --git a/tests/codegen/issue-98678-async.rs b/tests/codegen/issue-98678-async.rs new file mode 100644 index 00000000000..e937cfaddc6 --- /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 + } + +} -- cgit 1.4.1-3-g733a5 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: 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 (limited to 'tests/codegen') 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 fb3da3d8dbc..00000000000 --- 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 00000000000..a5bc6688b30 --- /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 0a520c18557..00000000000 --- 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) {} -- cgit 1.4.1-3-g733a5 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: Move tests into issues directory --- tests/codegen/issue-98678-async.rs | 25 ------------- tests/codegen/issue-98678-closure-generator.rs | 23 ------------ tests/codegen/issue-98678-enum.rs | 41 ---------------------- tests/codegen/issue-98678-struct-union.rs | 26 -------------- tests/codegen/issues/issue-98678-async.rs | 25 +++++++++++++ .../issues/issue-98678-closure-generator.rs | 23 ++++++++++++ tests/codegen/issues/issue-98678-enum.rs | 41 ++++++++++++++++++++++ tests/codegen/issues/issue-98678-struct-union.rs | 26 ++++++++++++++ 8 files changed, 115 insertions(+), 115 deletions(-) delete mode 100644 tests/codegen/issue-98678-async.rs delete mode 100644 tests/codegen/issue-98678-closure-generator.rs delete mode 100644 tests/codegen/issue-98678-enum.rs delete mode 100644 tests/codegen/issue-98678-struct-union.rs create mode 100644 tests/codegen/issues/issue-98678-async.rs create mode 100644 tests/codegen/issues/issue-98678-closure-generator.rs create mode 100644 tests/codegen/issues/issue-98678-enum.rs create mode 100644 tests/codegen/issues/issue-98678-struct-union.rs (limited to 'tests/codegen') diff --git a/tests/codegen/issue-98678-async.rs b/tests/codegen/issue-98678-async.rs deleted file mode 100644 index e937cfaddc6..00000000000 --- a/tests/codegen/issue-98678-async.rs +++ /dev/null @@ -1,25 +0,0 @@ -// 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 - } - -} diff --git a/tests/codegen/issue-98678-closure-generator.rs b/tests/codegen/issue-98678-closure-generator.rs deleted file mode 100644 index 140515e7a9e..00000000000 --- a/tests/codegen/issue-98678-closure-generator.rs +++ /dev/null @@ -1,23 +0,0 @@ -// 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)] - -// ignore-tidy-linelength - -// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-closure-generator.rs{{".*}}) -// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-closure-generator.rs{{".*}}) - -pub fn foo() { - // 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); - - // 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-enum.rs b/tests/codegen/issue-98678-enum.rs deleted file mode 100644 index a5bc6688b30..00000000000 --- a/tests/codegen/issue-98678-enum.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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-struct-union.rs b/tests/codegen/issue-98678-struct-union.rs deleted file mode 100644 index 36f37c0e826..00000000000 --- a/tests/codegen/issue-98678-struct-union.rs +++ /dev/null @@ -1,26 +0,0 @@ -// This test verifies the accuracy of emitted file and line debuginfo metadata for structs and -// unions. -// -// 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{{".*}}) - -// 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/issues/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs new file mode 100644 index 00000000000..e937cfaddc6 --- /dev/null +++ b/tests/codegen/issues/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 + } + +} diff --git a/tests/codegen/issues/issue-98678-closure-generator.rs b/tests/codegen/issues/issue-98678-closure-generator.rs new file mode 100644 index 00000000000..140515e7a9e --- /dev/null +++ b/tests/codegen/issues/issue-98678-closure-generator.rs @@ -0,0 +1,23 @@ +// 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)] + +// ignore-tidy-linelength + +// NONMSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}/codegen/issue-98678-closure-generator.rs{{".*}}) +// MSVC: ![[#FILE:]] = !DIFile({{.*}}filename:{{.*}}\\codegen\\issue-98678-closure-generator.rs{{".*}}) + +pub fn foo() { + // 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); + + // 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/issues/issue-98678-enum.rs b/tests/codegen/issues/issue-98678-enum.rs new file mode 100644 index 00000000000..a5bc6688b30 --- /dev/null +++ b/tests/codegen/issues/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/issues/issue-98678-struct-union.rs b/tests/codegen/issues/issue-98678-struct-union.rs new file mode 100644 index 00000000000..36f37c0e826 --- /dev/null +++ b/tests/codegen/issues/issue-98678-struct-union.rs @@ -0,0 +1,26 @@ +// This test verifies the accuracy of emitted file and line debuginfo metadata for structs and +// unions. +// +// 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{{".*}}) + +// 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) {} -- cgit 1.4.1-3-g733a5 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: Move additional source location info behind -Z option --- .../rustc_codegen_llvm/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 +-- tests/codegen/issues/issue-98678-struct-union.rs | 6 +-- 10 files changed, 123 insertions(+), 34 deletions(-) (limited to 'tests/codegen') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 6099b8ddd42..10264af65f4 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 62e0f9d92be..83a0af851bd 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 754395257ee..16ae8dc37e5 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 604e9bab077..0d289d8995d 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 ce90ceeda56..732c2e3aa14 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 087ba0522eb..883894f473c 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 e937cfaddc6..92e11d05569 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 140515e7a9e..a12efd495f9 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 a5bc6688b30..8005c6c24ee 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 36f37c0e826..3876ae46186 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 { -- cgit 1.4.1-3-g733a5 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: Rename option and add doc --- .../rustc_codegen_llvm/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 +-- .../compiler-flags/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 +- tests/codegen/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 (limited to 'tests/codegen') diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 0a442f44a8d..d68da52be11 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 83a0af851bd..81a77ef4e98 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 16ae8dc37e5..1486096ddcb 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 326aba7d2f3..3b4c6ea0893 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 732c2e3aa14..2b710c45bf4 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 883894f473c..ef83f40e250 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 00000000000..bea667dcf44 --- /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 92e11d05569..5872d9b054c 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 a12efd495f9..3c63cce99b6 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 8005c6c24ee..eaa1a7a070b 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 3876ae46186..7c56209e7f0 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 -- cgit 1.4.1-3-g733a5 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: Rename generator test file --- .../issues/issue-98678-closure-coroutine.rs | 23 ++++++++++++++++++++++ .../issues/issue-98678-closure-generator.rs | 23 ---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 tests/codegen/issues/issue-98678-closure-coroutine.rs delete mode 100644 tests/codegen/issues/issue-98678-closure-generator.rs (limited to 'tests/codegen') diff --git a/tests/codegen/issues/issue-98678-closure-coroutine.rs b/tests/codegen/issues/issue-98678-closure-coroutine.rs new file mode 100644 index 00000000000..2c95974d71f --- /dev/null +++ b/tests/codegen/issues/issue-98678-closure-coroutine.rs @@ -0,0 +1,23 @@ +// 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"] +#![feature(coroutines, stmt_expr_attributes)] + +// ignore-tidy-linelength + +// 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]], + // 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] + || yield 1; +} diff --git a/tests/codegen/issues/issue-98678-closure-generator.rs b/tests/codegen/issues/issue-98678-closure-generator.rs deleted file mode 100644 index 3c63cce99b6..00000000000 --- a/tests/codegen/issues/issue-98678-closure-generator.rs +++ /dev/null @@ -1,23 +0,0 @@ -// This test verifies the accuracy of emitted file and line debuginfo metadata for closures and -// generators. -// -// compile-flags: -C debuginfo=2 -Z debug-info-type-line-numbers=true -#![crate_type = "lib"] -#![feature(generators, stmt_expr_attributes)] - -// ignore-tidy-linelength - -// 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]], - // MSVC-DAG: !DICompositeType({{.*"}}closure_env$0{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]], - 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] - || yield 1; -} -- cgit 1.4.1-3-g733a5 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: 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(-) (limited to 'tests/codegen') diff --git a/tests/codegen/issues/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs index 5872d9b054c..e5cc39861d5 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 2c95974d71f..0d26c1d0b2e 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 eaa1a7a070b..fd89d27d2e8 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 7c56209e7f0..9f7c0c6c9a6 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 -- cgit 1.4.1-3-g733a5 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: 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(-) (limited to 'tests/codegen') diff --git a/tests/codegen/issues/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs index e5cc39861d5..df413537f01 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 0d26c1d0b2e..15e4fbb7773 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 fd89d27d2e8..aec18c2132c 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 9f7c0c6c9a6..4c0189dd046 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 -- cgit 1.4.1-3-g733a5 From 64dd58216682257043552673c32eced30c8ce4d9 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Thu, 14 Mar 2024 13:43:25 -0500 Subject: 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(-) (limited to 'tests/codegen') diff --git a/tests/codegen/issues/issue-98678-closure-coroutine.rs b/tests/codegen/issues/issue-98678-closure-coroutine.rs index 15e4fbb7773..e628f04409b 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; } -- cgit 1.4.1-3-g733a5 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: Fix relative lines in coroutine test --- tests/codegen/issues/issue-98678-closure-coroutine.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codegen') diff --git a/tests/codegen/issues/issue-98678-closure-coroutine.rs b/tests/codegen/issues/issue-98678-closure-coroutine.rs index e628f04409b..0ae94700c5d 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; } -- cgit 1.4.1-3-g733a5 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: 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(-) (limited to 'tests/codegen') diff --git a/tests/codegen/issues/issue-98678-async.rs b/tests/codegen/issues/issue-98678-async.rs index df413537f01..75f5d82eee5 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 0ae94700c5d..0730e56bf31 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 aec18c2132c..62c6cded866 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 4c0189dd046..bf2d6e731aa 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]], -- cgit 1.4.1-3-g733a5