Skip to content

Commit

Permalink
Rollup merge of #92375 - wesleywiser:consolidate_debuginfo_msvc_check…
Browse files Browse the repository at this point in the history
…, r=michaelwoerister

Consolidate checking for msvc when generating debuginfo

If the target we're generating code for is msvc, then we do two main
things differently: we generate type names in a C++ style instead of a
Rust style and we generate debuginfo for enums differently.

I've refactored the code so that there is one function
(`cpp_like_debuginfo`) which determines if we should use the C++ style
of naming types and other debuginfo generation or the regular Rust one.

r? ``@michaelwoerister``

This PR is not urgent so please don't let it interrupt your holidays! 🎄 🎁
  • Loading branch information
ehuss authored Jan 8, 2022
2 parents 81c515b + 836addc commit 5cddd24
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 64 deletions.
28 changes: 14 additions & 14 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::llvm::debuginfo::{
use crate::value::Value;

use cstr::cstr;
use rustc_codegen_ssa::debuginfo::type_names::cpp_like_debuginfo;
use rustc_codegen_ssa::traits::*;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -933,16 +934,16 @@ fn basic_type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'l

// When targeting MSVC, emit MSVC style type names for compatibility with
// .natvis visualizers (and perhaps other existing native debuggers?)
let msvc_like_names = cx.tcx.sess.target.is_like_msvc;
let cpp_like_debuginfo = cpp_like_debuginfo(cx.tcx);

let (name, encoding) = match t.kind() {
ty::Never => ("!", DW_ATE_unsigned),
ty::Tuple(elements) if elements.is_empty() => ("()", DW_ATE_unsigned),
ty::Bool => ("bool", DW_ATE_boolean),
ty::Char => ("char", DW_ATE_unsigned_char),
ty::Int(int_ty) if msvc_like_names => (int_ty.msvc_basic_name(), DW_ATE_signed),
ty::Uint(uint_ty) if msvc_like_names => (uint_ty.msvc_basic_name(), DW_ATE_unsigned),
ty::Float(float_ty) if msvc_like_names => (float_ty.msvc_basic_name(), DW_ATE_float),
ty::Int(int_ty) if cpp_like_debuginfo => (int_ty.msvc_basic_name(), DW_ATE_signed),
ty::Uint(uint_ty) if cpp_like_debuginfo => (uint_ty.msvc_basic_name(), DW_ATE_unsigned),
ty::Float(float_ty) if cpp_like_debuginfo => (float_ty.msvc_basic_name(), DW_ATE_float),
ty::Int(int_ty) => (int_ty.name_str(), DW_ATE_signed),
ty::Uint(uint_ty) => (uint_ty.name_str(), DW_ATE_unsigned),
ty::Float(float_ty) => (float_ty.name_str(), DW_ATE_float),
Expand All @@ -959,7 +960,7 @@ fn basic_type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'l
)
};

if !msvc_like_names {
if !cpp_like_debuginfo {
return ty_metadata;
}

Expand Down Expand Up @@ -1525,13 +1526,6 @@ fn prepare_union_metadata<'ll, 'tcx>(
// Enums
//=-----------------------------------------------------------------------------

/// DWARF variant support is only available starting in LLVM 8, but
/// on MSVC we have to use the fallback mode, because LLVM doesn't
/// lower variant parts to PDB.
fn use_enum_fallback(cx: &CodegenCx<'_, '_>) -> bool {
cx.sess().target.is_like_msvc
}

// FIXME(eddyb) maybe precompute this? Right now it's computed once
// per generator monomorphization, but it doesn't depend on substs.
fn generator_layout_and_saved_local_names<'tcx>(
Expand Down Expand Up @@ -1606,7 +1600,10 @@ impl<'ll, 'tcx> EnumMemberDescriptionFactory<'ll, 'tcx> {
_ => bug!(),
};

let fallback = use_enum_fallback(cx);
// While LLVM supports generating debuginfo for variant types (enums), it doesn't support
// lowering that debuginfo to CodeView records for msvc targets. So if we are targeting
// msvc, then we need to use a different, fallback encoding of the debuginfo.
let fallback = cpp_like_debuginfo(cx.tcx);
// This will always find the metadata in the type map.
let self_metadata = type_metadata(cx, self.enum_type, self.span);

Expand Down Expand Up @@ -2159,7 +2156,10 @@ fn prepare_enum_metadata<'ll, 'tcx>(
return FinalMetadata(discriminant_type_metadata(tag.value));
}

if use_enum_fallback(cx) {
// While LLVM supports generating debuginfo for variant types (enums), it doesn't support
// lowering that debuginfo to CodeView records for msvc targets. So if we are targeting
// msvc, then we need to use a different encoding of the debuginfo.
if cpp_like_debuginfo(tcx) {
let discriminant_type_metadata = match layout.variants {
Variants::Single { .. } => None,
Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, .. }
Expand Down
Loading

0 comments on commit 5cddd24

Please sign in to comment.