@@ -632,7 +632,7 @@ fn struct_field_ptr<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
632
632
let meta = val. meta ;
633
633
634
634
635
- let offset = st. offset_of_field ( ix ) . bytes ( ) ;
635
+ let offset = st. offsets [ ix ] . bytes ( ) ;
636
636
let unaligned_offset = C_uint ( bcx. ccx ( ) , offset) ;
637
637
638
638
// Get the alignment of the field
@@ -695,9 +695,9 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
695
695
let lldiscr = C_integral ( Type :: from_integer ( ccx, d) , discr. 0 as u64 , true ) ;
696
696
let mut vals_with_discr = vec ! [ lldiscr] ;
697
697
vals_with_discr. extend_from_slice ( vals) ;
698
- let mut contents = build_const_struct ( ccx, & variant. offset_after_field [ .. ] ,
699
- & vals_with_discr[ ..] , variant . packed ) ;
700
- let needed_padding = l. size ( dl) . bytes ( ) - variant. min_size ( ) . bytes ( ) ;
698
+ let mut contents = build_const_struct ( ccx, & variant,
699
+ & vals_with_discr[ ..] ) ;
700
+ let needed_padding = l. size ( dl) . bytes ( ) - variant. min_size . bytes ( ) ;
701
701
if needed_padding > 0 {
702
702
contents. push ( padding ( ccx, needed_padding) ) ;
703
703
}
@@ -711,7 +711,7 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
711
711
layout:: Univariant { ref variant, .. } => {
712
712
assert_eq ! ( discr, Disr ( 0 ) ) ;
713
713
let contents = build_const_struct ( ccx,
714
- & variant. offset_after_field [ .. ] , vals, variant . packed ) ;
714
+ & variant, vals) ;
715
715
C_struct ( ccx, & contents[ ..] , variant. packed )
716
716
}
717
717
layout:: Vector { .. } => {
@@ -728,9 +728,7 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
728
728
}
729
729
layout:: StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
730
730
if discr. 0 == nndiscr {
731
- C_struct ( ccx, & build_const_struct ( ccx,
732
- & nonnull. offset_after_field [ ..] ,
733
- vals, nonnull. packed ) ,
731
+ C_struct ( ccx, & build_const_struct ( ccx, & nonnull, vals) ,
734
732
false )
735
733
} else {
736
734
let fields = compute_fields ( ccx, t, nndiscr as usize , false ) ;
@@ -739,10 +737,7 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
739
737
// field; see #8506.
740
738
C_null ( type_of:: sizing_type_of ( ccx, ty) )
741
739
} ) . collect :: < Vec < ValueRef > > ( ) ;
742
- C_struct ( ccx, & build_const_struct ( ccx,
743
- & nonnull. offset_after_field [ ..] ,
744
- & vals[ ..] ,
745
- false ) ,
740
+ C_struct ( ccx, & build_const_struct ( ccx, & nonnull, & vals[ ..] ) ,
746
741
false )
747
742
}
748
743
}
@@ -759,11 +754,10 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
759
754
/// a two-element struct will locate it at offset 4, and accesses to it
760
755
/// will read the wrong memory.
761
756
fn build_const_struct < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
762
- offset_after_field : & [ layout:: Size ] ,
763
- vals : & [ ValueRef ] ,
764
- packed : bool )
757
+ st : & layout:: Struct ,
758
+ vals : & [ ValueRef ] )
765
759
-> Vec < ValueRef > {
766
- assert_eq ! ( vals. len( ) , offset_after_field . len( ) ) ;
760
+ assert_eq ! ( vals. len( ) , st . offsets . len( ) ) ;
767
761
768
762
if vals. len ( ) == 0 {
769
763
return Vec :: new ( ) ;
@@ -772,24 +766,19 @@ fn build_const_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
772
766
// offset of current value
773
767
let mut offset = 0 ;
774
768
let mut cfields = Vec :: new ( ) ;
775
- let target_offsets = offset_after_field. iter ( ) . map ( |i| i. bytes ( ) ) ;
776
- for ( & val, target_offset) in vals. iter ( ) . zip ( target_offsets) {
777
- assert ! ( !is_undef( val) ) ;
778
- cfields. push ( val) ;
779
- offset += machine:: llsize_of_alloc ( ccx, val_ty ( val) ) ;
780
- if !packed {
781
- let val_align = machine:: llalign_of_min ( ccx, val_ty ( val) ) ;
782
- offset = roundup ( offset, val_align) ;
783
- }
784
- if offset != target_offset {
769
+ let offsets = st. offsets . iter ( ) . map ( |i| i. bytes ( ) ) ;
770
+ for ( & val, target_offset) in vals. iter ( ) . zip ( offsets) {
771
+ if offset < target_offset {
785
772
cfields. push ( padding ( ccx, target_offset - offset) ) ;
786
773
offset = target_offset;
787
774
}
775
+ assert ! ( !is_undef( val) ) ;
776
+ cfields. push ( val) ;
777
+ offset += machine:: llsize_of_alloc ( ccx, val_ty ( val) ) ;
788
778
}
789
779
790
- let size = offset_after_field. last ( ) . unwrap ( ) ;
791
- if offset < size. bytes ( ) {
792
- cfields. push ( padding ( ccx, size. bytes ( ) - offset) ) ;
780
+ if offset < st. min_size . bytes ( ) {
781
+ cfields. push ( padding ( ccx, st. min_size . bytes ( ) - offset) ) ;
793
782
}
794
783
795
784
cfields
0 commit comments