@@ -314,16 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
314314 align : Align ,
315315 ) -> InterpResult < ' tcx , Option < Pointer < M :: PointerTag > > > {
316316 let align = if M :: CHECK_ALIGN { Some ( align) } else { None } ;
317- self . check_ptr_access_align ( sptr, size, align)
317+ self . check_ptr_access_align ( sptr, size, align, CheckInAllocMsg :: MemoryAccessTest )
318318 }
319319
320320 /// Like `check_ptr_access`, but *definitely* checks alignment when `align`
321- /// is `Some` (overriding `M::CHECK_ALIGN`).
322- pub ( super ) fn check_ptr_access_align (
321+ /// is `Some` (overriding `M::CHECK_ALIGN`). Also lets the caller control
322+ /// the error message for the out-of-bounds case.
323+ pub fn check_ptr_access_align (
323324 & self ,
324325 sptr : Scalar < M :: PointerTag > ,
325326 size : Size ,
326327 align : Option < Align > ,
328+ msg : CheckInAllocMsg ,
327329 ) -> InterpResult < ' tcx , Option < Pointer < M :: PointerTag > > > {
328330 fn check_offset_align ( offset : u64 , align : Align ) -> InterpResult < ' static > {
329331 if offset % align. bytes ( ) == 0 {
@@ -368,7 +370,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
368370 // It is sufficient to check this for the end pointer. The addition
369371 // checks for overflow.
370372 let end_ptr = ptr. offset ( size, self ) ?;
371- end_ptr. check_inbounds_alloc ( allocation_size, CheckInAllocMsg :: MemoryAccessTest ) ?;
373+ end_ptr. check_inbounds_alloc ( allocation_size, msg ) ?;
372374 // Test align. Check this last; if both bounds and alignment are violated
373375 // we want the error to be about the bounds.
374376 if let Some ( align) = align {
0 commit comments