Florian Hahn | f62460c | 2014-02-07 19:08:32 | [diff] [blame] | 1 | // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 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 | |
Florian Hahn | f62460c | 2014-02-07 19:08:32 | [diff] [blame] | 11 | // ignore-tidy-linelength |
| 12 | // ignore-android: FIXME(#10381) |
sh8281.kim | 4e54828 | 2013-11-04 06:53:01 | [diff] [blame] | 13 | |
Alex Crichton | 071ee96 | 2014-02-07 03:57:09 | [diff] [blame] | 14 | // compile-flags:-g |
Michael Woerister | c7f45a9 | 2014-07-09 12:46:09 | [diff] [blame^] | 15 | |
| 16 | // === GDB TESTS =================================================================================== |
| 17 | |
Michael Woerister | 55a8bd5 | 2014-04-24 09:35:48 | [diff] [blame] | 18 | // gdb-command:set print union on |
| 19 | // gdb-command:rbreak zzz |
| 20 | // gdb-command:run |
| 21 | // gdb-command:finish |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 22 | |
Michael Woerister | 55a8bd5 | 2014-04-24 09:35:48 | [diff] [blame] | 23 | // gdb-command:print case1 |
| 24 | // gdb-check:$1 = {{Case1, 0, {x = 2088533116, y = 2088533116, z = 31868}}, {Case1, 0, 8970181431921507452, 31868}} |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 25 | |
Michael Woerister | 55a8bd5 | 2014-04-24 09:35:48 | [diff] [blame] | 26 | // gdb-command:print case2 |
| 27 | // gdb-check:$2 = {{Case2, 0, {x = 286331153, y = 286331153, z = 4369}}, {Case2, 0, 1229782938247303441, 4369}} |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 28 | |
Michael Woerister | 55a8bd5 | 2014-04-24 09:35:48 | [diff] [blame] | 29 | // gdb-command:print univariant |
Michael Woerister | eea329b | 2014-05-15 13:33:51 | [diff] [blame] | 30 | // gdb-check:$3 = {{{x = 123, y = 456, z = 789}}} |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 31 | |
Michael Woerister | c7f45a9 | 2014-07-09 12:46:09 | [diff] [blame^] | 32 | |
| 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 Goregaokar | 713e875 | 2014-04-14 15:30:31 | [diff] [blame] | 45 | #![allow(unused_variable)] |
Erick Tryzelaar | ad5c676 | 2013-08-17 15:37:42 | [diff] [blame] | 46 | |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 47 | struct Struct { |
Derek Guenther | 730bdb6 | 2014-02-05 22:33:10 | [diff] [blame] | 48 | x: u32, |
| 49 | y: i32, |
| 50 | z: i16 |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 51 | } |
| 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. |
| 56 | enum Regular { |
| 57 | Case1(u64, Struct), |
| 58 | Case2(u64, u64, i16) |
| 59 | } |
| 60 | |
| 61 | enum Univariant { |
Derek Guenther | 730bdb6 | 2014-02-05 22:33:10 | [diff] [blame] | 62 | TheOnlyCase(Struct) |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | fn 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 Woerister | c7f45a9 | 2014-07-09 12:46:09 | [diff] [blame^] | 85 | zzz(); // #break |
Michael Woerister | 70e5c08 | 2013-07-11 08:17:31 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | fn zzz() {()} |