auto merge of #20060 : Aatch/rust/enum-repr, r=alexcrichton

The previous behaviour of using the smallest type possible caused LLVM
to treat padding too conservatively, causing poor codegen. This commit
changes the behaviour to use an alignment-sized integer as the
discriminant. This keeps types the same size, but helps LLVM understand
the data structure a little better, resulting in better codegen.
This commit is contained in:
bors 2014-12-24 16:21:23 +00:00
commit 29ad8539b9
2 changed files with 79 additions and 6 deletions

View file

@ -18,6 +18,17 @@ struct w {a: int, b: ()}
struct x {a: int, b: (), c: ()}
struct y {x: int}
enum e1 {
a(u8, u32), b(u32), c
}
enum e2 {
a(u32), b
}
enum e3 {
a([u16, ..0], u8), b
}
pub fn main() {
assert_eq!(size_of::<u8>(), 1 as uint);
assert_eq!(size_of::<u32>(), 4 as uint);
@ -34,4 +45,11 @@ pub fn main() {
assert_eq!(size_of::<w>(), size_of::<int>());
assert_eq!(size_of::<x>(), size_of::<int>());
assert_eq!(size_of::<int>(), size_of::<y>());
// Make sure enum types are the appropriate size, mostly
// around ensuring alignment is handled properly
assert_eq!(size_of::<e1>(), 8 as uint);
assert_eq!(size_of::<e2>(), 8 as uint);
assert_eq!(size_of::<e3>(), 4 as uint);
}