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.
11 // ignore-wasm32-bare seems unimportant to test
15 #![feature(intrinsics)]
20 extern "rust-intrinsic" {
21 pub fn pref_align_of
<T
>() -> usize;
22 pub fn min_align_of
<T
>() -> usize;
26 // This is the type with the questionable alignment
32 // This is the type that contains the type with the
33 // questionable alignment, for testing
41 #[cfg(any(target_os = "linux",
43 target_os
= "freebsd",
44 target_os
= "dragonfly",
46 target_os
= "openbsd",
47 target_os
= "solaris",
48 target_os
= "emscripten"))]
50 #[cfg(target_arch = "x86")]
52 pub fn align() -> usize { 4 }
53 pub fn size() -> usize { 12 }
56 #[cfg(not(target_arch = "x86"))]
58 pub fn align() -> usize { 8 }
59 pub fn size() -> usize { 16 }
63 #[cfg(target_os = "bitrig")]
65 #[cfg(target_arch = "x86_64")]
67 pub fn align() -> usize { 8 }
68 pub fn size() -> usize { 16 }
72 #[cfg(target_os = "windows")]
74 #[cfg(target_arch = "x86")]
76 pub fn align() -> usize { 8 }
77 pub fn size() -> usize { 16 }
80 #[cfg(target_arch = "x86_64")]
82 pub fn align() -> usize { 8 }
83 pub fn size() -> usize { 16 }
87 #[cfg(target_os = "android")]
89 #[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
91 pub fn align() -> usize { 8 }
92 pub fn size() -> usize { 16 }
98 let x
= Outer {c8: 22, t: Inner {c64: 44}
};
100 let y
= format
!("{:?}", x
);
102 println
!("align inner = {:?}", rusti
::min_align_of
::<Inner
>());
103 println
!("size outer = {:?}", mem
::size_of
::<Outer
>());
104 println
!("y = {:?}", y
);
106 // per clang/gcc the alignment of `Inner` is 4 on x86.
107 assert_eq
!(rusti
::min_align_of
::<Inner
>(), m
::m
::align());
109 // per clang/gcc the size of `Outer` should be 12
110 // because `Inner`s alignment was 4.
111 assert_eq
!(mem
::size_of
::<Outer
>(), m
::m
::size());
113 assert_eq
!(y
, "Outer { c8: 22, t: Inner { c64: 44 } }".to_string());