blob: c8ad621f6f0d49dab3276914737e70df4ca9ab87 [file] [log] [blame]
Michael Woerister70e5c082013-07-11 08:17:311// Copyright 2013 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// compile-flags:-Z extra-debug-info
12// debugger:set print union on
13// debugger:break zzz
14// debugger:run
15// debugger:finish
16
17// debugger:print case1
18// check:$1 = {{Case1, 0, {x = 2088533116, y = 2088533116, z = 31868}}, {Case1, 0, 8970181431921507452, 31868}}
19
20// debugger:print case2
21// check:$2 = {{Case2, 0, {x = 286331153, y = 286331153, z = 4369}}, {Case2, 0, 1229782938247303441, 4369}}
22
23// debugger:print univariant
24// check:$3 = {{{x = 123, y = 456, z = 789}}}
25
26struct Struct {
27 x: u32,
28 y: i32,
29 z: i16
30}
31
32// The first element is to ensure proper alignment, irrespective of the machines word size. Since
33// the size of the discriminant value is machine dependent, this has be taken into account when
34// datatype layout should be predictable as in this case.
35enum Regular {
36 Case1(u64, Struct),
37 Case2(u64, u64, i16)
38}
39
40enum Univariant {
41 TheOnlyCase(Struct)
42}
43
44fn main() {
45
46 // In order to avoid endianess trouble all of the following test values consist of a single
47 // repeated byte. This way each interpretation of the union should look the same, no matter if
48 // this is a big or little endian machine.
49
50 // 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452
51 // 0b01111100011111000111110001111100 = 2088533116
52 // 0b0111110001111100 = 31868
53 // 0b01111100 = 124
54 let case1 = Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 });
55
56 // 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
57 // 0b00010001000100010001000100010001 = 286331153
58 // 0b0001000100010001 = 4369
59 // 0b00010001 = 17
60 let case2 = Case2(0, 1229782938247303441, 4369);
61
62 let univariant = TheOnlyCase(Struct { x: 123, y: 456, z: 789 });
63
64 zzz();
65}
66
67fn zzz() {()}