1 // Copyright 2012-2015 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)]
18 extern "rust-intrinsic" {
19 pub fn pref_align_of<T>() -> uint;
20 pub fn min_align_of<T>() -> uint;
24 // This is the type with the questionable alignment
30 // This is the type that contains the type with the
31 // questionable alignment, for testing
39 #[cfg(any(target_os = "linux",
41 target_os = "freebsd",
42 target_os = "dragonfly"))]
44 #[cfg(target_arch = "x86")]
46 pub fn align() -> uint { 4u }
47 pub fn size() -> uint { 12u }
50 #[cfg(any(target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))]
52 pub fn align() -> uint { 8u }
53 pub fn size() -> uint { 16u }
57 #[cfg(target_os = "windows")]
59 #[cfg(target_arch = "x86")]
61 pub fn align() -> uint { 8u }
62 pub fn size() -> uint { 16u }
65 #[cfg(target_arch = "x86_64")]
67 pub fn align() -> uint { 8u }
68 pub fn size() -> uint { 16u }
72 #[cfg(target_os = "android")]
74 #[cfg(target_arch = "arm")]
76 pub fn align() -> uint { 8u }
77 pub fn size() -> uint { 16u }
83 let x = Outer {c8: 22u8, t: Inner {c64: 44u64}};
85 let y = format!("{:?}", x);
87 println!("align inner = {:?}", rusti::min_align_of::<Inner>());
88 println!("size outer = {:?}", mem::size_of::<Outer>());
89 println!("y = {:?}", y);
91 // per clang/gcc the alignment of `Inner` is 4 on x86.
92 assert_eq!(rusti::min_align_of::<Inner>(), m::m::align());
94 // per clang/gcc the size of `Outer` should be 12
95 // because `Inner`s alignment was 4.
96 assert_eq!(mem::size_of::<Outer>(), m::m::size());
98 assert_eq!(y, "Outer { c8: 22, t: Inner { c64: 44 } }".to_string());