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