]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs-enums/rec-align-u64.rs
Pin panic-in-drop=abort test to old pass manager
[rust.git] / src / test / ui / structs-enums / rec-align-u64.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_unsafe)]
4 // ignore-wasm32-bare seems unimportant to test
5
6 // Issue #2303
7
8 #![feature(intrinsics)]
9
10 use std::mem;
11
12 mod rusti {
13     extern "rust-intrinsic" {
14         pub fn pref_align_of<T>() -> usize;
15         pub fn min_align_of<T>() -> usize;
16     }
17 }
18
19 // This is the type with the questionable alignment
20 #[derive(Debug)]
21 struct Inner {
22     c64: u64
23 }
24
25 // This is the type that contains the type with the
26 // questionable alignment, for testing
27 #[derive(Debug)]
28 struct Outer {
29     c8: u8,
30     t: Inner
31 }
32
33
34 #[cfg(any(target_os = "android",
35           target_os = "dragonfly",
36           target_os = "emscripten",
37           target_os = "freebsd",
38           target_os = "fuchsia",
39           target_os = "linux",
40           target_os = "macos",
41           target_os = "netbsd",
42           target_os = "openbsd",
43           target_os = "solaris",
44           target_os = "vxworks"))]
45 mod m {
46     #[cfg(target_arch = "x86")]
47     pub mod m {
48         pub fn align() -> usize { 4 }
49         pub fn size() -> usize { 12 }
50     }
51
52     #[cfg(not(target_arch = "x86"))]
53     pub mod m {
54         pub fn align() -> usize { 8 }
55         pub fn size() -> usize { 16 }
56     }
57 }
58
59 #[cfg(target_env = "sgx")]
60 mod m {
61     #[cfg(target_arch = "x86_64")]
62     pub mod m {
63         pub fn align() -> usize { 8 }
64         pub fn size() -> usize { 16 }
65     }
66 }
67
68 #[cfg(target_os = "windows")]
69 mod m {
70     pub mod m {
71         pub fn align() -> usize { 8 }
72         pub fn size() -> usize { 16 }
73     }
74 }
75
76 pub fn main() {
77     unsafe {
78         let x = Outer {c8: 22, t: Inner {c64: 44}};
79
80         let y = format!("{:?}", x);
81
82         println!("align inner = {:?}", rusti::min_align_of::<Inner>());
83         println!("size outer = {:?}", mem::size_of::<Outer>());
84         println!("y = {:?}", y);
85
86         // per clang/gcc the alignment of `Inner` is 4 on x86.
87         assert_eq!(rusti::min_align_of::<Inner>(), m::m::align());
88
89         // per clang/gcc the size of `Outer` should be 12
90         // because `Inner`s alignment was 4.
91         assert_eq!(mem::size_of::<Outer>(), m::m::size());
92
93         assert_eq!(y, "Outer { c8: 22, t: Inner { c64: 44 } }".to_string());
94     }
95 }