@@ -158,8 +158,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
158
158
pub fn reallocate (
159
159
& mut self ,
160
160
ptr : Pointer < M :: PointerTag > ,
161
- old_size : Size ,
162
- old_align : Align ,
161
+ old_size_and_align : Option < ( Size , Align ) > ,
163
162
new_size : Size ,
164
163
new_align : Align ,
165
164
kind : MemoryKind < M :: MemoryKinds > ,
@@ -171,15 +170,19 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
171
170
// For simplicities' sake, we implement reallocate as "alloc, copy, dealloc".
172
171
// This happens so rarely, the perf advantage is outweighed by the maintenance cost.
173
172
let new_ptr = self . allocate ( new_size, new_align, kind) ;
173
+ let old_size = match old_size_and_align {
174
+ Some ( ( size, _align) ) => size,
175
+ None => Size :: from_bytes ( self . get ( ptr. alloc_id ) ?. bytes . len ( ) as u64 ) ,
176
+ } ;
174
177
self . copy (
175
178
ptr. into ( ) ,
176
- old_align ,
179
+ Align :: from_bytes ( 1 ) . unwrap ( ) , // old_align anyway gets checked below by `deallocate`
177
180
new_ptr. into ( ) ,
178
181
new_align,
179
182
old_size. min ( new_size) ,
180
183
/*nonoverlapping*/ true ,
181
184
) ?;
182
- self . deallocate ( ptr, Some ( ( old_size , old_align ) ) , kind) ?;
185
+ self . deallocate ( ptr, old_size_and_align , kind) ?;
183
186
184
187
Ok ( new_ptr)
185
188
}
@@ -198,7 +201,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
198
201
pub fn deallocate (
199
202
& mut self ,
200
203
ptr : Pointer < M :: PointerTag > ,
201
- size_and_align : Option < ( Size , Align ) > ,
204
+ old_size_and_align : Option < ( Size , Align ) > ,
202
205
kind : MemoryKind < M :: MemoryKinds > ,
203
206
) -> InterpResult < ' tcx > {
204
207
trace ! ( "deallocating: {}" , ptr. alloc_id) ;
@@ -232,7 +235,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
232
235
format!( "{:?}" , kind) ,
233
236
) ) ;
234
237
}
235
- if let Some ( ( size, align) ) = size_and_align {
238
+ if let Some ( ( size, align) ) = old_size_and_align {
236
239
if size. bytes ( ) != alloc. bytes . len ( ) as u64 || align != alloc. align {
237
240
let bytes = Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) ;
238
241
return err ! ( IncorrectAllocationInformation ( size,
0 commit comments