Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 836addc

Browse files
committed
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.
1 parent f8abed9 commit 836addc

File tree

2 files changed

+65
-64
lines changed

2 files changed

+65
-64
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::llvm::debuginfo::{
1818
use crate::value::Value;
1919

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

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

938939
let (name, encoding) = match t.kind() {
939940
ty::Never => ("!", DW_ATE_unsigned),
940941
ty::Tuple(elements) if elements.is_empty() => ("()", DW_ATE_unsigned),
941942
ty::Bool => ("bool", DW_ATE_boolean),
942943
ty::Char => ("char", DW_ATE_unsigned_char),
943-
ty::Int(int_ty) if msvc_like_names => (int_ty.msvc_basic_name(), DW_ATE_signed),
944-
ty::Uint(uint_ty) if msvc_like_names => (uint_ty.msvc_basic_name(), DW_ATE_unsigned),
945-
ty::Float(float_ty) if msvc_like_names => (float_ty.msvc_basic_name(), DW_ATE_float),
944+
ty::Int(int_ty) if cpp_like_debuginfo => (int_ty.msvc_basic_name(), DW_ATE_signed),
945+
ty::Uint(uint_ty) if cpp_like_debuginfo => (uint_ty.msvc_basic_name(), DW_ATE_unsigned),
946+
ty::Float(float_ty) if cpp_like_debuginfo => (float_ty.msvc_basic_name(), DW_ATE_float),
946947
ty::Int(int_ty) => (int_ty.name_str(), DW_ATE_signed),
947948
ty::Uint(uint_ty) => (uint_ty.name_str(), DW_ATE_unsigned),
948949
ty::Float(float_ty) => (float_ty.name_str(), DW_ATE_float),
@@ -959,7 +960,7 @@ fn basic_type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'l
959960
)
960961
};
961962

962-
if !msvc_like_names {
963+
if !cpp_like_debuginfo {
963964
return ty_metadata;
964965
}
965966

@@ -1521,13 +1522,6 @@ fn prepare_union_metadata<'ll, 'tcx>(
15211522
// Enums
15221523
//=-----------------------------------------------------------------------------
15231524

1524-
/// DWARF variant support is only available starting in LLVM 8, but
1525-
/// on MSVC we have to use the fallback mode, because LLVM doesn't
1526-
/// lower variant parts to PDB.
1527-
fn use_enum_fallback(cx: &CodegenCx<'_, '_>) -> bool {
1528-
cx.sess().target.is_like_msvc
1529-
}
1530-
15311525
// FIXME(eddyb) maybe precompute this? Right now it's computed once
15321526
// per generator monomorphization, but it doesn't depend on substs.
15331527
fn generator_layout_and_saved_local_names<'tcx>(
@@ -1602,7 +1596,10 @@ impl<'ll, 'tcx> EnumMemberDescriptionFactory<'ll, 'tcx> {
16021596
_ => bug!(),
16031597
};
16041598

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

@@ -2155,7 +2152,10 @@ fn prepare_enum_metadata<'ll, 'tcx>(
21552152
return FinalMetadata(discriminant_type_metadata(tag.value));
21562153
}
21572154

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

0 commit comments

Comments
 (0)