]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/option-like-enum.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / debuginfo / option-like-enum.rs
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.
4 //
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.
10
11 // ignore-tidy-linelength
12 // min-lldb-version: 310
13
14 // compile-flags:-g
15
16 // === GDB TESTS ===================================================================================
17
18 // gdb-command:run
19
20 // gdb-command:print some
21 // gdb-check:$1 = {RUST$ENCODED$ENUM$0$None = {__0 = 0x12345678}}
22
23 // gdb-command:print none
24 // gdb-check:$2 = {RUST$ENCODED$ENUM$0$None = {__0 = 0x0}}
25
26 // gdb-command:print full
27 // gdb-check:$3 = {RUST$ENCODED$ENUM$1$Empty = {__0 = 454545, __1 = 0x87654321, __2 = 9988}}
28
29 // gdb-command:print empty_gdb->discr
30 // gdb-check:$4 = (isize *) 0x0
31
32 // gdb-command:print droid
33 // gdb-check:$5 = {RUST$ENCODED$ENUM$2$Void = {id = 675675, range = 10000001, internals = 0x43218765}}
34
35 // gdb-command:print void_droid_gdb->internals
36 // gdb-check:$6 = (isize *) 0x0
37
38 // gdb-command:print nested_non_zero_yep
39 // gdb-check:$7 = {RUST$ENCODED$ENUM$1$2$Nope = {__0 = 10.5, __1 = {a = 10, b = 20, c = [...]}}}
40
41 // gdb-command:print nested_non_zero_nope
42 // gdb-check:$8 = {RUST$ENCODED$ENUM$1$2$Nope = {__0 = [...], __1 = {a = [...], b = [...], c = 0x0}}}
43
44 // gdb-command:continue
45
46
47 // === LLDB TESTS ==================================================================================
48
49 // lldb-command:run
50
51 // lldb-command:print some
52 // lldb-check:[...]$0 = Some(&0x12345678)
53
54 // lldb-command:print none
55 // lldb-check:[...]$1 = None
56
57 // lldb-command:print full
58 // lldb-check:[...]$2 = Full(454545, &0x87654321, 9988)
59
60 // lldb-command:print empty
61 // lldb-check:[...]$3 = Empty
62
63 // lldb-command:print droid
64 // lldb-check:[...]$4 = Droid { id: 675675, range: 10000001, internals: &0x43218765 }
65
66 // lldb-command:print void_droid
67 // lldb-check:[...]$5 = Void
68
69 // lldb-command:print some_str
70 // lldb-check:[...]$6 = Some("abc")
71
72 // lldb-command:print none_str
73 // lldb-check:[...]$7 = None
74
75 // lldb-command:print nested_non_zero_yep
76 // lldb-check:[...]$8 = Yep(10.5, NestedNonZeroField { a: 10, b: 20, c: &[...] })
77
78 // lldb-command:print nested_non_zero_nope
79 // lldb-check:[...]$9 = Nope
80
81
82 #![feature(omit_gdb_pretty_printer_section)]
83 #![omit_gdb_pretty_printer_section]
84
85 // If a struct has exactly two variants, one of them is empty, and the other one
86 // contains a non-nullable pointer, then this value is used as the discriminator.
87 // The test cases in this file make sure that something readable is generated for
88 // this kind of types.
89 // If the non-empty variant contains a single non-nullable pointer than the whole
90 // item is represented as just a pointer and not wrapped in a struct.
91 // Unfortunately (for these test cases) the content of the non-discriminant fields
92 // in the null-case is not defined. So we just read the discriminator field in
93 // this case (by casting the value to a memory-equivalent struct).
94
95 enum MoreFields<'a> {
96     Full(u32, &'a isize, i16),
97     Empty
98 }
99
100 struct MoreFieldsRepr<'a> {
101     a: u32,
102     discr: &'a isize,
103     b: i16
104 }
105
106 enum NamedFields<'a> {
107     Droid { id: i32, range: i64, internals: &'a isize },
108     Void
109 }
110
111 struct NamedFieldsRepr<'a> {
112     id: i32,
113     range: i64,
114     internals: &'a isize
115 }
116
117 struct NestedNonZeroField<'a> {
118     a: u16,
119     b: u32,
120     c: &'a char,
121 }
122
123 enum NestedNonZero<'a> {
124     Yep(f64, NestedNonZeroField<'a>),
125     Nope
126 }
127
128 fn main() {
129
130     let some_str: Option<&'static str> = Some("abc");
131     let none_str: Option<&'static str> = None;
132
133     let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678_usize) });
134     let none: Option<&u32> = None;
135
136     let full = MoreFields::Full(454545, unsafe { std::mem::transmute(0x87654321_usize) }, 9988);
137
138     let empty = MoreFields::Empty;
139     let empty_gdb: &MoreFieldsRepr = unsafe { std::mem::transmute(&MoreFields::Empty) };
140
141     let droid = NamedFields::Droid {
142         id: 675675,
143         range: 10000001,
144         internals: unsafe { std::mem::transmute(0x43218765_usize) }
145     };
146
147     let void_droid = NamedFields::Void;
148     let void_droid_gdb: &NamedFieldsRepr = unsafe { std::mem::transmute(&NamedFields::Void) };
149
150     let x = 'x';
151     let nested_non_zero_yep = NestedNonZero::Yep(
152         10.5,
153         NestedNonZeroField {
154             a: 10,
155             b: 20,
156             c: &x
157         });
158
159     let nested_non_zero_nope = NestedNonZero::Nope;
160
161     zzz(); // #break
162 }
163
164 fn zzz() {()}