@@ -632,7 +632,7 @@ fn struct_field_ptr<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
632632 let meta = val. meta ;
633633
634634
635- let offset = st. offset_of_field ( ix ) . bytes ( ) ;
635+ let offset = st. offsets [ ix ] . bytes ( ) ;
636636 let unaligned_offset = C_uint ( bcx. ccx ( ) , offset) ;
637637
638638 // 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
695695 let lldiscr = C_integral ( Type :: from_integer ( ccx, d) , discr. 0 as u64 , true ) ;
696696 let mut vals_with_discr = vec ! [ lldiscr] ;
697697 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 ( ) ;
701701 if needed_padding > 0 {
702702 contents. push ( padding ( ccx, needed_padding) ) ;
703703 }
@@ -711,7 +711,7 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
711711 layout:: Univariant { ref variant, .. } => {
712712 assert_eq ! ( discr, Disr ( 0 ) ) ;
713713 let contents = build_const_struct ( ccx,
714- & variant. offset_after_field [ .. ] , vals, variant . packed ) ;
714+ & variant, vals) ;
715715 C_struct ( ccx, & contents[ ..] , variant. packed )
716716 }
717717 layout:: Vector { .. } => {
@@ -728,9 +728,7 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
728728 }
729729 layout:: StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
730730 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) ,
734732 false )
735733 } else {
736734 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
739737 // field; see #8506.
740738 C_null ( type_of:: sizing_type_of ( ccx, ty) )
741739 } ) . 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[ ..] ) ,
746741 false )
747742 }
748743 }
@@ -759,11 +754,10 @@ pub fn trans_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>, discr: D
759754/// a two-element struct will locate it at offset 4, and accesses to it
760755/// will read the wrong memory.
761756fn 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 ] )
765759 -> Vec < ValueRef > {
766- assert_eq ! ( vals. len( ) , offset_after_field . len( ) ) ;
760+ assert_eq ! ( vals. len( ) , st . offsets . len( ) ) ;
767761
768762 if vals. len ( ) == 0 {
769763 return Vec :: new ( ) ;
@@ -772,24 +766,19 @@ fn build_const_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
772766 // offset of current value
773767 let mut offset = 0 ;
774768 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 {
785772 cfields. push ( padding ( ccx, target_offset - offset) ) ;
786773 offset = target_offset;
787774 }
775+ assert ! ( !is_undef( val) ) ;
776+ cfields. push ( val) ;
777+ offset += machine:: llsize_of_alloc ( ccx, val_ty ( val) ) ;
788778 }
789779
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) ) ;
793782 }
794783
795784 cfields
0 commit comments