@@ -47,15 +47,15 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
47
47
let size = layout. pref_pos . size . bytes ( ) ;
48
48
let align = layout. pref_pos . align . abi . bytes ( ) ;
49
49
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
+
52
52
// /////////////////////////////////////////////////////////////////////////////////////////
53
53
// If you touch this code, be sure to also make the corresponding changes to
54
54
// `get_vtable` in rust_codegen_llvm/meth.rs
55
55
// /////////////////////////////////////////////////////////////////////////////////////////
56
56
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 ,
59
59
MemoryKind :: Vtable ,
60
60
) ;
61
61
let tcx = & * self . tcx ;
@@ -69,10 +69,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
69
69
let vtable_alloc = self . memory . get_raw_mut ( vtable. alloc_id ) ?;
70
70
vtable_alloc. write_ptr_sized ( tcx, vtable, Scalar :: Ptr ( drop) . into ( ) ) ?;
71
71
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 ( ) ) ?;
76
78
77
79
for ( i, method) in methods. iter ( ) . enumerate ( ) {
78
80
if let Some ( ( def_id, substs) ) = * method {
@@ -85,7 +87,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
85
87
) . ok_or_else ( || err_inval ! ( TooGeneric ) ) ?;
86
88
let fn_ptr = self . memory . create_fn_alloc ( FnVal :: Instance ( instance) ) ;
87
89
// 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) ?;
89
91
self . memory . get_raw_mut ( vtable. alloc_id ) ?
90
92
. write_ptr_sized ( tcx, method_ptr, Scalar :: Ptr ( fn_ptr) . into ( ) ) ?;
91
93
}
@@ -127,25 +129,25 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
127
129
& self ,
128
130
vtable : Scalar < M :: PointerTag > ,
129
131
) -> InterpResult < ' tcx , ( Size , Align ) > {
130
- let pointer_size = self . pointer_size ( ) ;
132
+ let ptr_pos = self . pointer_pos ( ) ;
131
133
// We check for size = 3*ptr_size, that covers the drop fn (unused here),
132
134
// the size, and the align (which we read below).
133
135
let vtable = self . memory . check_ptr_access (
134
136
vtable,
135
- 3 * pointer_size ,
137
+ ( 3 * ptr_pos ) . size ,
136
138
self . tcx . data_layout . pointer_pos . align . abi ,
137
139
) ?. expect ( "cannot be a ZST" ) ;
138
140
let alloc = self . memory . get_raw ( vtable. alloc_id ) ?;
139
141
let size = alloc. read_ptr_sized (
140
142
self ,
141
- vtable. offset ( pointer_size , self ) ?
143
+ vtable. offset ( ptr_pos . size , self ) ?
142
144
) ?. 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 ;
144
146
let align = alloc. read_ptr_sized (
145
147
self ,
146
- vtable. offset ( pointer_size * 2 , self ) ?,
148
+ vtable. offset ( ( ptr_pos * 2 ) . size , self ) ?,
147
149
) ?. 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 ;
149
151
150
152
if size >= self . tcx . data_layout ( ) . obj_size_bound ( ) {
151
153
throw_ub_format ! ( "invalid vtable: \
0 commit comments