From 61c5a6d644e9e5c1995c33a2b07ab251702848ac Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 6 Oct 2021 14:26:50 +0200 Subject: Create more accurate debuginfo for vtables. Before this commit all vtables would have the same name "vtable" in debuginfo. Now they get a name that identifies the implementing type and the trait that is being implemented. --- src/test/codegen/debug-vtable.rs | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/test/codegen/debug-vtable.rs (limited to 'src/test/codegen/debug-vtable.rs') diff --git a/src/test/codegen/debug-vtable.rs b/src/test/codegen/debug-vtable.rs new file mode 100644 index 00000000000..851d68da5ee --- /dev/null +++ b/src/test/codegen/debug-vtable.rs @@ -0,0 +1,47 @@ +// compile-flags: -Cdebuginfo=2 -Copt-level=0 -Ccodegen-units=1 +// ignore-tidy-linelength + +// This test checks the debuginfo for the expected 3 vtables is generated for correct names and number +// of entries. + +// NONMSVC-LABEL: !DIGlobalVariable(name: "::{vtable}" +// MSVC-LABEL: !DIGlobalVariable(name: "impl$::vtable$" +// NONMSVC: !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const ()", +// MSVC: !DIDerivedType(tag: DW_TAG_pointer_type, name: "ptr_const$ >", +// CHECK: !DISubrange(count: 5 + +// NONMSVC-LABEL: !DIGlobalVariable(name: ">::{vtable}" +// MSVC-LABEL: !DIGlobalVariable(name: "impl$ >::vtable$" +// CHECK: !DISubrange(count: 4 + +// NONMSVC-LABEL: !DIGlobalVariable(name: "::{vtable}" +// MSVC-LABEL: !DIGlobalVariable(name: "impl$::vtable$" +// CHECK: !DISubrange(count: 3 + +#![crate_type = "lib"] + +pub struct Foo; + +pub trait SomeTrait { + fn method1(&self) -> u32; + fn method2(&self) -> u32; +} + +impl SomeTrait for Foo { + fn method1(&self) -> u32 { 1 } + fn method2(&self) -> u32 { 2 } +} + +pub trait SomeTraitWithGenerics { + fn method1(&self) -> (T, U); +} + +impl SomeTraitWithGenerics for Foo { + fn method1(&self) -> (u64, i8) { (1, 2) } +} + +pub fn foo(x: &Foo) -> (u32, (u64, i8), &dyn Send) { + let y: &dyn SomeTrait = x; + let z: &dyn SomeTraitWithGenerics = x; + (y.method1(), z.method1(), x as &dyn Send) +} -- cgit 1.4.1-3-g733a5