2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(unused_unsafe)]
|
2012-04-27 00:49:38 +00:00
|
|
|
// Issue #2303
|
|
|
|
|
2014-06-20 23:39:23 +00:00
|
|
|
#![feature(intrinsics)]
|
|
|
|
|
2013-10-17 01:34:01 +00:00
|
|
|
use std::mem;
|
2013-05-25 02:35:29 +00:00
|
|
|
|
2013-03-05 22:42:58 +00:00
|
|
|
mod rusti {
|
2013-07-19 02:08:57 +00:00
|
|
|
extern "rust-intrinsic" {
|
2015-03-26 00:06:52 +00:00
|
|
|
pub fn pref_align_of<T>() -> usize;
|
2022-08-18 09:15:26 +00:00
|
|
|
#[rustc_safe_intrinsic]
|
2015-03-26 00:06:52 +00:00
|
|
|
pub fn min_align_of<T>() -> usize;
|
2013-03-05 22:42:58 +00:00
|
|
|
}
|
2012-04-27 06:39:44 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 00:49:38 +00:00
|
|
|
// This is the type with the questionable alignment
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2013-01-26 06:46:32 +00:00
|
|
|
struct Inner {
|
2012-04-30 23:44:34 +00:00
|
|
|
c64: u32
|
2013-01-26 06:46:32 +00:00
|
|
|
}
|
2012-04-27 00:49:38 +00:00
|
|
|
|
|
|
|
// This is the type that contains the type with the
|
|
|
|
// questionable alignment, for testing
|
2015-01-20 23:45:07 +00:00
|
|
|
#[derive(Debug)]
|
2013-01-26 06:46:32 +00:00
|
|
|
struct Outer {
|
2012-04-27 00:49:38 +00:00
|
|
|
c8: u8,
|
2013-01-26 06:46:32 +00:00
|
|
|
t: Inner
|
|
|
|
}
|
2012-04-27 00:49:38 +00:00
|
|
|
|
2012-04-30 23:44:34 +00:00
|
|
|
mod m {
|
2015-03-26 00:06:52 +00:00
|
|
|
pub fn align() -> usize { 4 }
|
|
|
|
pub fn size() -> usize { 8 }
|
2012-04-30 23:44:34 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2013-01-24 00:29:31 +00:00
|
|
|
unsafe {
|
2015-03-03 08:42:26 +00:00
|
|
|
let x = Outer {c8: 22, t: Inner {c64: 44}};
|
2012-04-27 00:49:38 +00:00
|
|
|
|
2013-01-24 00:29:31 +00:00
|
|
|
// Send it through the shape code
|
2014-12-20 08:09:35 +00:00
|
|
|
let y = format!("{:?}", x);
|
2012-04-27 00:49:38 +00:00
|
|
|
|
2014-12-20 08:09:35 +00:00
|
|
|
println!("align inner = {:?}", rusti::min_align_of::<Inner>());
|
|
|
|
println!("size outer = {:?}", mem::size_of::<Outer>());
|
|
|
|
println!("y = {:?}", y);
|
2012-04-27 00:49:38 +00:00
|
|
|
|
2013-01-24 00:29:31 +00:00
|
|
|
// per clang/gcc the alignment of `inner` is 4 on x86.
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(rusti::min_align_of::<Inner>(), m::align());
|
2012-04-27 00:49:38 +00:00
|
|
|
|
2013-01-24 00:29:31 +00:00
|
|
|
// per clang/gcc the size of `outer` should be 12
|
|
|
|
// because `inner`s alignment was 4.
|
2013-10-17 01:34:01 +00:00
|
|
|
assert_eq!(mem::size_of::<Outer>(), m::size());
|
2012-04-27 00:49:38 +00:00
|
|
|
|
2015-01-20 23:45:07 +00:00
|
|
|
assert_eq!(y, "Outer { c8: 22, t: Inner { c64: 44 } }".to_string());
|
2013-01-24 00:29:31 +00:00
|
|
|
}
|
2012-04-27 00:49:38 +00:00
|
|
|
}
|