@@ -397,21 +397,24 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
397397 . checked_mul ( pointee_size)
398398 . ok_or_else ( || InterpError :: Overflow ( mir:: BinOp :: Mul ) ) ?;
399399 // Now let's see what kind of pointer this is.
400- if let Ok ( ptr) = self . force_ptr ( ptr) {
401- // Both old and new pointer must be in-bounds of a *live* allocation.
402- // (Of the same allocation, but that part is trivial with our representation.)
403- self . pointer_inbounds ( ptr) ?;
404- let ptr = ptr. signed_offset ( offset, self ) ?;
405- self . pointer_inbounds ( ptr) ?;
406- Ok ( Scalar :: Ptr ( ptr) )
407- } else {
408- // A "true" integer pointer. They can only be offset by 0, and we pretend there
409- // is a little zero-sized allocation here.
410- if offset == 0 {
411- Ok ( ptr)
412- } else {
413- err ! ( InvalidPointerMath )
400+ let ptr = if offset == 0 {
401+ match ptr {
402+ Scalar :: Ptr ( ptr) => ptr,
403+ Scalar :: Raw { .. } => {
404+ // Offset 0 on an integer. We accept that, pretending there is
405+ // a little zero-sized allocation here.
406+ return Ok ( ptr) ;
407+ }
414408 }
415- }
409+ } else {
410+ // Offset > 0. We *require* a pointer.
411+ self . force_ptr ( ptr) ?
412+ } ;
413+ // Both old and new pointer must be in-bounds of a *live* allocation.
414+ // (Of the same allocation, but that part is trivial with our representation.)
415+ self . pointer_inbounds ( ptr) ?;
416+ let ptr = ptr. signed_offset ( offset, self ) ?;
417+ self . pointer_inbounds ( ptr) ?;
418+ Ok ( Scalar :: Ptr ( ptr) )
416419 }
417420}
0 commit comments