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
>() -> usize;
20 pub fn min_align_of
<T
>() -> usize;
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",
43 target_os
= "openbsd"))]
45 #[cfg(target_arch = "x86")]
47 pub fn align() -> usize { 4 }
48 pub fn size() -> usize { 12 }
51 #[cfg(any(target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))]
53 pub fn align() -> usize { 8 }
54 pub fn size() -> usize { 16 }
58 #[cfg(target_os = "bitrig")]
60 #[cfg(target_arch = "x86_64")]
62 pub fn align() -> usize { 8 }
63 pub fn size() -> usize { 16 }
67 #[cfg(target_os = "windows")]
69 #[cfg(target_arch = "x86")]
71 pub fn align() -> usize { 8 }
72 pub fn size() -> usize { 16 }
75 #[cfg(target_arch = "x86_64")]
77 pub fn align() -> usize { 8 }
78 pub fn size() -> usize { 16 }
82 #[cfg(target_os = "android")]
84 #[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
86 pub fn align() -> usize { 8 }
87 pub fn size() -> usize { 16 }
93 let x
= Outer {c8: 22, t: Inner {c64: 44}
};
95 let y
= format
!("{:?}", x
);
97 println
!("align inner = {:?}", rusti
::min_align_of
::<Inner
>());
98 println
!("size outer = {:?}", mem
::size_of
::<Outer
>());
99 println
!("y = {:?}", y
);
101 // per clang/gcc the alignment of `Inner` is 4 on x86.
102 assert_eq
!(rusti
::min_align_of
::<Inner
>(), m
::m
::align());
104 // per clang/gcc the size of `Outer` should be 12
105 // because `Inner`s alignment was 4.
106 assert_eq
!(mem
::size_of
::<Outer
>(), m
::m
::size());
108 assert_eq
!(y
, "Outer { c8: 22, t: Inner { c64: 44 } }".to_string());