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(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"))]
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 // Send it through the shape code
86 let y = format!("{:?}", x);
88 println!("align inner = {}", rusti::min_align_of::<Inner>());
89 println!("size outer = {}", mem::size_of::<Outer>());
90 println!("y = {}", y);
92 // per clang/gcc the alignment of `Inner` is 4 on x86.
93 assert_eq!(rusti::min_align_of::<Inner>(), m::m::align());
95 // per clang/gcc the size of `Outer` should be 12
96 // because `Inner`s alignment was 4.
97 assert_eq!(mem::size_of::<Outer>(), m::m::size());
99 assert_eq!(y, "Outer{c8: 22u8, t: Inner{c64: 44u64}}".to_string());