about summary refs log tree commit diff
path: root/src/test/codegen/debug-vtable.rs
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2022-01-19 17:56:53 +0100
committerMichael Woerister <michaelwoerister@posteo>2022-02-01 10:39:40 +0100
commitfd7557b7ee454058fff84b556892adbef89f7d52 (patch)
tree667e850a23877f30ade7c45f4e92a8959d24bc9c /src/test/codegen/debug-vtable.rs
parent0bcacb391b28460f5a50fd627f01f670dfcfc7cc (diff)
downloadrust-fd7557b7ee454058fff84b556892adbef89f7d52.tar.gz
rust-fd7557b7ee454058fff84b556892adbef89f7d52.zip
debuginfo: Make sure that type names for closure and generator environments are unique in debuginfo.
Before this change, closure/generator environments coming from different
instantiations of the same generic function were all assigned the same
name even though they were distinct types with potentially different data
layout. Now we append the generic arguments of the originating function
to the type name.

This commit also emits '{closure_env#0}' as the name of these types in
order to disambiguate them from the accompanying closure function
'{closure#0}'. Previously both were assigned the same name.
Diffstat (limited to 'src/test/codegen/debug-vtable.rs')
-rw-r--r--src/test/codegen/debug-vtable.rs53
1 files changed, 39 insertions, 14 deletions
diff --git a/src/test/codegen/debug-vtable.rs b/src/test/codegen/debug-vtable.rs
index 1c8cc61f204..35fd275fd28 100644
--- a/src/test/codegen/debug-vtable.rs
+++ b/src/test/codegen/debug-vtable.rs
@@ -1,25 +1,36 @@
-// 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$"
+// Use the v0 symbol mangling scheme to codegen order independent of rustc version.
+// Unnamed items like shims are generated in lexicographical order of their symbol name and in the
+// legacy mangling scheme rustc version and generic parameters are both hashed into a single part
+// of the name, thus randomizing item order with respect to rustc version.
+
+// compile-flags: -Cdebuginfo=2 -Copt-level=0 -Csymbol-mangling-version=v0
+// ignore-tidy-linelength
+
+// NONMSVC: !DIGlobalVariable(name: "<debug_vtable::Foo as debug_vtable::SomeTrait>::{vtable}"
+// MSVC: !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$"
+// NONMSVC: !DIGlobalVariable(name: "<debug_vtable::Foo as debug_vtable::SomeTraitWithGenerics<u64, i8>>::{vtable}"
+// MSVC: !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$"
+// NONMSVC: !DIGlobalVariable(name: "<debug_vtable::Foo as _>::{vtable}"
+// MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, _>::vtable$"
 // CHECK: !DISubrange(count: 3
 
-// NONMSVC-LABEL: !DIGlobalVariable(name: "<debug_vtable::bar::{closure#0} as core::ops::function::FnOnce<(core::option::Option<&dyn core::ops::function::Fn<(), Output=()>>)>>::{vtable}"
-// MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::bar::closure$0, core::ops::function::FnOnce<tuple$<enum$<core::option::Option<ref$<dyn$<core::ops::function::Fn<tuple$<>,assoc$<Output,tuple$<> > > > > >, {{.*}}, {{.*}}, Some> > > >::vtable$"
+// NONMSVC: !DIGlobalVariable(name: "<debug_vtable::bar::{closure_env#0} as core::ops::function::FnOnce<(core::option::Option<&dyn core::ops::function::Fn<(), Output=()>>)>>::{vtable}"
+// MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::bar::closure_env$0, core::ops::function::FnOnce<tuple$<enum$<core::option::Option<ref$<dyn$<core::ops::function::Fn<tuple$<>,assoc$<Output,tuple$<> > > > > >, {{.*}}, {{.*}}, Some> > > >::vtable$"
+
+// NONMSVC: !DIGlobalVariable(name: "<debug_vtable::generic_closure::{closure_env#0}<bool> as core::ops::function::FnOnce<()>>::{vtable}"
+// MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::generic_closure::closure_env$0<bool>, core::ops::function::FnOnce<tuple$<> > >::vtable$
+
+// NONMSVC: !DIGlobalVariable(name: "<debug_vtable::generic_closure::{closure_env#0}<u32> as core::ops::function::FnOnce<()>>::{vtable}"
+// MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::generic_closure::closure_env$0<u32>, core::ops::function::FnOnce<tuple$<> > >::vtable$
 
 #![crate_type = "lib"]
 
@@ -31,8 +42,12 @@ pub trait SomeTrait {
 }
 
 impl SomeTrait for Foo {
-    fn method1(&self) -> u32 { 1 }
-    fn method2(&self) -> u32 { 2 }
+    fn method1(&self) -> u32 {
+        1
+    }
+    fn method2(&self) -> u32 {
+        2
+    }
 }
 
 pub trait SomeTraitWithGenerics<T, U> {
@@ -40,7 +55,9 @@ pub trait SomeTraitWithGenerics<T, U> {
 }
 
 impl SomeTraitWithGenerics<u64, i8> for Foo {
-    fn method1(&self) -> (u64, i8) { (1, 2) }
+    fn method1(&self) -> (u64, i8) {
+        (1, 2)
+    }
 }
 
 pub fn foo(x: &Foo) -> (u32, (u64, i8), &dyn Send) {
@@ -55,3 +72,11 @@ pub fn foo(x: &Foo) -> (u32, (u64, i8), &dyn Send) {
 pub fn bar() -> Box<dyn FnOnce(Option<&dyn Fn()>)> {
     Box::new(|_x: Option<&dyn Fn()>| {})
 }
+
+fn generic_closure<T: 'static>(x: T) -> Box<dyn FnOnce() -> T> {
+    Box::new(move || x)
+}
+
+pub fn instantiate_generic_closures() -> (Box<dyn FnOnce() -> u32>, Box<dyn FnOnce() -> bool>) {
+    (generic_closure(1u32), generic_closure(false))
+}