Sync from rust 44cfafe2fafe816395d3acc434663a45d5178c41
This commit is contained in:
commit
cceea847dd
@ -21,7 +21,8 @@ mod simd;
|
|||||||
pub(crate) use cpuid::codegen_cpuid_call;
|
pub(crate) use cpuid::codegen_cpuid_call;
|
||||||
pub(crate) use llvm::codegen_llvm_intrinsic_call;
|
pub(crate) use llvm::codegen_llvm_intrinsic_call;
|
||||||
|
|
||||||
use rustc_middle::ty::layout::HasParamEnv;
|
use rustc_middle::ty;
|
||||||
|
use rustc_middle::ty::layout::{HasParamEnv, ValidityRequirement};
|
||||||
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
|
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
|
||||||
use rustc_middle::ty::subst::SubstsRef;
|
use rustc_middle::ty::subst::SubstsRef;
|
||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
@ -634,37 +635,35 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
|||||||
intrinsic_args!(fx, args => (); intrinsic);
|
intrinsic_args!(fx, args => (); intrinsic);
|
||||||
|
|
||||||
let ty = substs.type_at(0);
|
let ty = substs.type_at(0);
|
||||||
let layout = fx.layout_of(ty);
|
|
||||||
let do_panic = match intrinsic {
|
let requirement = ValidityRequirement::from_intrinsic(intrinsic);
|
||||||
sym::assert_inhabited => layout.abi.is_uninhabited(),
|
|
||||||
sym::assert_zero_valid => !fx
|
if let Some(requirement) = requirement {
|
||||||
|
let do_panic = !fx
|
||||||
.tcx
|
.tcx
|
||||||
.permits_zero_init(fx.param_env().and(ty))
|
.check_validity_requirement((requirement, fx.param_env().and(ty)))
|
||||||
.expect("expected to have layout during codegen"),
|
.expect("expect to have layout during codegen");
|
||||||
sym::assert_mem_uninitialized_valid => !fx
|
|
||||||
.tcx
|
if do_panic {
|
||||||
.permits_uninit_init(fx.param_env().and(ty))
|
let layout = fx.layout_of(ty);
|
||||||
.expect("expected to have layout during codegen"),
|
let msg_str = with_no_visible_paths!({
|
||||||
_ => unreachable!(),
|
with_no_trimmed_paths!({
|
||||||
};
|
if layout.abi.is_uninhabited() {
|
||||||
if do_panic {
|
// Use this error even for the other intrinsics as it is more precise.
|
||||||
let msg_str = with_no_visible_paths!({
|
format!("attempted to instantiate uninhabited type `{}`", ty)
|
||||||
with_no_trimmed_paths!({
|
} else if intrinsic == sym::assert_zero_valid {
|
||||||
if layout.abi.is_uninhabited() {
|
format!("attempted to zero-initialize type `{}`, which is invalid", ty)
|
||||||
// Use this error even for the other intrinsics as it is more precise.
|
} else {
|
||||||
format!("attempted to instantiate uninhabited type `{}`", ty)
|
format!(
|
||||||
} else if intrinsic == sym::assert_zero_valid {
|
"attempted to leave type `{}` uninitialized, which is invalid",
|
||||||
format!("attempted to zero-initialize type `{}`, which is invalid", ty)
|
ty
|
||||||
} else {
|
)
|
||||||
format!(
|
}
|
||||||
"attempted to leave type `{}` uninitialized, which is invalid",
|
})
|
||||||
ty
|
});
|
||||||
)
|
crate::base::codegen_panic_nounwind(fx, &msg_str, source_info);
|
||||||
}
|
return;
|
||||||
})
|
}
|
||||||
});
|
|
||||||
crate::base::codegen_panic_nounwind(fx, &msg_str, source_info);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user