blob: d01119bce05338ce3c618c8d8feddd3f8259b671 [file] [log] [blame]
Florian Hahnf62460c2014-02-07 19:08:321// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
Michael Woerister70e5c082013-07-11 08:17:312// 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
Florian Hahnf62460c2014-02-07 19:08:3211// ignore-tidy-linelength
12// ignore-android: FIXME(#10381)
sh8281.kim4e548282013-11-04 06:53:0113
Alex Crichton071ee962014-02-07 03:57:0914// compile-flags:-g
Michael Woeristerc7f45a92014-07-09 12:46:0915
16// === GDB TESTS ===================================================================================
17
Michael Woerister55a8bd52014-04-24 09:35:4818// gdb-command:set print union on
19// gdb-command:rbreak zzz
20// gdb-command:run
21// gdb-command:finish
Michael Woerister70e5c082013-07-11 08:17:3122
Michael Woerister55a8bd52014-04-24 09:35:4823// gdb-command:print case1
24// gdb-check:$1 = {{Case1, 0, {x = 2088533116, y = 2088533116, z = 31868}}, {Case1, 0, 8970181431921507452, 31868}}
Michael Woerister70e5c082013-07-11 08:17:3125
Michael Woerister55a8bd52014-04-24 09:35:4826// gdb-command:print case2
27// gdb-check:$2 = {{Case2, 0, {x = 286331153, y = 286331153, z = 4369}}, {Case2, 0, 1229782938247303441, 4369}}
Michael Woerister70e5c082013-07-11 08:17:3128
Michael Woerister55a8bd52014-04-24 09:35:4829// gdb-command:print univariant
Michael Woeristereea329b2014-05-15 13:33:5130// gdb-check:$3 = {{{x = 123, y = 456, z = 789}}}
Michael Woerister70e5c082013-07-11 08:17:3131
Michael Woeristerc7f45a92014-07-09 12:46:0932
33// === LLDB TESTS ==================================================================================
34
35// lldb-command:run
36
37// lldb-command:print case1
38// lldb-check:[...]$0 = Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 })
39// lldb-command:print case2
40// lldb-check:[...]$1 = Case2(0, 1229782938247303441, 4369)
41
42// lldb-command:print univariant
43// lldb-check:[...]$2 = TheOnlyCase(Struct { x: 123, y: 456, z: 789 })
44
Manish Goregaokar713e8752014-04-14 15:30:3145#![allow(unused_variable)]
Erick Tryzelaarad5c6762013-08-17 15:37:4246
Michael Woerister70e5c082013-07-11 08:17:3147struct Struct {
Derek Guenther730bdb62014-02-05 22:33:1048 x: u32,
49 y: i32,
50 z: i16
Michael Woerister70e5c082013-07-11 08:17:3151}
52
53// The first element is to ensure proper alignment, irrespective of the machines word size. Since
54// the size of the discriminant value is machine dependent, this has be taken into account when
55// datatype layout should be predictable as in this case.
56enum Regular {
57 Case1(u64, Struct),
58 Case2(u64, u64, i16)
59}
60
61enum Univariant {
Derek Guenther730bdb62014-02-05 22:33:1062 TheOnlyCase(Struct)
Michael Woerister70e5c082013-07-11 08:17:3163}
64
65fn main() {
66
67 // In order to avoid endianess trouble all of the following test values consist of a single
68 // repeated byte. This way each interpretation of the union should look the same, no matter if
69 // this is a big or little endian machine.
70
71 // 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452
72 // 0b01111100011111000111110001111100 = 2088533116
73 // 0b0111110001111100 = 31868
74 // 0b01111100 = 124
75 let case1 = Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 });
76
77 // 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
78 // 0b00010001000100010001000100010001 = 286331153
79 // 0b0001000100010001 = 4369
80 // 0b00010001 = 17
81 let case2 = Case2(0, 1229782938247303441, 4369);
82
83 let univariant = TheOnlyCase(Struct { x: 123, y: 456, z: 789 });
84
Michael Woeristerc7f45a92014-07-09 12:46:0985 zzz(); // #break
Michael Woerister70e5c082013-07-11 08:17:3186}
87
88fn zzz() {()}