@@ -7,7 +7,7 @@ use rustc::hir::def_id::DefId;
77use rustc:: hir:: def:: DefKind ;
88use rustc:: mir;
99use rustc:: ty:: layout:: {
10- self , Size , Align , HasDataLayout , LayoutOf , TyLayout
10+ self , Size , MemoryPosition , HasDataLayout , LayoutOf , TyLayout
1111} ;
1212use rustc:: ty:: subst:: SubstsRef ;
1313use rustc:: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
@@ -369,13 +369,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
369369 /// Returns the actual dynamic size and alignment of the place at the given type.
370370 /// Only the "meta" (metadata) part of the place matters.
371371 /// This can fail to provide an answer for extern types.
372- pub ( super ) fn size_and_align_of (
372+ pub ( super ) fn mem_pos_of (
373373 & self ,
374374 metadata : Option < Scalar < M :: PointerTag > > ,
375375 layout : TyLayout < ' tcx > ,
376- ) -> InterpResult < ' tcx , Option < ( Size , Align ) > > {
376+ ) -> InterpResult < ' tcx , Option < MemoryPosition > > {
377377 if !layout. is_unsized ( ) {
378- return Ok ( Some ( ( layout. pref_pos . size , layout . pref_pos . align . abi ) ) ) ;
378+ return Ok ( Some ( layout. pref_pos . mem_pos ( ) ) ) ;
379379 }
380380 match layout. ty . kind {
381381 ty:: Adt ( ..) | ty:: Tuple ( ..) => {
@@ -399,7 +399,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
399399 // the last field). Can't have foreign types here, how would we
400400 // adjust alignment and size for them?
401401 let field = layout. field ( self , layout. fields . count ( ) - 1 ) ?;
402- let ( unsized_size , unsized_align ) = match self . size_and_align_of ( metadata, field) ? {
402+ let unsized_mem_pos = match self . mem_pos_of ( metadata, field) ? {
403403 Some ( size_and_align) => size_and_align,
404404 None => {
405405 // A field with extern type. If this field is at offset 0, we behave
@@ -415,6 +415,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
415415 }
416416 } ;
417417
418+ let unsized_size = unsized_mem_pos. size ;
419+ let unsized_align = unsized_mem_pos. align ;
420+
418421 // FIXME (#26403, #27023): We should be adding padding
419422 // to `sized_size` (to accommodate the `unsized_align`
420423 // required of the unsized field that follows) before
@@ -438,12 +441,16 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
438441 throw_ub_format ! ( "wide pointer metadata contains invalid information: \
439442 total size is bigger than largest supported object") ;
440443 }
441- Ok ( Some ( ( size, align) ) )
442- }
444+ let mem_pos = MemoryPosition :: new ( size, align) . strided ( ) ;
445+
446+ Ok ( Some ( mem_pos) )
447+ } ,
443448 ty:: Dynamic ( ..) => {
444449 let vtable = metadata. expect ( "dyn trait fat ptr must have vtable" ) ;
445450 // Read size and align from vtable (already checks size).
446- Ok ( Some ( self . read_size_and_align_from_vtable ( vtable) ?) )
451+ let ( size, align) = self . read_size_and_align_from_vtable ( vtable) ?;
452+ let mem_pos = MemoryPosition :: new ( size, align) ;
453+ Ok ( Some ( mem_pos) )
447454 }
448455
449456 ty:: Slice ( _) | ty:: Str => {
@@ -454,22 +461,22 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
454461 let pref_pos = elem. pref_pos . checked_mul ( len, & * self . tcx )
455462 . ok_or_else ( || err_ub_format ! ( "invalid slice: \
456463 total size is bigger than largest supported object") ) ?;
457- Ok ( Some ( ( pref_pos. size , pref_pos . align . abi ) ) )
464+ Ok ( Some ( pref_pos. mem_pos ( ) ) )
458465 }
459466
460467 ty:: Foreign ( _) => {
461468 Ok ( None )
462469 }
463470
464- _ => bug ! ( "size_and_align_of ::<{:?}> not supported" , layout. ty) ,
471+ _ => bug ! ( "mem_pos_of ::<{:?}> not supported" , layout. ty) ,
465472 }
466473 }
467474 #[ inline]
468- pub fn size_and_align_of_mplace (
475+ pub fn mem_pos_of_mplace (
469476 & self ,
470477 mplace : MPlaceTy < ' tcx , M :: PointerTag >
471- ) -> InterpResult < ' tcx , Option < ( Size , Align ) > > {
472- self . size_and_align_of ( mplace. meta , mplace. layout )
478+ ) -> InterpResult < ' tcx , Option < MemoryPosition > > {
479+ self . mem_pos_of ( mplace. meta , mplace. layout )
473480 }
474481
475482 pub fn push_stack_frame (
0 commit comments