summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_codegen_ssa/src/debuginfo/mod.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /compiler/rustc_codegen_ssa/src/debuginfo/mod.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/debuginfo/mod.rs')
-rw-r--r--compiler/rustc_codegen_ssa/src/debuginfo/mod.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/mod.rs b/compiler/rustc_codegen_ssa/src/debuginfo/mod.rs
new file mode 100644
index 000000000..6e3f4f0b8
--- /dev/null
+++ b/compiler/rustc_codegen_ssa/src/debuginfo/mod.rs
@@ -0,0 +1,34 @@
+use rustc_middle::ty::{self, layout::TyAndLayout};
+use rustc_target::abi::Size;
+
+// FIXME(eddyb) find a place for this (or a way to replace it).
+pub mod type_names;
+
+/// Returns true if we want to generate a DW_TAG_enumeration_type description for
+/// this instead of a DW_TAG_struct_type with DW_TAG_variant_part.
+///
+/// NOTE: This is somewhat inconsistent right now: For empty enums and enums with a single
+/// fieldless variant, we generate DW_TAG_struct_type, although a
+/// DW_TAG_enumeration_type would be a better fit.
+pub fn wants_c_like_enum_debuginfo<'tcx>(enum_type_and_layout: TyAndLayout<'tcx>) -> bool {
+ match enum_type_and_layout.ty.kind() {
+ ty::Adt(adt_def, _) => {
+ if !adt_def.is_enum() {
+ return false;
+ }
+
+ match adt_def.variants().len() {
+ 0 => false,
+ 1 => {
+ // Univariant enums unless they are zero-sized
+ enum_type_and_layout.size != Size::ZERO && adt_def.all_fields().count() == 0
+ }
+ _ => {
+ // Enums with more than one variant if they have no fields
+ adt_def.all_fields().count() == 0
+ }
+ }
+ }
+ _ => false,
+ }
+}