From be42b04ee7769f5d0e9d040fb06ec2c60d9c5482 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 21 Nov 2022 16:51:16 +0000 Subject: [PATCH 1/2] Make alignment checks a future incompat lint --- src/machine.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/machine.rs b/src/machine.rs index e5b1eb2e48706..8f3c979f5ebab 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -24,6 +24,7 @@ use rustc_span::def_id::{CrateNum, DefId}; use rustc_span::Symbol; use rustc_target::abi::Size; use rustc_target::spec::abi::Abi; +use rustc_const_eval::const_eval::CheckAlignment; use crate::{ concurrency::{data_race, weak_memory}, @@ -752,8 +753,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> { const PANIC_ON_ALLOC_FAIL: bool = false; #[inline(always)] - fn enforce_alignment(ecx: &MiriInterpCx<'mir, 'tcx>) -> bool { - ecx.machine.check_alignment != AlignmentCheck::None + fn enforce_alignment(ecx: &MiriInterpCx<'mir, 'tcx>) -> CheckAlignment { + if ecx.machine.check_alignment == AlignmentCheck::None { + CheckAlignment::No + } else { + CheckAlignment::Error + } } #[inline(always)] From 21b99baa3ffa3f1782707d1bb49204faabaeee53 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 22 Nov 2022 11:16:33 +0000 Subject: [PATCH 2/2] Move alignment failure error reporting to machine --- src/machine.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/machine.rs b/src/machine.rs index 8f3c979f5ebab..ab629e4711b10 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -22,7 +22,7 @@ use rustc_middle::{ }; use rustc_span::def_id::{CrateNum, DefId}; use rustc_span::Symbol; -use rustc_target::abi::Size; +use rustc_target::abi::{Size, Align}; use rustc_target::spec::abi::Abi; use rustc_const_eval::const_eval::CheckAlignment; @@ -766,6 +766,15 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> { ecx.machine.check_alignment == AlignmentCheck::Int } + fn alignment_check_failed( + _ecx: &InterpCx<'mir, 'tcx, Self>, + has: Align, + required: Align, + _check: CheckAlignment, + ) -> InterpResult<'tcx, ()> { + throw_ub!(AlignmentCheckFailed { has, required }) + } + #[inline(always)] fn enforce_validity(ecx: &MiriInterpCx<'mir, 'tcx>) -> bool { ecx.machine.validate