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),
|
layout.fields.offset(abi::WIDE_PTR_ADDR),
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
data_ptr_type_di_node,
|
data_ptr_type_di_node,
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
build_field_di_node(
|
build_field_di_node(
|
||||||
cx,
|
cx,
|
||||||
|
@ -270,6 +271,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
|
||||||
layout.fields.offset(abi::WIDE_PTR_EXTRA),
|
layout.fields.offset(abi::WIDE_PTR_EXTRA),
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
type_di_node(cx, extra_field.ty),
|
type_di_node(cx, extra_field.ty),
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -994,15 +996,17 @@ fn build_field_di_node<'ll, 'tcx>(
|
||||||
offset: Size,
|
offset: Size,
|
||||||
flags: DIFlags,
|
flags: DIFlags,
|
||||||
type_di_node: &'ll DIType,
|
type_di_node: &'ll DIType,
|
||||||
|
def_id: Option<DefId>,
|
||||||
) -> &'ll DIType {
|
) -> &'ll DIType {
|
||||||
|
let (file_metadata, line_number) = file_metadata_from_def_id(cx, def_id);
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMRustDIBuilderCreateMemberType(
|
llvm::LLVMRustDIBuilderCreateMemberType(
|
||||||
DIB(cx),
|
DIB(cx),
|
||||||
owner,
|
owner,
|
||||||
name.as_c_char_ptr(),
|
name.as_c_char_ptr(),
|
||||||
name.len(),
|
name.len(),
|
||||||
unknown_file_metadata(cx),
|
file_metadata,
|
||||||
UNKNOWN_LINE_NUMBER,
|
line_number,
|
||||||
size_and_align.0.bits(),
|
size_and_align.0.bits(),
|
||||||
size_and_align.1.bits() as u32,
|
size_and_align.1.bits() as u32,
|
||||||
offset.bits(),
|
offset.bits(),
|
||||||
|
@ -1082,6 +1086,7 @@ fn build_struct_type_di_node<'ll, 'tcx>(
|
||||||
struct_type_and_layout.fields.offset(i),
|
struct_type_and_layout.fields.offset(i),
|
||||||
visibility_di_flags(cx, f.did, adt_def.did()),
|
visibility_di_flags(cx, f.did, adt_def.did()),
|
||||||
type_di_node(cx, field_layout.ty),
|
type_di_node(cx, field_layout.ty),
|
||||||
|
Some(f.did),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -1133,6 +1138,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
|
||||||
layout.fields.offset(index),
|
layout.fields.offset(index),
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
type_di_node(cx, up_var_ty),
|
type_di_node(cx, up_var_ty),
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -1177,6 +1183,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
|
||||||
tuple_type_and_layout.fields.offset(index),
|
tuple_type_and_layout.fields.offset(index),
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
type_di_node(cx, component_type),
|
type_di_node(cx, component_type),
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -1258,6 +1265,7 @@ fn build_union_type_di_node<'ll, 'tcx>(
|
||||||
Size::ZERO,
|
Size::ZERO,
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
type_di_node(cx, field_layout.ty),
|
type_di_node(cx, field_layout.ty),
|
||||||
|
Some(f.did),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect()
|
.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
|
// 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).
|
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952).
|
||||||
let var_scope = get_namespace_for_item(cx, def_id);
|
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) = file_metadata_from_def_id(cx, Some(def_id));
|
||||||
|
|
||||||
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 is_local_to_unit = is_node_local_to_unit(cx, 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,
|
field_offset,
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
field_type_di_node,
|
field_type_di_node,
|
||||||
|
None,
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -1619,3 +1621,18 @@ fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
|
||||||
.map(|s| Cow::from(*s))
|
.map(|s| Cow::from(*s))
|
||||||
.unwrap_or_else(|| Cow::from(format!("__{field_index}")))
|
.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,
|
Size::ZERO,
|
||||||
visibility_flags,
|
visibility_flags,
|
||||||
variant_struct_type_wrapper_di_node,
|
variant_struct_type_wrapper_di_node,
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMRustDIBuilderCreateStaticMemberType(
|
llvm::LLVMRustDIBuilderCreateStaticMemberType(
|
||||||
|
@ -540,6 +541,7 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
|
||||||
Size::ZERO,
|
Size::ZERO,
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
variant_struct_type_di_node,
|
variant_struct_type_di_node,
|
||||||
|
None,
|
||||||
));
|
));
|
||||||
|
|
||||||
let build_assoc_const =
|
let build_assoc_const =
|
||||||
|
@ -842,6 +844,7 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>(
|
||||||
lo_offset,
|
lo_offset,
|
||||||
di_flags,
|
di_flags,
|
||||||
type_di_node,
|
type_di_node,
|
||||||
|
None,
|
||||||
));
|
));
|
||||||
|
|
||||||
unions_fields.push(build_field_di_node(
|
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,
|
hi_offset,
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
type_di_node,
|
type_di_node,
|
||||||
|
None,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
unions_fields.push(build_field_di_node(
|
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),
|
enum_type_and_layout.fields.offset(tag_field),
|
||||||
di_flags,
|
di_flags,
|
||||||
tag_base_type_di_node,
|
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),
|
variant_layout.fields.offset(field_index),
|
||||||
di_flags,
|
di_flags,
|
||||||
type_di_node(cx, field_layout.ty),
|
type_di_node(cx, field_layout.ty),
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<SmallVec<_>>()
|
.collect::<SmallVec<_>>()
|
||||||
|
@ -318,6 +319,7 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
|
||||||
variant_layout.fields.offset(field_index),
|
variant_layout.fields.offset(field_index),
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
type_di_node(cx, field_type),
|
type_di_node(cx, field_type),
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -337,6 +339,7 @@ fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
|
||||||
coroutine_type_and_layout.fields.offset(index),
|
coroutine_type_and_layout.fields.offset(index),
|
||||||
DIFlags::FlagZero,
|
DIFlags::FlagZero,
|
||||||
type_di_node(cx, upvar_ty),
|
type_di_node(cx, upvar_ty),
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -15,11 +15,16 @@ pub enum MyCppLikeEnum {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: !DICompositeType({{.*"}}MyType{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]],
|
// 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]],
|
// CHECK: !DICompositeType({{.*"}}MyUnion{{".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]],
|
||||||
pub union MyUnion {
|
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,
|
f: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue