Skip to content

Commit cd300b8

Browse files
committed
---
yaml --- r: 273383 b: refs/heads/beta c: 399b522 h: refs/heads/master i: 273381: dc7ae28 273379: 8442992 273375: c244f9e
1 parent 368e599 commit cd300b8

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
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: ec84ab0e0f5ceda69f69078923fc04482c1dda9b
26+
refs/heads/beta: 399b52217b19dd8e1d86b652c150579c0110e772
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_back/target/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
//! this module defines the format the JSON file should take, though each
4141
//! underscore in the field names should be replaced with a hyphen (`-`) in the
4242
//! JSON file. Some fields are required in every target specification, such as
43-
//! `data-layout`, `llvm-target`, `target-endian`, `target-pointer-width`, and
44-
//! `arch`. In general, options passed to rustc with `-C` override the target's
43+
//! `llvm-target`, `target-endian`, `target-pointer-width`, `arch`, and
44+
//! `os`. In general, options passed to rustc with `-C` override the target's
4545
//! settings, though `target-feature` and `link-args` will *add* to the list
4646
//! specified by the target, rather than replace.
4747

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,15 @@ fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
396396
}
397397
}
398398
}
399+
400+
// If the alignment is smaller than the chosen discriminant size, don't use the
401+
// alignment as the final size.
402+
let min_ty = ll_inttype(&cx, min_ity);
403+
let min_size = machine::llsize_of_real(cx, min_ty);
404+
if (align as u64) < min_size {
405+
use_align = false;
406+
}
407+
399408
let ity = if use_align {
400409
// Use the overall alignment
401410
match align {
@@ -813,11 +822,11 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
813822
// FIXME #10604: this breaks when vector types are present.
814823
let (size, align) = union_size_and_align(&sts[..]);
815824
let align_s = align as u64;
816-
assert_eq!(size % align_s, 0);
817-
let align_units = size / align_s - 1;
818-
819825
let discr_ty = ll_inttype(cx, ity);
820826
let discr_size = machine::llsize_of_alloc(cx, discr_ty);
827+
let padded_discr_size = roundup(discr_size, align);
828+
assert_eq!(size % align_s, 0); // Ensure division in align_units comes out evenly
829+
let align_units = (size - padded_discr_size) / align_s;
821830
let fill_ty = match align_s {
822831
1 => Type::array(&Type::i8(cx), align_units),
823832
2 => Type::array(&Type::i16(cx), align_units),
@@ -829,10 +838,10 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
829838
_ => panic!("unsupported enum alignment: {}", align)
830839
};
831840
assert_eq!(machine::llalign_of_min(cx, fill_ty), align);
832-
assert_eq!(align_s % discr_size, 0);
841+
assert_eq!(padded_discr_size % discr_size, 0); // Ensure discr_ty can fill pad evenly
833842
let mut fields: Vec<Type> =
834843
[discr_ty,
835-
Type::array(&discr_ty, align_s / discr_size - 1),
844+
Type::array(&discr_ty, (padded_discr_size - discr_size)/discr_size),
836845
fill_ty].iter().cloned().collect();
837846
if delay_drop_flag && dtor_needed {
838847
fields.pop();

branches/beta/src/test/run-pass/enum-discrim-manual-sizing.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
use std::mem::size_of;
12+
use std::mem::{size_of, align_of};
1313

1414
#[repr(i8)]
1515
enum Ei8 {
@@ -71,6 +71,24 @@ enum Euint {
7171
Buint = 1
7272
}
7373

74+
#[repr(u8)]
75+
enum Eu8NonCLike<T> {
76+
_None,
77+
_Some(T),
78+
}
79+
80+
#[repr(i64)]
81+
enum Ei64NonCLike<T> {
82+
_None,
83+
_Some(T),
84+
}
85+
86+
#[repr(u64)]
87+
enum Eu64NonCLike<T> {
88+
_None,
89+
_Some(T),
90+
}
91+
7492
pub fn main() {
7593
assert_eq!(size_of::<Ei8>(), 1);
7694
assert_eq!(size_of::<Eu8>(), 1);
@@ -82,4 +100,17 @@ pub fn main() {
82100
assert_eq!(size_of::<Eu64>(), 8);
83101
assert_eq!(size_of::<Eint>(), size_of::<isize>());
84102
assert_eq!(size_of::<Euint>(), size_of::<usize>());
103+
assert_eq!(size_of::<Eu8NonCLike<()>>(), 1);
104+
assert_eq!(size_of::<Ei64NonCLike<()>>(), 8);
105+
assert_eq!(size_of::<Eu64NonCLike<()>>(), 8);
106+
let u8_expected_size = round_up(9, align_of::<Eu64NonCLike<u8>>());
107+
assert_eq!(size_of::<Eu64NonCLike<u8>>(), u8_expected_size);
108+
let array_expected_size = round_up(28, align_of::<Eu64NonCLike<[u32; 5]>>());
109+
assert_eq!(size_of::<Eu64NonCLike<[u32; 5]>>(), array_expected_size);
110+
assert_eq!(size_of::<Eu64NonCLike<[u32; 6]>>(), 32);
111+
}
112+
113+
// Rounds x up to the next multiple of a
114+
fn round_up(x: usize, a: usize) -> usize {
115+
((x + (a - 1)) / a) * a
85116
}

0 commit comments

Comments
 (0)