@@ -314,16 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
314
314
align : Align ,
315
315
) -> InterpResult < ' tcx , Option < Pointer < M :: PointerTag > > > {
316
316
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 )
318
318
}
319
319
320
320
/// 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 (
323
324
& self ,
324
325
sptr : Scalar < M :: PointerTag > ,
325
326
size : Size ,
326
327
align : Option < Align > ,
328
+ msg : CheckInAllocMsg ,
327
329
) -> InterpResult < ' tcx , Option < Pointer < M :: PointerTag > > > {
328
330
fn check_offset_align ( offset : u64 , align : Align ) -> InterpResult < ' static > {
329
331
if offset % align. bytes ( ) == 0 {
@@ -368,7 +370,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
368
370
// It is sufficient to check this for the end pointer. The addition
369
371
// checks for overflow.
370
372
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 ) ?;
372
374
// Test align. Check this last; if both bounds and alignment are violated
373
375
// we want the error to be about the bounds.
374
376
if let Some ( align) = align {
0 commit comments