1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // ignore-tidy-linelength
14 // Require LLVM with DW_TAG_variant_part and a gdb that can read it.
15 // min-system-llvm-version: 7.0
16 // min-gdb-version: 8.2
22 // gdb-command:print stack_unique.value
24 // gdbr-command:print stack_unique.next.val.value
27 // gdbr-command:print unique_unique.value
29 // gdbr-command:print unique_unique.next.val.value
32 // gdb-command:print vec_unique[0].value
34 // gdbr-command:print vec_unique[0].next.val.value
37 // gdbr-command:print borrowed_unique.value
39 // gdbr-command:print borrowed_unique.next.val.value
43 // gdb-command:print long_cycle1.value
45 // gdbr-command:print long_cycle1.next.value
47 // gdbr-command:print long_cycle1.next.next.value
49 // gdbr-command:print long_cycle1.next.next.next.value
52 // gdb-command:print long_cycle2.value
54 // gdbr-command:print long_cycle2.next.value
56 // gdbr-command:print long_cycle2.next.next.value
59 // gdb-command:print long_cycle3.value
61 // gdbr-command:print long_cycle3.next.value
64 // gdb-command:print long_cycle4.value
65 // gdb-check:$18 = 29.5
67 // gdbr-command:print long_cycle_w_anonymous_types.value
70 // gdbr-command:print long_cycle_w_anonymous_types.next.val.value
73 // gdb-command:continue
75 #![allow(unused_variables)]
76 #![feature(box_syntax)]
77 #![feature(omit_gdb_pretty_printer_section)]
78 #![omit_gdb_pretty_printer_section]
80 use self::Opt::{Empty, Val};
87 struct UniqueNode<T> {
88 next: Opt<Box<UniqueNode<T>>>,
92 struct LongCycle1<T> {
93 next: Box<LongCycle2<T>>,
97 struct LongCycle2<T> {
98 next: Box<LongCycle3<T>>,
102 struct LongCycle3<T> {
103 next: Box<LongCycle4<T>>,
107 struct LongCycle4<T> {
108 next: Option<Box<LongCycle1<T>>>,
112 struct LongCycleWithAnonymousTypes {
113 next: Opt<Box<Box<Box<Box<Box<LongCycleWithAnonymousTypes>>>>>>,
117 // This test case makes sure that recursive structs are properly described. The Node structs are
118 // generic so that we can have a new type (that newly needs to be described) for the different
119 // cases. The potential problem with recursive types is that the DI generation algorithm gets
120 // trapped in an endless loop. To make sure, we actually test this in the different cases, we have
121 // to operate on a new type each time, otherwise we would just hit the DI cache for all but the
124 // The different cases below (stack_*, unique_*, box_*, etc) are set up so that the type description
125 // algorithm will enter the type reference cycle that is created by a recursive definition from a
126 // different context each time.
128 // The "long cycle" cases are constructed to span a longer, indirect recursion cycle between types.
129 // The different locals will cause the DI algorithm to enter the type reference cycle at different
133 let stack_unique: UniqueNode<u16> = UniqueNode {
135 val: box UniqueNode {
143 let unique_unique: Box<UniqueNode<u32>> = box UniqueNode {
145 val: box UniqueNode {
153 let vec_unique: [UniqueNode<f32>; 1] = [UniqueNode {
155 val: box UniqueNode {
163 let borrowed_unique: &UniqueNode<f64> = &UniqueNode {
165 val: box UniqueNode {
174 let long_cycle1: LongCycle1<u16> = LongCycle1 {
175 next: box LongCycle2 {
176 next: box LongCycle3 {
177 next: box LongCycle4 {
188 let long_cycle2: LongCycle2<u32> = LongCycle2 {
189 next: box LongCycle3 {
190 next: box LongCycle4 {
199 let long_cycle3: LongCycle3<u64> = LongCycle3 {
200 next: box LongCycle4 {
207 let long_cycle4: LongCycle4<f32> = LongCycle4 {
212 // It's important that LongCycleWithAnonymousTypes is encountered only at the end of the
214 let long_cycle_w_anonymous_types = box box box box box LongCycleWithAnonymousTypes {
216 val: box box box box box LongCycleWithAnonymousTypes {