Skip to content

Commit 8442992

Browse files
---
yaml --- r: 273379 b: refs/heads/beta c: ffe5162 h: refs/heads/master i: 273377: 8717934 273375: c244f9e
1 parent ab7db1c commit 8442992

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 3f94fac150c872f93ee00eaad736eae5e3226aaa
26+
refs/heads/beta: ffe5162cd1605228a1dae798953a5ea6b8f2e97f
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_trans/trans/adt.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,15 @@ fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
400400
}
401401
}
402402
}
403+
404+
// If the alignment is smaller than the chosen discriminant size, don't use the
405+
// alignment as the final size.
406+
let min_ty = ll_inttype(&cx, min_ity);
407+
let min_size = machine::llsize_of_real(cx, min_ty);
408+
if (align as u64) < min_size {
409+
use_align = false;
410+
}
411+
403412
let ity = if use_align {
404413
// Use the overall alignment
405414
match align {
@@ -817,11 +826,11 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
817826
// FIXME #10604: this breaks when vector types are present.
818827
let (size, align) = union_size_and_align(&sts[..]);
819828
let align_s = align as u64;
820-
assert_eq!(size % align_s, 0);
821-
let align_units = size / align_s - 1;
822-
823829
let discr_ty = ll_inttype(cx, ity);
824830
let discr_size = machine::llsize_of_alloc(cx, discr_ty);
831+
let padded_discr_size = roundup(discr_size, align);
832+
assert_eq!(size % align_s, 0); // Ensure division in align_units comes out evenly
833+
let align_units = (size - padded_discr_size) / align_s;
825834
let fill_ty = match align_s {
826835
1 => Type::array(&Type::i8(cx), align_units),
827836
2 => Type::array(&Type::i16(cx), align_units),
@@ -833,10 +842,10 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
833842
_ => panic!("unsupported enum alignment: {}", align)
834843
};
835844
assert_eq!(machine::llalign_of_min(cx, fill_ty), align);
836-
assert_eq!(align_s % discr_size, 0);
845+
assert_eq!(padded_discr_size % discr_size, 0); // Ensure discr_ty can fill pad evenly
837846
let mut fields: Vec<Type> =
838847
[discr_ty,
839-
Type::array(&discr_ty, align_s / discr_size - 1),
848+
Type::array(&discr_ty, (padded_discr_size - discr_size)/discr_size),
840849
fill_ty].iter().cloned().collect();
841850
if delay_drop_flag && dtor_needed {
842851
fields.pop();

0 commit comments

Comments
 (0)