debuginfo: Support fat pointers to unsized tuples.
This commit is contained in:
parent
a240ccd81c
commit
28ca6b0f79
2 changed files with 27 additions and 9 deletions
|
@ -6,7 +6,7 @@ use super::CrateDebugContext;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
use rustc_middle::ty::{self, DefIdTree, Ty};
|
use rustc_middle::ty::{self, DefIdTree, Ty};
|
||||||
use rustc_target::abi::VariantIdx;
|
use rustc_target::abi::Variants;
|
||||||
|
|
||||||
use crate::common::CodegenCx;
|
use crate::common::CodegenCx;
|
||||||
use crate::llvm;
|
use crate::llvm;
|
||||||
|
@ -72,20 +72,15 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
|
||||||
match *pointee_ty.kind() {
|
match *pointee_ty.kind() {
|
||||||
ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice),
|
ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice),
|
||||||
ty::Dynamic(..) => Some(FatPtrKind::Dyn),
|
ty::Dynamic(..) => Some(FatPtrKind::Dyn),
|
||||||
ty::Adt(adt_def, _) => {
|
ty::Adt(..) | ty::Tuple(..) if matches!(layout.variants, Variants::Single { .. }) => {
|
||||||
assert!(adt_def.is_struct());
|
let last_field_index = layout.fields.count() - 1;
|
||||||
assert!(adt_def.variants.len() == 1);
|
|
||||||
let variant = &adt_def.variants[VariantIdx::from_usize(0)];
|
|
||||||
assert!(!variant.fields.is_empty());
|
|
||||||
let last_field_index = variant.fields.len() - 1;
|
|
||||||
|
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
(0..last_field_index)
|
(0..last_field_index)
|
||||||
.all(|field_index| { !layout.field(cx, field_index).is_unsized() })
|
.all(|field_index| { !layout.field(cx, field_index).is_unsized() })
|
||||||
);
|
);
|
||||||
|
|
||||||
let unsized_field = layout.field(cx, last_field_index);
|
let unsized_field = layout.field(cx, last_field_index);
|
||||||
assert!(unsized_field.is_unsized());
|
debug_assert!(unsized_field.is_unsized());
|
||||||
fat_pointer_kind(cx, unsized_field.ty)
|
fat_pointer_kind(cx, unsized_field.ty)
|
||||||
}
|
}
|
||||||
ty::Foreign(_) => {
|
ty::Foreign(_) => {
|
||||||
|
|
|
@ -16,6 +16,14 @@
|
||||||
// gdbg-check:$3 = {pointer = [...], vtable = [...]}
|
// gdbg-check:$3 = {pointer = [...], vtable = [...]}
|
||||||
// gdbr-check:$3 = &unsized::Foo<dyn core::fmt::Debug> {pointer: [...], vtable: [...]}
|
// gdbr-check:$3 = &unsized::Foo<dyn core::fmt::Debug> {pointer: [...], vtable: [...]}
|
||||||
|
|
||||||
|
// gdb-command:print tuple_slice
|
||||||
|
// gdbg-check:$4 = {data_ptr = [...], length = 2}
|
||||||
|
// gdbr-check:$4 = &(i32, i32, [i32]) {data_ptr: [...], length: 2}
|
||||||
|
|
||||||
|
// gdb-command:print tuple_dyn
|
||||||
|
// gdbg-check:$5 = {pointer = [...], vtable = [...]}
|
||||||
|
// gdbr-check:$5 = &(i32, i32, dyn core::fmt::Debug) {pointer: [...], vtable: [...]}
|
||||||
|
|
||||||
// === CDB TESTS ===================================================================================
|
// === CDB TESTS ===================================================================================
|
||||||
|
|
||||||
// cdb-command: g
|
// cdb-command: g
|
||||||
|
@ -34,6 +42,17 @@
|
||||||
// cdb-check: [+0x000] pointer : 0x[...] [Type: unsized::Foo<dyn$<core::fmt::Debug> > *]
|
// cdb-check: [+0x000] pointer : 0x[...] [Type: unsized::Foo<dyn$<core::fmt::Debug> > *]
|
||||||
// cdb-check: [...] vtable : 0x[...] [Type: unsigned [...]int[...] (*)[3]]
|
// cdb-check: [...] vtable : 0x[...] [Type: unsigned [...]int[...] (*)[3]]
|
||||||
|
|
||||||
|
// cdb-command:dx tuple_slice
|
||||||
|
// cdb-check:tuple_slice [Type: ref$<tuple$<i32,i32,slice$<i32> > >]
|
||||||
|
// cdb-check: [+0x000] data_ptr : 0x[...] [Type: tuple$<i32,i32,slice$<i32> > *]
|
||||||
|
// cdb-check: [...] length : 0x2 [Type: unsigned [...]int[...]
|
||||||
|
|
||||||
|
// cdb-command:dx tuple_dyn
|
||||||
|
// cdb-check:tuple_dyn [Type: ref$<tuple$<i32,i32,dyn$<core::fmt::Debug> > >]
|
||||||
|
// cdb-check: [+0x000] pointer : 0x[...] [Type: tuple$<i32,i32,dyn$<core::fmt::Debug> > *]
|
||||||
|
// cdb-check: [...] vtable : 0x[...] [Type: unsigned [...]int[...] (*)[3]]
|
||||||
|
|
||||||
|
#![feature(unsized_tuple_coercion)]
|
||||||
#![feature(omit_gdb_pretty_printer_section)]
|
#![feature(omit_gdb_pretty_printer_section)]
|
||||||
#![omit_gdb_pretty_printer_section]
|
#![omit_gdb_pretty_printer_section]
|
||||||
|
|
||||||
|
@ -51,6 +70,10 @@ fn main() {
|
||||||
let b: &Foo<Foo<[u8]>> = &foo;
|
let b: &Foo<Foo<[u8]>> = &foo;
|
||||||
let c: &Foo<dyn std::fmt::Debug> = &Foo { value: 7i32 };
|
let c: &Foo<dyn std::fmt::Debug> = &Foo { value: 7i32 };
|
||||||
|
|
||||||
|
// Also check unsized tuples
|
||||||
|
let tuple_slice: &(i32, i32, [i32]) = &(0, 1, [2, 3]);
|
||||||
|
let tuple_dyn: &(i32, i32, dyn std::fmt::Debug) = &(0, 1, &3u64);
|
||||||
|
|
||||||
zzz(); // #break
|
zzz(); // #break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue