about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-11 04:31:47 +0000
committerbors <bors@rust-lang.org>2021-10-11 04:31:47 +0000
commit9a757817c352801de8b0593728f8aee21e23cd53 (patch)
tree42c5d573cee81a5de4b243cbe9d52eddeda23a97 /src/test/codegen
parent1ddd4e6d7ed446934abd428a08e18535faef5e03 (diff)
parent61c5a6d644e9e5c1995c33a2b07ab251702848ac (diff)
downloadrust-9a757817c352801de8b0593728f8aee21e23cd53.tar.gz
rust-9a757817c352801de8b0593728f8aee21e23cd53.zip
Auto merge of #89597 - michaelwoerister:improve-vtable-debuginfo, r=wesleywiser
Create more accurate debuginfo for vtables.

Before this PR all vtables would have the same name (`"vtable"`) in debuginfo. Now they get an unambiguous name that identifies the implementing type and the trait that is being implemented.

This is only one of several possible improvements:
- This PR describes vtables as arrays of `*const u8` pointers. It would nice to describe them as structs where function pointer is represented by a field with a name indicative of the method it maps to. However, this requires coming up with a naming scheme that avoids clashes between methods with the same name (which is possible if the vtable contains multiple traits).
- The PR does not update the debuginfo we generate for the vtable-pointer field in a fat `dyn` pointer. Right now there does not seem to be an easy way of getting ahold of a vtable-layout without also knowing the concrete self-type of a trait object.

r? `@wesleywiser`
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/debug-vtable.rs47
-rw-r--r--src/test/codegen/vtabletype.rs21
2 files changed, 47 insertions, 21 deletions
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: "<debug_vtable::Foo as debug_vtable::SomeTrait>::{vtable}"
+// MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, debug_vtable::SomeTrait>::vtable$"
+// NONMSVC: !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const ()",
+// MSVC: !DIDerivedType(tag: DW_TAG_pointer_type, name: "ptr_const$<tuple$<> >",
+// CHECK: !DISubrange(count: 5
+
+// NONMSVC-LABEL: !DIGlobalVariable(name: "<debug_vtable::Foo as debug_vtable::SomeTraitWithGenerics<u64, i8>>::{vtable}"
+// MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, debug_vtable::SomeTraitWithGenerics<u64,i8> >::vtable$"
+// CHECK: !DISubrange(count: 4
+
+// NONMSVC-LABEL: !DIGlobalVariable(name: "<debug_vtable::Foo as _>::{vtable}"
+// MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, _>::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<T, U> {
+    fn method1(&self) -> (T, U);
+}
+
+impl SomeTraitWithGenerics<u64, i8> 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<u64, i8> = x;
+    (y.method1(), z.method1(), x as &dyn Send)
+}
diff --git a/src/test/codegen/vtabletype.rs b/src/test/codegen/vtabletype.rs
deleted file mode 100644
index 82d65b101b0..00000000000
--- a/src/test/codegen/vtabletype.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-// This test depends on a patch that was committed to upstream LLVM
-// after 5.0, then backported to the Rust LLVM fork.
-
-// ignore-windows
-// ignore-macos
-
-// compile-flags: -g -C no-prepopulate-passes
-
-// CHECK-LABEL: @main
-// CHECK: {{.*}}DICompositeType{{.*}}name: "vtable",{{.*}}vtableHolder:{{.*}}
-
-pub trait T {
-}
-
-impl T for f64 {
-}
-
-pub fn main() {
-    let d = 23.0f64;
-    let td = &d as &T;
-}