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_arch = "x86")]
37 #[cfg(target_arch = "arm")]
39 pub fn align() -> uint { 4u }
40 pub fn size() -> uint { 8u }
43 #[cfg(target_arch = "x86_64")]
45 pub fn align() -> uint { 4u }
46 pub fn size() -> uint { 8u }
51 let x = Outer {c8: 22u8, t: Inner {c64: 44u32}};
53 // Send it through the shape code
54 let y = format!("{:?}", x);
56 println!("align inner = {:?}", rusti::min_align_of::<Inner>());
57 println!("size outer = {:?}", mem::size_of::<Outer>());
58 println!("y = {}", y);
60 // per clang/gcc the alignment of `inner` is 4 on x86.
61 assert_eq!(rusti::min_align_of::<Inner>(), m::align());
63 // per clang/gcc the size of `outer` should be 12
64 // because `inner`s alignment was 4.
65 assert_eq!(mem::size_of::<Outer>(), m::size());
67 assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u32}}");