Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
debuginfo: add type metadata for params
This commit adds type metadata for generic parameters (that arise from
polymorphization). Generic parameter metadata is considered zero-sized
and named after the generic parameter.

Signed-off-by: David Wood <[email protected]>
  • Loading branch information
davidtwco committed Jul 20, 2020
commit 19e849516e19fcb0a16be7d3e329c1bbb1746fa3
16 changes: 16 additions & 0 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp
prepare_tuple_metadata(cx, t, &tys, unique_type_id, usage_site_span, NO_SCOPE_METADATA)
.finalize(cx)
}
// Type parameters from polymorphized functions.
ty::Param(_) => MetadataCreationResult::new(param_type_metadata(cx, t), false),
_ => bug!("debuginfo: unexpected type in type_metadata: {:?}", t),
};

Expand Down Expand Up @@ -955,6 +957,20 @@ fn pointer_type_metadata(
}
}

fn param_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
debug!("param_type_metadata: {:?}", t);
let name = format!("{:?}", t);
return unsafe {
llvm::LLVMRustDIBuilderCreateBasicType(
DIB(cx),
name.as_ptr().cast(),
name.len(),
Size::ZERO.bits(),
DW_ATE_unsigned,
)
};
}

pub fn compile_unit_metadata(
tcx: TyCtxt<'_>,
codegen_unit_name: &str,
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_codegen_ssa/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,17 @@ pub fn push_debuginfo_type_name<'tcx>(
tcx.def_key(def_id).disambiguated_data.disambiguator
));
}
// Type parameters from polymorphized functions.
ty::Param(_) => {
output.push_str(&format!("{:?}", t));
}
ty::Error(_)
| ty::Infer(_)
| ty::Placeholder(..)
| ty::Projection(..)
| ty::Bound(..)
| ty::Opaque(..)
| ty::GeneratorWitness(..)
| ty::Param(_) => {
| ty::GeneratorWitness(..) => {
bug!(
"debuginfo: Trying to create type name for \
unexpected type: {:?}",
Expand Down