1 // Copyright 2012-2014 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.
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.
13 #![feature(intrinsics)]
20 extern "rust-intrinsic" {
21 pub fn pref_align_of<T>() -> uint;
22 pub fn min_align_of<T>() -> uint;
26 // This is the type with the questionable alignment
31 // This is the type that contains the type with the
32 // questionable alignment, for testing
39 #[cfg(target_os = "linux")]
40 #[cfg(target_os = "macos")]
41 #[cfg(target_os = "freebsd")]
43 #[cfg(target_arch = "x86")]
45 pub fn align() -> uint { 4u }
46 pub fn size() -> uint { 12u }
49 #[cfg(target_arch = "x86_64")]
51 pub fn align() -> uint { 8u }
52 pub fn size() -> uint { 16u }
56 #[cfg(target_os = "win32")]
58 #[cfg(target_arch = "x86")]
60 pub fn align() -> uint { 8u }
61 pub fn size() -> uint { 16u }
65 #[cfg(target_os = "android")]
67 #[cfg(target_arch = "arm")]
69 pub fn align() -> uint { 8u }
70 pub fn size() -> uint { 16u }
76 let x = Outer {c8: 22u8, t: Inner {c64: 44u64}};
78 // Send it through the shape code
79 let y = format!("{:?}", x);
81 println!("align inner = {}", rusti::min_align_of::<Inner>());
82 println!("size outer = {}", mem::size_of::<Outer>());
83 println!("y = {}", y);
85 // per clang/gcc the alignment of `Inner` is 4 on x86.
86 assert_eq!(rusti::min_align_of::<Inner>(), m::m::align());
88 // per clang/gcc the size of `Outer` should be 12
89 // because `Inner`s alignment was 4.
90 assert_eq!(mem::size_of::<Outer>(), m::m::size());
92 assert_eq!(y, "Outer{c8: 22u8, t: Inner{c64: 44u64}}".to_string());