]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
1 | // Copyright 2012 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 | // Issue #2303 | |
12 | ||
13 | mod rusti { | |
14 | #[abi = "rust-intrinsic"] | |
15 | pub extern "rust-intrinsic" { | |
16 | pub fn pref_align_of<T>() -> uint; | |
17 | pub fn min_align_of<T>() -> uint; | |
18 | } | |
19 | } | |
20 | ||
21 | // This is the type with the questionable alignment | |
22 | struct Inner { | |
23 | c64: u64 | |
24 | } | |
25 | ||
26 | // This is the type that contains the type with the | |
27 | // questionable alignment, for testing | |
28 | struct Outer { | |
29 | c8: u8, | |
30 | t: Inner | |
31 | } | |
32 | ||
33 | ||
34 | #[cfg(target_os = "linux")] | |
35 | #[cfg(target_os = "macos")] | |
36 | #[cfg(target_os = "freebsd")] | |
37 | mod m { | |
38 | #[cfg(target_arch = "x86")] | |
39 | pub mod m { | |
40 | pub fn align() -> uint { 4u } | |
41 | pub fn size() -> uint { 12u } | |
42 | } | |
43 | ||
44 | #[cfg(target_arch = "x86_64")] | |
45 | mod m { | |
46 | pub fn align() -> uint { 8u } | |
47 | pub fn size() -> uint { 16u } | |
48 | } | |
49 | } | |
50 | ||
51 | #[cfg(target_os = "win32")] | |
52 | mod m { | |
53 | #[cfg(target_arch = "x86")] | |
54 | pub mod m { | |
55 | pub fn align() -> uint { 8u } | |
56 | pub fn size() -> uint { 16u } | |
57 | } | |
58 | } | |
59 | ||
60 | pub fn main() { | |
61 | unsafe { | |
62 | let x = Outer {c8: 22u8, t: Inner {c64: 44u64}}; | |
63 | ||
64 | // Send it through the shape code | |
65 | let y = fmt!("%?", x); | |
66 | ||
67 | debug!("align inner = %?", rusti::min_align_of::<Inner>()); | |
68 | debug!("size outer = %?", sys::size_of::<Outer>()); | |
69 | debug!("y = %s", y); | |
70 | ||
71 | // per clang/gcc the alignment of `Inner` is 4 on x86. | |
72 | assert!(rusti::min_align_of::<Inner>() == m::m::align()); | |
73 | ||
74 | // per clang/gcc the size of `Outer` should be 12 | |
75 | // because `Inner`s alignment was 4. | |
76 | assert!(sys::size_of::<Outer>() == m::m::size()); | |
77 | ||
78 | assert!(y == ~"{c8: 22, t: {c64: 44}}"); | |
79 | } | |
80 | } |