Add file and line metadata for struct/union members
This commit is contained in:
parent
c07797a854
commit
af6b0deaf3
4 changed files with 42 additions and 12 deletions
|
@ -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<DefId>,
|
||||
) -> &'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<DefId>,
|
||||
) -> (&'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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -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::<SmallVec<_>>()
|
||||
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue