@@ -424,7 +424,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
424
424
throw_ub ! ( DanglingIntPointer ( addr, msg) ) ;
425
425
}
426
426
// Must be aligned.
427
- self . check_misalign ( Self :: offset_misalignment ( addr, align) ) ?;
427
+ if M :: enforce_alignment ( self ) && align. bytes ( ) > 1 {
428
+ self . check_misalign ( Self :: offset_misalignment ( addr, align) ) ?;
429
+ }
428
430
None
429
431
}
430
432
Ok ( ( alloc_id, offset, prov) ) => {
@@ -446,7 +448,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
446
448
}
447
449
// Test align. Check this last; if both bounds and alignment are violated
448
450
// we want the error to be about the bounds.
449
- self . check_misalign ( self . alloc_misalignment ( ptr, offset, align, alloc_align) ) ?;
451
+ if M :: enforce_alignment ( self ) && align. bytes ( ) > 1 {
452
+ self . check_misalign ( self . alloc_misalignment ( ptr, offset, align, alloc_align) ) ?;
453
+ }
450
454
451
455
// We can still be zero-sized in this branch, in which case we have to
452
456
// return `None`.
@@ -457,10 +461,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
457
461
458
462
#[ inline( always) ]
459
463
pub ( super ) fn check_misalign ( & self , misaligned : Option < Misalignment > ) -> InterpResult < ' tcx > {
460
- if M :: enforce_alignment ( self ) {
461
- if let Some ( misaligned) = misaligned {
462
- throw_ub ! ( AlignmentCheckFailed ( misaligned) )
463
- }
464
+ if let Some ( misaligned) = misaligned {
465
+ throw_ub ! ( AlignmentCheckFailed ( misaligned) )
464
466
}
465
467
Ok ( ( ) )
466
468
}
@@ -502,6 +504,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
502
504
ptr : Pointer < Option < M :: Provenance > > ,
503
505
align : Align ,
504
506
) -> Option < Misalignment > {
507
+ if !M :: enforce_alignment ( self ) {
508
+ return None ;
509
+ }
505
510
match self . ptr_try_get_alloc_id ( ptr) {
506
511
Err ( addr) => Self :: offset_misalignment ( addr, align) ,
507
512
Ok ( ( alloc_id, offset, _prov) ) => {
0 commit comments