@@ -349,11 +349,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
349349 size : Size ,
350350 align : Align ,
351351 ) -> InterpResult < ' tcx , Option < ( AllocId , Size , M :: ProvenanceExtra ) > > {
352- let align = M :: enforce_alignment ( & self ) . then_some ( align) ;
353352 self . check_and_deref_ptr (
354353 ptr,
355354 size,
356355 align,
356+ M :: enforce_alignment ( self ) ,
357357 CheckInAllocMsg :: MemoryAccessTest ,
358358 |alloc_id, offset, prov| {
359359 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> {
373373 align : Align ,
374374 msg : CheckInAllocMsg ,
375375 ) -> 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+ ) ?;
380387 Ok ( ( ) )
381388 }
382389
@@ -388,7 +395,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
388395 & self ,
389396 ptr : Pointer < Option < M :: Provenance > > ,
390397 size : Size ,
391- align : Option < Align > ,
398+ align : Align ,
399+ force_alignment_check : bool ,
392400 msg : CheckInAllocMsg ,
393401 alloc_size : impl FnOnce (
394402 AllocId ,
@@ -417,7 +425,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
417425 throw_ub ! ( DanglingIntPointer ( addr, msg) ) ;
418426 }
419427 // Must be aligned.
420- if let Some ( align ) = align {
428+ if force_alignment_check {
421429 check_offset_align ( addr, align) ?;
422430 }
423431 None
@@ -441,7 +449,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
441449 }
442450 // Test align. Check this last; if both bounds and alignment are violated
443451 // we want the error to be about the bounds.
444- if let Some ( align ) = align {
452+ if force_alignment_check {
445453 if M :: use_addr_for_alignment_check ( self ) {
446454 // `use_addr_for_alignment_check` can only be true if `OFFSET_IS_ADDR` is true.
447455 check_offset_align ( ptr. addr ( ) . bytes ( ) , align) ?;
@@ -560,11 +568,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
560568 size : Size ,
561569 align : Align ,
562570 ) -> InterpResult < ' tcx , Option < AllocRef < ' a , ' tcx , M :: Provenance , M :: AllocExtra > > > {
563- let align = M :: enforce_alignment ( self ) . then_some ( align) ;
564571 let ptr_and_alloc = self . check_and_deref_ptr (
565572 ptr,
566573 size,
567574 align,
575+ M :: enforce_alignment ( self ) ,
568576 CheckInAllocMsg :: MemoryAccessTest ,
569577 |alloc_id, offset, prov| {
570578 let alloc = self . get_alloc_raw ( alloc_id) ?;
0 commit comments