Skip to content

Commit 5a1a370

Browse files
committed
Auto merge of #94050 - michaelwoerister:fix-unsized-tuple-debuginfo, r=pnkfelix
debuginfo: Support fat pointers to unsized tuples. This PR makes fat pointer debuginfo generation handle the case of unsized tuples. Fixes #93871
2 parents b17226f + 28ca6b0 commit 5a1a370

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/utils.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::CrateDebugContext;
66
use rustc_hir::def_id::DefId;
77
use rustc_middle::ty::layout::LayoutOf;
88
use rustc_middle::ty::{self, DefIdTree, Ty};
9-
use rustc_target::abi::VariantIdx;
9+
use rustc_target::abi::Variants;
1010

1111
use crate::common::CodegenCx;
1212
use crate::llvm;
@@ -72,20 +72,15 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
7272
match *pointee_ty.kind() {
7373
ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice),
7474
ty::Dynamic(..) => Some(FatPtrKind::Dyn),
75-
ty::Adt(adt_def, _) => {
76-
assert!(adt_def.is_struct());
77-
assert!(adt_def.variants.len() == 1);
78-
let variant = &adt_def.variants[VariantIdx::from_usize(0)];
79-
assert!(!variant.fields.is_empty());
80-
let last_field_index = variant.fields.len() - 1;
81-
75+
ty::Adt(..) | ty::Tuple(..) if matches!(layout.variants, Variants::Single { .. }) => {
76+
let last_field_index = layout.fields.count() - 1;
8277
debug_assert!(
8378
(0..last_field_index)
8479
.all(|field_index| { !layout.field(cx, field_index).is_unsized() })
8580
);
8681

8782
let unsized_field = layout.field(cx, last_field_index);
88-
assert!(unsized_field.is_unsized());
83+
debug_assert!(unsized_field.is_unsized());
8984
fat_pointer_kind(cx, unsized_field.ty)
9085
}
9186
ty::Foreign(_) => {

src/test/debuginfo/unsized.rs

+23
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
// gdbg-check:$3 = {pointer = [...], vtable = [...]}
1717
// gdbr-check:$3 = &unsized::Foo<dyn core::fmt::Debug> {pointer: [...], vtable: [...]}
1818

19+
// gdb-command:print tuple_slice
20+
// gdbg-check:$4 = {data_ptr = [...], length = 2}
21+
// gdbr-check:$4 = &(i32, i32, [i32]) {data_ptr: [...], length: 2}
22+
23+
// gdb-command:print tuple_dyn
24+
// gdbg-check:$5 = {pointer = [...], vtable = [...]}
25+
// gdbr-check:$5 = &(i32, i32, dyn core::fmt::Debug) {pointer: [...], vtable: [...]}
26+
1927
// === CDB TESTS ===================================================================================
2028

2129
// cdb-command: g
@@ -34,6 +42,17 @@
3442
// cdb-check: [+0x000] pointer : 0x[...] [Type: unsized::Foo<dyn$<core::fmt::Debug> > *]
3543
// cdb-check: [...] vtable : 0x[...] [Type: unsigned [...]int[...] (*)[3]]
3644

45+
// cdb-command:dx tuple_slice
46+
// cdb-check:tuple_slice [Type: ref$<tuple$<i32,i32,slice$<i32> > >]
47+
// cdb-check: [+0x000] data_ptr : 0x[...] [Type: tuple$<i32,i32,slice$<i32> > *]
48+
// cdb-check: [...] length : 0x2 [Type: unsigned [...]int[...]
49+
50+
// cdb-command:dx tuple_dyn
51+
// cdb-check:tuple_dyn [Type: ref$<tuple$<i32,i32,dyn$<core::fmt::Debug> > >]
52+
// cdb-check: [+0x000] pointer : 0x[...] [Type: tuple$<i32,i32,dyn$<core::fmt::Debug> > *]
53+
// cdb-check: [...] vtable : 0x[...] [Type: unsigned [...]int[...] (*)[3]]
54+
55+
#![feature(unsized_tuple_coercion)]
3756
#![feature(omit_gdb_pretty_printer_section)]
3857
#![omit_gdb_pretty_printer_section]
3958

@@ -51,6 +70,10 @@ fn main() {
5170
let b: &Foo<Foo<[u8]>> = &foo;
5271
let c: &Foo<dyn std::fmt::Debug> = &Foo { value: 7i32 };
5372

73+
// Also check unsized tuples
74+
let tuple_slice: &(i32, i32, [i32]) = &(0, 1, [2, 3]);
75+
let tuple_dyn: &(i32, i32, dyn std::fmt::Debug) = &(0, 1, &3u64);
76+
5477
zzz(); // #break
5578
}
5679

0 commit comments

Comments
 (0)