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.
17 extern "rust-intrinsic" {
18 pub fn pref_align_of<T>() -> uint;
19 pub fn min_align_of<T>() -> uint;
23 // This is the type with the questionable alignment
28 // This is the type that contains the type with the
29 // questionable alignment, for testing
36 #[cfg(target_os = "linux")]
37 #[cfg(target_os = "macos")]
38 #[cfg(target_os = "freebsd")]
40 #[cfg(target_arch = "x86")]
42 pub fn align() -> uint { 4u }
43 pub fn size() -> uint { 12u }
46 #[cfg(target_arch = "x86_64")]
48 pub fn align() -> uint { 8u }
49 pub fn size() -> uint { 16u }
53 #[cfg(target_os = "win32")]
55 #[cfg(target_arch = "x86")]
57 pub fn align() -> uint { 8u }
58 pub fn size() -> uint { 16u }
62 #[cfg(target_os = "android")]
64 #[cfg(target_arch = "arm")]
66 pub fn align() -> uint { 8u }
67 pub fn size() -> uint { 16u }
73 let x = Outer {c8: 22u8, t: Inner {c64: 44u64}};
75 // Send it through the shape code
76 let y = format!("{:?}", x);
78 println!("align inner = {}", rusti::min_align_of::<Inner>());
79 println!("size outer = {}", mem::size_of::<Outer>());
80 println!("y = {}", y);
82 // per clang/gcc the alignment of `Inner` is 4 on x86.
83 assert_eq!(rusti::min_align_of::<Inner>(), m::m::align());
85 // per clang/gcc the size of `Outer` should be 12
86 // because `Inner`s alignment was 4.
87 assert_eq!(mem::size_of::<Outer>(), m::m::size());
89 assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u64}}");