Unify all validity check intrinsics
Also merges the inhabitedness check into the query to further unify the code paths.
This commit is contained in:
parent
32317b5a5b
commit
1b57cb6762
@ -22,7 +22,7 @@ macro_rules! intrinsic_args {
|
||||
pub(crate) use llvm::codegen_llvm_intrinsic_call;
|
||||
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::layout::{HasParamEnv, InitKind};
|
||||
use rustc_middle::ty::layout::{HasParamEnv, ValidityRequirement};
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
@ -628,59 +628,41 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
intrinsic_args!(fx, args => (); intrinsic);
|
||||
|
||||
let ty = substs.type_at(0);
|
||||
let layout = fx.layout_of(ty);
|
||||
if layout.abi.is_uninhabited() {
|
||||
with_no_trimmed_paths!({
|
||||
crate::base::codegen_panic_nounwind(
|
||||
fx,
|
||||
&format!("attempted to instantiate uninhabited type `{}`", layout.ty),
|
||||
source_info,
|
||||
)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if intrinsic == sym::assert_zero_valid
|
||||
&& !fx
|
||||
let requirement = ValidityRequirement::from_intrinsic(intrinsic);
|
||||
|
||||
if let Some(requirement) = requirement {
|
||||
let do_panic = !fx
|
||||
.tcx
|
||||
.check_validity_of_init((InitKind::Zero, fx.param_env().and(ty)))
|
||||
.expect("expected to have layout during codegen")
|
||||
{
|
||||
.check_validity_requirement((requirement, fx.param_env().and(ty)))
|
||||
.expect("expect to have layout during codegen");
|
||||
|
||||
if do_panic {
|
||||
let layout = fx.layout_of(ty);
|
||||
|
||||
with_no_trimmed_paths!({
|
||||
crate::base::codegen_panic_nounwind(
|
||||
fx,
|
||||
&format!(
|
||||
&if layout.abi.is_uninhabited() {
|
||||
format!("attempted to instantiate uninhabited type `{}`", layout.ty)
|
||||
} else if requirement == ValidityRequirement::Zero {
|
||||
format!(
|
||||
"attempted to zero-initialize type `{}`, which is invalid",
|
||||
layout.ty
|
||||
),
|
||||
source_info,
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if intrinsic == sym::assert_mem_uninitialized_valid
|
||||
&& !fx
|
||||
.tcx
|
||||
.check_validity_of_init((
|
||||
InitKind::UninitMitigated0x01Fill,
|
||||
fx.param_env().and(ty),
|
||||
))
|
||||
.expect("expected to have layout during codegen")
|
||||
{
|
||||
with_no_trimmed_paths!({
|
||||
crate::base::codegen_panic_nounwind(
|
||||
fx,
|
||||
&format!(
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"attempted to leave type `{}` uninitialized, which is invalid",
|
||||
layout.ty
|
||||
),
|
||||
)
|
||||
},
|
||||
source_info,
|
||||
)
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sym::volatile_load | sym::unaligned_volatile_load => {
|
||||
intrinsic_args!(fx, args => (ptr); intrinsic);
|
||||
|
Loading…
Reference in New Issue
Block a user