3 // Require a gdb that can read DW_TAG_variant_part.
4 // min-gdb-version: 8.2
10 // gdb-command:print stack_unique.value
12 // gdbr-command:print stack_unique.next.val.value
15 // gdbr-command:print unique_unique.value
17 // gdbr-command:print unique_unique.next.val.value
20 // gdb-command:print vec_unique[0].value
22 // gdbr-command:print vec_unique[0].next.val.value
25 // gdbr-command:print borrowed_unique.value
27 // gdbr-command:print borrowed_unique.next.val.value
31 // gdb-command:print long_cycle1.value
33 // gdbr-command:print long_cycle1.next.value
35 // gdbr-command:print long_cycle1.next.next.value
37 // gdbr-command:print long_cycle1.next.next.next.value
40 // gdb-command:print long_cycle2.value
42 // gdbr-command:print long_cycle2.next.value
44 // gdbr-command:print long_cycle2.next.next.value
47 // gdb-command:print long_cycle3.value
49 // gdbr-command:print long_cycle3.next.value
52 // gdb-command:print long_cycle4.value
53 // gdb-check:$18 = 29.5
55 // gdbr-command:print long_cycle_w_anon_types.value
58 // gdbr-command:print long_cycle_w_anon_types.next.val.value
61 // gdb-command:continue
63 #![allow(unused_variables)]
64 #![feature(omit_gdb_pretty_printer_section)]
65 #![omit_gdb_pretty_printer_section]
67 use self::Opt::{Empty, Val};
68 use std::boxed::Box as B;
75 struct UniqueNode<T> {
76 next: Opt<Box<UniqueNode<T>>>,
80 struct LongCycle1<T> {
81 next: Box<LongCycle2<T>>,
85 struct LongCycle2<T> {
86 next: Box<LongCycle3<T>>,
90 struct LongCycle3<T> {
91 next: Box<LongCycle4<T>>,
95 struct LongCycle4<T> {
96 next: Option<Box<LongCycle1<T>>>,
100 struct LongCycleWithAnonymousTypes {
101 next: Opt<Box<Box<Box<Box<Box<LongCycleWithAnonymousTypes>>>>>>,
105 // This test case makes sure that recursive structs are properly described. The Node structs are
106 // generic so that we can have a new type (that newly needs to be described) for the different
107 // cases. The potential problem with recursive types is that the DI generation algorithm gets
108 // trapped in an endless loop. To make sure, we actually test this in the different cases, we have
109 // to operate on a new type each time, otherwise we would just hit the DI cache for all but the
112 // The different cases below (stack_*, unique_*, box_*, etc) are set up so that the type description
113 // algorithm will enter the type reference cycle that is created by a recursive definition from a
114 // different context each time.
116 // The "long cycle" cases are constructed to span a longer, indirect recursion cycle between types.
117 // The different locals will cause the DI algorithm to enter the type reference cycle at different
121 let stack_unique: UniqueNode<u16> = UniqueNode {
123 val: Box::new(UniqueNode {
131 let unique_unique: Box<UniqueNode<u32>> = Box::new(UniqueNode {
133 val: Box::new(UniqueNode {
141 let vec_unique: [UniqueNode<f32>; 1] = [UniqueNode {
143 val: Box::new(UniqueNode {
151 let borrowed_unique: &UniqueNode<f64> = &UniqueNode {
153 val: Box::new(UniqueNode {
162 let long_cycle1: LongCycle1<u16> = LongCycle1 {
163 next: Box::new(LongCycle2 {
164 next: Box::new(LongCycle3 {
165 next: Box::new(LongCycle4 {
176 let long_cycle2: LongCycle2<u32> = LongCycle2 {
177 next: Box::new(LongCycle3 {
178 next: Box::new(LongCycle4 {
187 let long_cycle3: LongCycle3<u64> = LongCycle3 {
188 next: Box::new(LongCycle4 {
195 let long_cycle4: LongCycle4<f32> = LongCycle4 {
200 // It's important that LongCycleWithAnonymousTypes is encountered only at the end of the
202 let long_cycle_w_anon_types = B::new(B::new(B::new(B::new(B::new(LongCycleWithAnonymousTypes {
204 val: Box::new(Box::new(Box::new(Box::new(Box::new(LongCycleWithAnonymousTypes {