blob: 0d3883f1102e23a76528d46eec2182c0b1ba4597 [file] [log] [blame]
Michael Woerister99ebb812013-07-01 10:11:291// 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
Derek Guenther730bdb62014-02-05 22:33:1011// xfail-tidy-linelength
Young-il Choica553172013-11-09 07:16:4412// xfail-android: FIXME(#10381)
sh8281.kim4e548282013-11-04 06:53:0113
Alex Crichton071ee962014-02-07 03:57:0914// compile-flags:-g
Michael Woerister99ebb812013-07-01 10:11:2915// debugger:set print pretty off
Michael Woerister93d63282013-09-06 14:00:0816// debugger:rbreak zzz
Michael Woerister99ebb812013-07-01 10:11:2917// debugger:run
18// debugger:finish
19
20// debugger:print packed
21// check:$1 = {x = 123, y = 234, z = 345}
22
23// debugger:print packedInPacked
24// check:$2 = {a = 1111, b = {x = 2222, y = 3333, z = 4444}, c = 5555, d = {x = 6666, y = 7777, z = 8888}}
25
26// debugger:print packedInUnpacked
27// check:$3 = {a = -1111, b = {x = -2222, y = -3333, z = -4444}, c = -5555, d = {x = -6666, y = -7777, z = -8888}}
28
29// debugger:print unpackedInPacked
30// check:$4 = {a = 987, b = {x = 876, y = 765, z = 654, w = 543}, c = {x = 432, y = 321, z = 210, w = 109}, d = -98}
31
32// debugger:print sizeof(packed)
33// check:$5 = 14
34
35// debugger:print sizeof(packedInPacked)
36// check:$6 = 40
37
Erick Tryzelaarad5c6762013-08-17 15:37:4238#[allow(unused_variable)];
39
Michael Woerister99ebb812013-07-01 10:11:2940#[packed]
41struct Packed {
42 x: i16,
43 y: i32,
44 z: i64
45}
46
47#[packed]
48struct PackedInPacked {
49 a: i32,
50 b: Packed,
51 c: i64,
52 d: Packed
53}
54
Michael Woeristera1303cc2013-07-20 08:47:2455// layout (64 bit): aaaa bbbb bbbb bbbb bb.. .... cccc cccc dddd dddd dddd dd..
Michael Woerister99ebb812013-07-01 10:11:2956struct PackedInUnpacked {
57 a: i32,
58 b: Packed,
59 c: i64,
60 d: Packed
61}
62
Michael Woeristera1303cc2013-07-20 08:47:2463// layout (64 bit): xx.. yyyy zz.. .... wwww wwww
Michael Woerister99ebb812013-07-01 10:11:2964struct Unpacked {
65 x: i16,
66 y: i32,
67 z: i16,
68 w: i64
69}
70
Michael Woeristera1303cc2013-07-20 08:47:2471// layout (64 bit): aabb bbbb bbbb bbbb bbbb bbbb bbcc cccc cccc cccc cccc cccc ccdd dddd dd
Michael Woerister99ebb812013-07-01 10:11:2972#[packed]
73struct UnpackedInPacked {
74 a: i16,
75 b: Unpacked,
76 c: Unpacked,
77 d: i64
78}
79
80fn main() {
81 let packed = Packed { x: 123, y: 234, z: 345 };
82
83 let packedInPacked = PackedInPacked {
84 a: 1111,
85 b: Packed { x: 2222, y: 3333, z: 4444 },
86 c: 5555,
87 d: Packed { x: 6666, y: 7777, z: 8888 }
88 };
89
90 let packedInUnpacked = PackedInUnpacked {
91 a: -1111,
92 b: Packed { x: -2222, y: -3333, z: -4444 },
93 c: -5555,
94 d: Packed { x: -6666, y: -7777, z: -8888 }
95 };
96
97 let unpackedInPacked = UnpackedInPacked {
98 a: 987,
99 b: Unpacked { x: 876, y: 765, z: 654, w: 543 },
100 c: Unpacked { x: 432, y: 321, z: 210, w: 109 },
101 d: -98
102 };
103
104 zzz();
105}
106
Erick Tryzelaarad5c6762013-08-17 15:37:42107fn zzz() {()}