blob: 5e2ae478d7db5641629f6f3c75d33dd257cdc11f [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)
Michael Woerister47e8cf72014-10-09 14:31:0313// min-lldb-version: 310
sh8281.kim4e548282013-11-04 06:53:0114
Alex Crichton071ee962014-02-07 03:57:0915// compile-flags:-g
Michael Woeristerc7f45a92014-07-09 12:46:0916
17// === GDB TESTS ===================================================================================
18
Michael Woerister55a8bd52014-04-24 09:35:4819// gdb-command:set print union on
20// gdb-command:rbreak zzz
21// gdb-command:run
22// gdb-command:finish
Michael Woerister70e5c082013-07-11 08:17:3123
Michael Woerister55a8bd52014-04-24 09:35:4824// gdb-command:print case1
Michael Woerister98a0f912014-10-02 13:59:2225// gdb-check:$1 = {{RUST$ENUM$DISR = Case1, 0, {x = 2088533116, y = 2088533116, z = 31868}}, {RUST$ENUM$DISR = Case1, 0, 8970181431921507452, 31868}}
Michael Woerister70e5c082013-07-11 08:17:3126
Michael Woerister55a8bd52014-04-24 09:35:4827// gdb-command:print case2
Michael Woerister98a0f912014-10-02 13:59:2228// gdb-check:$2 = {{RUST$ENUM$DISR = Case2, 0, {x = 286331153, y = 286331153, z = 4369}}, {RUST$ENUM$DISR = Case2, 0, 1229782938247303441, 4369}}
Michael Woerister70e5c082013-07-11 08:17:3129
Michael Woerister55a8bd52014-04-24 09:35:4830// gdb-command:print univariant
Michael Woeristereea329b2014-05-15 13:33:5131// gdb-check:$3 = {{{x = 123, y = 456, z = 789}}}
Michael Woerister70e5c082013-07-11 08:17:3132
Michael Woeristerc7f45a92014-07-09 12:46:0933
34// === LLDB TESTS ==================================================================================
35
36// lldb-command:run
37
38// lldb-command:print case1
39// lldb-check:[...]$0 = Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 })
40// lldb-command:print case2
41// lldb-check:[...]$1 = Case2(0, 1229782938247303441, 4369)
42
43// lldb-command:print univariant
44// lldb-check:[...]$2 = TheOnlyCase(Struct { x: 123, y: 456, z: 789 })
45
Aaron Turone0ad0fc2014-10-27 22:37:0746#![allow(unused_variables)]
Erick Tryzelaarad5c6762013-08-17 15:37:4247
Michael Woerister70e5c082013-07-11 08:17:3148struct Struct {
Derek Guenther730bdb62014-02-05 22:33:1049 x: u32,
50 y: i32,
51 z: i16
Michael Woerister70e5c082013-07-11 08:17:3152}
53
54// The first element is to ensure proper alignment, irrespective of the machines word size. Since
55// the size of the discriminant value is machine dependent, this has be taken into account when
56// datatype layout should be predictable as in this case.
57enum Regular {
58 Case1(u64, Struct),
59 Case2(u64, u64, i16)
60}
61
62enum Univariant {
Derek Guenther730bdb62014-02-05 22:33:1063 TheOnlyCase(Struct)
Michael Woerister70e5c082013-07-11 08:17:3164}
65
66fn main() {
67
68 // In order to avoid endianess trouble all of the following test values consist of a single
69 // repeated byte. This way each interpretation of the union should look the same, no matter if
70 // this is a big or little endian machine.
71
72 // 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452
73 // 0b01111100011111000111110001111100 = 2088533116
74 // 0b0111110001111100 = 31868
75 // 0b01111100 = 124
76 let case1 = Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 });
77
78 // 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
79 // 0b00010001000100010001000100010001 = 286331153
80 // 0b0001000100010001 = 4369
81 // 0b00010001 = 17
82 let case2 = Case2(0, 1229782938247303441, 4369);
83
84 let univariant = TheOnlyCase(Struct { x: 123, y: 456, z: 789 });
85
Michael Woeristerc7f45a92014-07-09 12:46:0986 zzz(); // #break
Michael Woerister70e5c082013-07-11 08:17:3187}
88
89fn zzz() {()}