2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2018-08-31 13:02:01 +00:00
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
2013-10-17 01:34:01 +00:00
|
|
|
use std::mem;
|
2013-05-25 02:35:29 +00:00
|
|
|
|
2014-05-27 06:56:52 +00:00
|
|
|
#[repr(packed)]
|
2018-02-04 11:10:28 +00:00
|
|
|
struct P1S4(u8,[u8; 3]);
|
|
|
|
|
|
|
|
#[repr(packed(2))]
|
|
|
|
struct P2S4(u8,[u8; 3]);
|
2013-04-10 13:47:53 +00:00
|
|
|
|
2014-05-27 06:56:52 +00:00
|
|
|
#[repr(packed)]
|
2018-02-04 11:10:28 +00:00
|
|
|
struct P1S5(u8, u32);
|
|
|
|
|
|
|
|
#[repr(packed(2))]
|
|
|
|
struct P2S6(u8, u32);
|
2013-04-10 13:47:53 +00:00
|
|
|
|
2014-05-27 06:56:52 +00:00
|
|
|
#[repr(packed)]
|
2018-02-04 11:10:28 +00:00
|
|
|
struct P1S13(i64, f32, u8);
|
|
|
|
|
|
|
|
#[repr(packed(2))]
|
|
|
|
struct P2S14(i64, f32, u8);
|
|
|
|
|
|
|
|
#[repr(packed(4))]
|
|
|
|
struct P4S16(u8, f32, i64, u16);
|
|
|
|
|
|
|
|
#[repr(C, packed(4))]
|
|
|
|
struct P4CS20(u8, f32, i64, u16);
|
2013-04-10 13:47:53 +00:00
|
|
|
|
|
|
|
enum Foo {
|
|
|
|
Bar = 1,
|
|
|
|
Baz = 2
|
|
|
|
}
|
|
|
|
|
2014-05-27 06:56:52 +00:00
|
|
|
#[repr(packed)]
|
2018-02-04 11:10:28 +00:00
|
|
|
struct P1S3_Foo(u8, u16, Foo);
|
|
|
|
|
|
|
|
#[repr(packed(2))]
|
|
|
|
struct P2_Foo(Foo);
|
|
|
|
|
|
|
|
#[repr(packed(2))]
|
|
|
|
struct P2S3_Foo(u8, u16, Foo);
|
2013-04-10 13:47:53 +00:00
|
|
|
|
2014-05-27 06:56:52 +00:00
|
|
|
#[repr(packed)]
|
2018-02-04 11:10:28 +00:00
|
|
|
struct P1S7_Option(f32, u8, u16, Option<Box<f64>>);
|
2013-04-10 13:47:53 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
#[repr(packed(2))]
|
|
|
|
struct P2_Option(Option<Box<f64>>);
|
|
|
|
|
|
|
|
#[repr(packed(2))]
|
|
|
|
struct P2S7_Option(f32, u8, u16, Option<Box<f64>>);
|
2013-04-10 13:47:53 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
fn align_to(value: usize, align: usize) -> usize {
|
|
|
|
(value + (align - 1)) & !(align - 1)
|
|
|
|
}
|
2013-04-10 13:47:53 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
macro_rules! check {
|
|
|
|
($t:ty, $align:expr, $size:expr) => ({
|
|
|
|
assert_eq!(mem::align_of::<$t>(), $align);
|
|
|
|
assert_eq!(mem::size_of::<$t>(), $size);
|
|
|
|
});
|
|
|
|
}
|
2013-04-10 13:47:53 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
pub fn main() {
|
|
|
|
check!(P1S4, 1, 4);
|
|
|
|
check!(P1S5, 1, 5);
|
|
|
|
check!(P1S13, 1, 13);
|
|
|
|
check!(P1S3_Foo, 1, 3 + mem::size_of::<Foo>());
|
|
|
|
check!(P1S7_Option, 1, 7 + mem::size_of::<Option<Box<f64>>>());
|
2013-04-10 13:47:53 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
check!(P2S4, 1, 4);
|
|
|
|
check!(P2S6, 2, 6);
|
|
|
|
check!(P2S14, 2, 14);
|
|
|
|
check!(P4S16, 4, 16);
|
|
|
|
check!(P4CS20, 4, 20);
|
|
|
|
check!(P2S3_Foo, 2, align_to(3 + mem::size_of::<P2_Foo>(), 2));
|
|
|
|
check!(P2S7_Option, 2, align_to(7 + mem::size_of::<P2_Option>(), 2));
|
2013-04-10 13:47:53 +00:00
|
|
|
}
|