@@ -47,15 +47,15 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
4747 let size = layout. pref_pos . size . bytes ( ) ;
4848 let align = layout. pref_pos . align . abi . bytes ( ) ;
4949
50- let ptr_size = self . pointer_size ( ) ;
51- let ptr_align = self . tcx . data_layout . pointer_pos . align . abi ;
50+ let ptr_pref_pos = self . pointer_pos ( ) ;
51+
5252 // /////////////////////////////////////////////////////////////////////////////////////////
5353 // If you touch this code, be sure to also make the corresponding changes to
5454 // `get_vtable` in rust_codegen_llvm/meth.rs
5555 // /////////////////////////////////////////////////////////////////////////////////////////
5656 let vtable = self . memory . allocate (
57- ptr_size * ( 3 + methods. len ( ) as u64 ) ,
58- ptr_align ,
57+ ( ptr_pref_pos * ( 3 + methods. len ( ) as u64 ) ) . size ,
58+ ptr_pref_pos . align . abi ,
5959 MemoryKind :: Vtable ,
6060 ) ;
6161 let tcx = & * self . tcx ;
@@ -69,10 +69,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6969 let vtable_alloc = self . memory . get_raw_mut ( vtable. alloc_id ) ?;
7070 vtable_alloc. write_ptr_sized ( tcx, vtable, Scalar :: Ptr ( drop) . into ( ) ) ?;
7171
72- let size_ptr = vtable. offset ( ptr_size, tcx) ?;
73- vtable_alloc. write_ptr_sized ( tcx, size_ptr, Scalar :: from_uint ( size, ptr_size) . into ( ) ) ?;
74- let align_ptr = vtable. offset ( ptr_size * 2 , tcx) ?;
75- vtable_alloc. write_ptr_sized ( tcx, align_ptr, Scalar :: from_uint ( align, ptr_size) . into ( ) ) ?;
72+ let size_ptr = vtable. offset ( ptr_pref_pos. size , tcx) ?;
73+ vtable_alloc. write_ptr_sized ( tcx, size_ptr,
74+ Scalar :: from_uint ( size, ptr_pref_pos. size ) . into ( ) ) ?;
75+ let align_ptr = vtable. offset ( ( ptr_pref_pos * 2 ) . size , tcx) ?;
76+ vtable_alloc. write_ptr_sized ( tcx, align_ptr,
77+ Scalar :: from_uint ( align, ptr_pref_pos. size ) . into ( ) ) ?;
7678
7779 for ( i, method) in methods. iter ( ) . enumerate ( ) {
7880 if let Some ( ( def_id, substs) ) = * method {
@@ -85,7 +87,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
8587 ) . ok_or_else ( || err_inval ! ( TooGeneric ) ) ?;
8688 let fn_ptr = self . memory . create_fn_alloc ( FnVal :: Instance ( instance) ) ;
8789 // We cannot use `vtable_allic` as we are creating fn ptrs in this loop.
88- let method_ptr = vtable. offset ( ptr_size * ( 3 + i as u64 ) , tcx) ?;
90+ let method_ptr = vtable. offset ( ( ptr_pref_pos * ( 3 + i as u64 ) ) . size , tcx) ?;
8991 self . memory . get_raw_mut ( vtable. alloc_id ) ?
9092 . write_ptr_sized ( tcx, method_ptr, Scalar :: Ptr ( fn_ptr) . into ( ) ) ?;
9193 }
@@ -127,25 +129,25 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
127129 & self ,
128130 vtable : Scalar < M :: PointerTag > ,
129131 ) -> InterpResult < ' tcx , ( Size , Align ) > {
130- let pointer_size = self . pointer_size ( ) ;
132+ let ptr_pos = self . pointer_pos ( ) ;
131133 // We check for size = 3*ptr_size, that covers the drop fn (unused here),
132134 // the size, and the align (which we read below).
133135 let vtable = self . memory . check_ptr_access (
134136 vtable,
135- 3 * pointer_size ,
137+ ( 3 * ptr_pos ) . size ,
136138 self . tcx . data_layout . pointer_pos . align . abi ,
137139 ) ?. expect ( "cannot be a ZST" ) ;
138140 let alloc = self . memory . get_raw ( vtable. alloc_id ) ?;
139141 let size = alloc. read_ptr_sized (
140142 self ,
141- vtable. offset ( pointer_size , self ) ?
143+ vtable. offset ( ptr_pos . size , self ) ?
142144 ) ?. not_undef ( ) ?;
143- let size = self . force_bits ( size, pointer_size ) ? as u64 ;
145+ let size = self . force_bits ( size, ptr_pos . size ) ? as u64 ;
144146 let align = alloc. read_ptr_sized (
145147 self ,
146- vtable. offset ( pointer_size * 2 , self ) ?,
148+ vtable. offset ( ( ptr_pos * 2 ) . size , self ) ?,
147149 ) ?. not_undef ( ) ?;
148- let align = self . force_bits ( align, pointer_size ) ? as u64 ;
150+ let align = self . force_bits ( align, ptr_pos . size ) ? as u64 ;
149151
150152 if size >= self . tcx . data_layout ( ) . obj_size_bound ( ) {
151153 throw_ub_format ! ( "invalid vtable: \
0 commit comments