Use constant eval to do strict validity checks
This commit is contained in:
@@ -15,7 +15,7 @@ use rustc_middle::ty::layout::LayoutOf as _;
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::{Ty, TyCtxt};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_target::abi::{Abi, Align, InitKind, Primitive, Size};
|
||||
use rustc_target::abi::{Abi, Align, Primitive, Size};
|
||||
|
||||
use super::{
|
||||
util::ensure_monomorphic_enough, CheckInAllocMsg, ImmTy, InterpCx, Machine, OpTy, PlaceTy,
|
||||
@@ -413,35 +413,33 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
),
|
||||
)?;
|
||||
}
|
||||
if intrinsic_name == sym::assert_zero_valid
|
||||
&& !layout.might_permit_raw_init(
|
||||
self,
|
||||
InitKind::Zero,
|
||||
self.tcx.sess.opts.unstable_opts.strict_init_checks,
|
||||
)
|
||||
{
|
||||
M::abort(
|
||||
self,
|
||||
format!(
|
||||
"aborted execution: attempted to zero-initialize type `{}`, which is invalid",
|
||||
ty
|
||||
),
|
||||
)?;
|
||||
|
||||
if intrinsic_name == sym::assert_zero_valid {
|
||||
let should_panic = !self.tcx.permits_zero_init(layout);
|
||||
|
||||
if should_panic {
|
||||
M::abort(
|
||||
self,
|
||||
format!(
|
||||
"aborted execution: attempted to zero-initialize type `{}`, which is invalid",
|
||||
ty
|
||||
),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
if intrinsic_name == sym::assert_uninit_valid
|
||||
&& !layout.might_permit_raw_init(
|
||||
self,
|
||||
InitKind::Uninit,
|
||||
self.tcx.sess.opts.unstable_opts.strict_init_checks,
|
||||
)
|
||||
{
|
||||
M::abort(
|
||||
self,
|
||||
format!(
|
||||
"aborted execution: attempted to leave type `{}` uninitialized, which is invalid",
|
||||
ty
|
||||
),
|
||||
)?;
|
||||
|
||||
if intrinsic_name == sym::assert_uninit_valid {
|
||||
let should_panic = !self.tcx.permits_uninit_init(layout);
|
||||
|
||||
if should_panic {
|
||||
M::abort(
|
||||
self,
|
||||
format!(
|
||||
"aborted execution: attempted to leave type `{}` uninitialized, which is invalid",
|
||||
ty
|
||||
),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
sym::simd_insert => {
|
||||
|
||||
Reference in New Issue
Block a user