]> git.lizzy.rs Git - rust.git/blob - src/test/debuginfo/generic-tuple-style-enum.rs
Rollup merge of #59432 - phansch:compiletest_docs, r=alexcrichton
[rust.git] / src / test / debuginfo / generic-tuple-style-enum.rs
1 // ignore-tidy-linelength
2
3 // Require LLVM with DW_TAG_variant_part and a gdb and lldb that can
4 // read it.
5 // min-system-llvm-version: 8.0
6 // min-gdb-version: 8.2
7 // rust-lldb
8
9 // compile-flags:-g
10
11 // === GDB TESTS ===================================================================================
12
13 // gdb-command:set print union on
14 // gdb-command:run
15
16 // gdb-command:print case1
17 // gdbr-check:$1 = generic_tuple_style_enum::Regular<u16, u32, u64>::Case1(0, 31868, 31868, 31868, 31868)
18
19 // gdb-command:print case2
20 // gdbr-check:$2 = generic_tuple_style_enum::Regular<i16, i32, i64>::Case2(0, 286331153, 286331153)
21
22 // gdb-command:print case3
23 // gdbr-check:$3 = generic_tuple_style_enum::Regular<i16, i32, i64>::Case3(0, 6438275382588823897)
24
25 // gdb-command:print univariant
26 // gdbr-check:$4 = generic_tuple_style_enum::Univariant<i64>::TheOnlyCase(-1)
27
28
29 // === LLDB TESTS ==================================================================================
30
31 // lldb-command:run
32
33 // lldb-command:print case1
34 // lldbr-check:(generic_tuple_style_enum::Regular<u16, u32, u64>::Case1) case1 = { __0 = 0 __1 = 31868 __2 = 31868 __3 = 31868 __4 = 31868 }
35
36 // lldb-command:print case2
37 // lldbr-check:(generic_tuple_style_enum::Regular<i16, i32, i64>::Case2) case2 = Regular<i16, i32, i64>::Case2 { Case1: 0, Case2: 286331153, Case3: 286331153 }
38
39 // lldb-command:print case3
40 // lldbr-check:(generic_tuple_style_enum::Regular<i16, i32, i64>::Case3) case3 = Regular<i16, i32, i64>::Case3 { Case1: 0, Case2: 6438275382588823897 }
41
42 // lldb-command:print univariant
43 // lldbr-check:(generic_tuple_style_enum::Univariant<i64>) univariant = Univariant<i64> { TheOnlyCase: Univariant<i64>::TheOnlyCase(-1) }
44
45 #![feature(omit_gdb_pretty_printer_section)]
46 #![omit_gdb_pretty_printer_section]
47
48 use self::Regular::{Case1, Case2, Case3};
49 use self::Univariant::TheOnlyCase;
50
51 // NOTE: This is a copy of the non-generic test case. The `Txx` type parameters have to be
52 // substituted with something of size `xx` bits and the same alignment as an integer type of the
53 // same size.
54
55 // The first element is to ensure proper alignment, irrespective of the machines word size. Since
56 // the size of the discriminant value is machine dependent, this has be taken into account when
57 // datatype layout should be predictable as in this case.
58 enum Regular<T16, T32, T64> {
59     Case1(T64, T16, T16, T16, T16),
60     Case2(T64, T32, T32),
61     Case3(T64, T64)
62 }
63
64 enum Univariant<T64> {
65     TheOnlyCase(T64)
66 }
67
68 fn main() {
69
70     // In order to avoid endianness trouble all of the following test values consist of a single
71     // repeated byte. This way each interpretation of the union should look the same, no matter if
72     // this is a big or little endian machine.
73
74     // 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452
75     // 0b01111100011111000111110001111100 = 2088533116
76     // 0b0111110001111100 = 31868
77     // 0b01111100 = 124
78     let case1: Regular<u16, u32, u64> = Case1(0_u64, 31868_u16, 31868_u16, 31868_u16, 31868_u16);
79
80     // 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
81     // 0b00010001000100010001000100010001 = 286331153
82     // 0b0001000100010001 = 4369
83     // 0b00010001 = 17
84     let case2: Regular<i16, i32, i64> = Case2(0_i64, 286331153_i32, 286331153_i32);
85
86     // 0b0101100101011001010110010101100101011001010110010101100101011001 = 6438275382588823897
87     // 0b01011001010110010101100101011001 = 1499027801
88     // 0b0101100101011001 = 22873
89     // 0b01011001 = 89
90     let case3: Regular<i16, i32, i64> = Case3(0_i64, 6438275382588823897_i64);
91
92     let univariant = TheOnlyCase(-1_i64);
93
94     zzz(); // #break
95 }
96
97 fn zzz() { () }