@@ -349,11 +349,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
349
349
size : Size ,
350
350
align : Align ,
351
351
) -> InterpResult < ' tcx , Option < ( AllocId , Size , M :: ProvenanceExtra ) > > {
352
- let align = M :: enforce_alignment ( & self ) . then_some ( align) ;
353
352
self . check_and_deref_ptr (
354
353
ptr,
355
354
size,
356
355
align,
356
+ M :: enforce_alignment ( self ) ,
357
357
CheckInAllocMsg :: MemoryAccessTest ,
358
358
|alloc_id, offset, prov| {
359
359
let ( size, align) = self . get_live_alloc_size_and_align ( alloc_id) ?;
@@ -373,10 +373,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
373
373
align : Align ,
374
374
msg : CheckInAllocMsg ,
375
375
) -> InterpResult < ' tcx > {
376
- self . check_and_deref_ptr ( ptr, size, Some ( align) , msg, |alloc_id, _, _| {
377
- let ( size, align) = self . get_live_alloc_size_and_align ( alloc_id) ?;
378
- Ok ( ( size, align, ( ) ) )
379
- } ) ?;
376
+ self . check_and_deref_ptr (
377
+ ptr,
378
+ size,
379
+ align,
380
+ /* force_alignment_check */ true ,
381
+ msg,
382
+ |alloc_id, _, _| {
383
+ let ( size, align) = self . get_live_alloc_size_and_align ( alloc_id) ?;
384
+ Ok ( ( size, align, ( ) ) )
385
+ } ,
386
+ ) ?;
380
387
Ok ( ( ) )
381
388
}
382
389
@@ -388,7 +395,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
388
395
& self ,
389
396
ptr : Pointer < Option < M :: Provenance > > ,
390
397
size : Size ,
391
- align : Option < Align > ,
398
+ align : Align ,
399
+ force_alignment_check : bool ,
392
400
msg : CheckInAllocMsg ,
393
401
alloc_size : impl FnOnce (
394
402
AllocId ,
@@ -417,7 +425,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
417
425
throw_ub ! ( DanglingIntPointer ( addr, msg) ) ;
418
426
}
419
427
// Must be aligned.
420
- if let Some ( align ) = align {
428
+ if force_alignment_check {
421
429
check_offset_align ( addr, align) ?;
422
430
}
423
431
None
@@ -441,7 +449,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
441
449
}
442
450
// Test align. Check this last; if both bounds and alignment are violated
443
451
// we want the error to be about the bounds.
444
- if let Some ( align ) = align {
452
+ if force_alignment_check {
445
453
if M :: use_addr_for_alignment_check ( self ) {
446
454
// `use_addr_for_alignment_check` can only be true if `OFFSET_IS_ADDR` is true.
447
455
check_offset_align ( ptr. addr ( ) . bytes ( ) , align) ?;
@@ -560,11 +568,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
560
568
size : Size ,
561
569
align : Align ,
562
570
) -> InterpResult < ' tcx , Option < AllocRef < ' a , ' tcx , M :: Provenance , M :: AllocExtra > > > {
563
- let align = M :: enforce_alignment ( self ) . then_some ( align) ;
564
571
let ptr_and_alloc = self . check_and_deref_ptr (
565
572
ptr,
566
573
size,
567
574
align,
575
+ M :: enforce_alignment ( self ) ,
568
576
CheckInAllocMsg :: MemoryAccessTest ,
569
577
|alloc_id, offset, prov| {
570
578
let alloc = self . get_alloc_raw ( alloc_id) ?;
0 commit comments