@@ -7,7 +7,7 @@ use rustc::hir::def_id::DefId;
7
7
use rustc:: hir:: def:: DefKind ;
8
8
use rustc:: mir;
9
9
use rustc:: ty:: layout:: {
10
- self , Size , Align , HasDataLayout , LayoutOf , TyLayout
10
+ self , Size , MemoryPosition , HasDataLayout , LayoutOf , TyLayout
11
11
} ;
12
12
use rustc:: ty:: subst:: SubstsRef ;
13
13
use rustc:: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
@@ -369,13 +369,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
369
369
/// Returns the actual dynamic size and alignment of the place at the given type.
370
370
/// Only the "meta" (metadata) part of the place matters.
371
371
/// 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 (
373
373
& self ,
374
374
metadata : Option < Scalar < M :: PointerTag > > ,
375
375
layout : TyLayout < ' tcx > ,
376
- ) -> InterpResult < ' tcx , Option < ( Size , Align ) > > {
376
+ ) -> InterpResult < ' tcx , Option < MemoryPosition > > {
377
377
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 ( ) ) ) ;
379
379
}
380
380
match layout. ty . kind {
381
381
ty:: Adt ( ..) | ty:: Tuple ( ..) => {
@@ -399,7 +399,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
399
399
// the last field). Can't have foreign types here, how would we
400
400
// adjust alignment and size for them?
401
401
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) ? {
403
403
Some ( size_and_align) => size_and_align,
404
404
None => {
405
405
// 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> {
415
415
}
416
416
} ;
417
417
418
+ let unsized_size = unsized_mem_pos. size ;
419
+ let unsized_align = unsized_mem_pos. align ;
420
+
418
421
// FIXME (#26403, #27023): We should be adding padding
419
422
// to `sized_size` (to accommodate the `unsized_align`
420
423
// required of the unsized field that follows) before
@@ -438,12 +441,16 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
438
441
throw_ub_format ! ( "wide pointer metadata contains invalid information: \
439
442
total size is bigger than largest supported object") ;
440
443
}
441
- Ok ( Some ( ( size, align) ) )
442
- }
444
+ let mem_pos = MemoryPosition :: new ( size, align) . strided ( ) ;
445
+
446
+ Ok ( Some ( mem_pos) )
447
+ } ,
443
448
ty:: Dynamic ( ..) => {
444
449
let vtable = metadata. expect ( "dyn trait fat ptr must have vtable" ) ;
445
450
// 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) )
447
454
}
448
455
449
456
ty:: Slice ( _) | ty:: Str => {
@@ -454,22 +461,22 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
454
461
let pref_pos = elem. pref_pos . checked_mul ( len, & * self . tcx )
455
462
. ok_or_else ( || err_ub_format ! ( "invalid slice: \
456
463
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 ( ) ) )
458
465
}
459
466
460
467
ty:: Foreign ( _) => {
461
468
Ok ( None )
462
469
}
463
470
464
- _ => bug ! ( "size_and_align_of ::<{:?}> not supported" , layout. ty) ,
471
+ _ => bug ! ( "mem_pos_of ::<{:?}> not supported" , layout. ty) ,
465
472
}
466
473
}
467
474
#[ inline]
468
- pub fn size_and_align_of_mplace (
475
+ pub fn mem_pos_of_mplace (
469
476
& self ,
470
477
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 )
473
480
}
474
481
475
482
pub fn push_stack_frame (
0 commit comments