Rename assert_uninit_valid
intrinsic
It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that.
This commit is contained in:
parent
32da230588
commit
8b2a7da3b0
9 changed files with 25 additions and 19 deletions
|
@ -713,7 +713,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||||
let res = CValue::by_val(swap(&mut fx.bcx, val), arg.layout());
|
let res = CValue::by_val(swap(&mut fx.bcx, val), arg.layout());
|
||||||
ret.write_cvalue(fx, res);
|
ret.write_cvalue(fx, res);
|
||||||
}
|
}
|
||||||
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
|
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_mem_uninitialized_valid => {
|
||||||
intrinsic_args!(fx, args => (); intrinsic);
|
intrinsic_args!(fx, args => (); intrinsic);
|
||||||
|
|
||||||
let layout = fx.layout_of(substs.type_at(0));
|
let layout = fx.layout_of(substs.type_at(0));
|
||||||
|
@ -742,7 +742,9 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if intrinsic == sym::assert_uninit_valid && !fx.tcx.permits_uninit_init(layout) {
|
if intrinsic == sym::assert_mem_uninitialized_valid
|
||||||
|
&& !fx.tcx.permits_uninit_init(layout)
|
||||||
|
{
|
||||||
with_no_trimmed_paths!({
|
with_no_trimmed_paths!({
|
||||||
crate::base::codegen_panic(
|
crate::base::codegen_panic(
|
||||||
fx,
|
fx,
|
||||||
|
|
|
@ -666,12 +666,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
enum AssertIntrinsic {
|
enum AssertIntrinsic {
|
||||||
Inhabited,
|
Inhabited,
|
||||||
ZeroValid,
|
ZeroValid,
|
||||||
UninitValid,
|
MemUninitializedValid,
|
||||||
}
|
}
|
||||||
let panic_intrinsic = intrinsic.and_then(|i| match i {
|
let panic_intrinsic = intrinsic.and_then(|i| match i {
|
||||||
sym::assert_inhabited => Some(AssertIntrinsic::Inhabited),
|
sym::assert_inhabited => Some(AssertIntrinsic::Inhabited),
|
||||||
sym::assert_zero_valid => Some(AssertIntrinsic::ZeroValid),
|
sym::assert_zero_valid => Some(AssertIntrinsic::ZeroValid),
|
||||||
sym::assert_uninit_valid => Some(AssertIntrinsic::UninitValid),
|
sym::assert_mem_uninitialized_valid => Some(AssertIntrinsic::MemUninitializedValid),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
if let Some(intrinsic) = panic_intrinsic {
|
if let Some(intrinsic) = panic_intrinsic {
|
||||||
|
@ -682,7 +682,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
let do_panic = match intrinsic {
|
let do_panic = match intrinsic {
|
||||||
Inhabited => layout.abi.is_uninhabited(),
|
Inhabited => layout.abi.is_uninhabited(),
|
||||||
ZeroValid => !bx.tcx().permits_zero_init(layout),
|
ZeroValid => !bx.tcx().permits_zero_init(layout),
|
||||||
UninitValid => !bx.tcx().permits_uninit_init(layout),
|
MemUninitializedValid => !bx.tcx().permits_uninit_init(layout),
|
||||||
};
|
};
|
||||||
Some(if do_panic {
|
Some(if do_panic {
|
||||||
let msg_str = with_no_visible_paths!({
|
let msg_str = with_no_visible_paths!({
|
||||||
|
|
|
@ -432,7 +432,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
sym::transmute => {
|
sym::transmute => {
|
||||||
self.copy_op(&args[0], dest, /*allow_transmute*/ true)?;
|
self.copy_op(&args[0], dest, /*allow_transmute*/ true)?;
|
||||||
}
|
}
|
||||||
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
|
sym::assert_inhabited
|
||||||
|
| sym::assert_zero_valid
|
||||||
|
| sym::assert_mem_uninitialized_valid => {
|
||||||
let ty = instance.substs.type_at(0);
|
let ty = instance.substs.type_at(0);
|
||||||
let layout = self.layout_of(ty)?;
|
let layout = self.layout_of(ty)?;
|
||||||
|
|
||||||
|
@ -464,7 +466,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if intrinsic_name == sym::assert_uninit_valid {
|
if intrinsic_name == sym::assert_mem_uninitialized_valid {
|
||||||
let should_panic = !self.tcx.permits_uninit_init(layout);
|
let should_panic = !self.tcx.permits_uninit_init(layout);
|
||||||
|
|
||||||
if should_panic {
|
if should_panic {
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
|
||||||
sym::abort
|
sym::abort
|
||||||
| sym::assert_inhabited
|
| sym::assert_inhabited
|
||||||
| sym::assert_zero_valid
|
| sym::assert_zero_valid
|
||||||
| sym::assert_uninit_valid
|
| sym::assert_mem_uninitialized_valid
|
||||||
| sym::size_of
|
| sym::size_of
|
||||||
| sym::min_align_of
|
| sym::min_align_of
|
||||||
| sym::needs_drop
|
| sym::needs_drop
|
||||||
|
@ -193,9 +193,9 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
||||||
}
|
}
|
||||||
sym::rustc_peek => (1, vec![param(0)], param(0)),
|
sym::rustc_peek => (1, vec![param(0)], param(0)),
|
||||||
sym::caller_location => (0, vec![], tcx.caller_location_ty()),
|
sym::caller_location => (0, vec![], tcx.caller_location_ty()),
|
||||||
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
|
sym::assert_inhabited
|
||||||
(1, Vec::new(), tcx.mk_unit())
|
| sym::assert_zero_valid
|
||||||
}
|
| sym::assert_mem_uninitialized_valid => (1, Vec::new(), tcx.mk_unit()),
|
||||||
sym::forget => (1, vec![param(0)], tcx.mk_unit()),
|
sym::forget => (1, vec![param(0)], tcx.mk_unit()),
|
||||||
sym::transmute => (2, vec![param(0)], param(1)),
|
sym::transmute => (2, vec![param(0)], param(1)),
|
||||||
sym::prefetch_read_data
|
sym::prefetch_read_data
|
||||||
|
|
|
@ -377,9 +377,9 @@ symbols! {
|
||||||
assert_eq_macro,
|
assert_eq_macro,
|
||||||
assert_inhabited,
|
assert_inhabited,
|
||||||
assert_macro,
|
assert_macro,
|
||||||
|
assert_mem_uninitialized_valid,
|
||||||
assert_ne_macro,
|
assert_ne_macro,
|
||||||
assert_receiver_is_total_eq,
|
assert_receiver_is_total_eq,
|
||||||
assert_uninit_valid,
|
|
||||||
assert_zero_valid,
|
assert_zero_valid,
|
||||||
asserting,
|
asserting,
|
||||||
associated_const_equality,
|
associated_const_equality,
|
||||||
|
|
|
@ -959,13 +959,14 @@ extern "rust-intrinsic" {
|
||||||
#[rustc_safe_intrinsic]
|
#[rustc_safe_intrinsic]
|
||||||
pub fn assert_zero_valid<T>();
|
pub fn assert_zero_valid<T>();
|
||||||
|
|
||||||
/// A guard for unsafe functions that cannot ever be executed if `T` has invalid
|
/// A guard for `std::mem::uninitialized`. Checks whether a repeated bit pattern `0x01`
|
||||||
/// bit patterns: This will statically either panic, or do nothing.
|
/// is legal for `T`: This will statically either panic, or do nothing.
|
||||||
///
|
///
|
||||||
/// This intrinsic does not have a stable counterpart.
|
/// This intrinsic does not have a stable counterpart.
|
||||||
#[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
|
#[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
|
||||||
#[rustc_safe_intrinsic]
|
#[rustc_safe_intrinsic]
|
||||||
pub fn assert_uninit_valid<T>();
|
#[cfg(not(bootstrap))]
|
||||||
|
pub fn assert_mem_uninitialized_valid<T>();
|
||||||
|
|
||||||
/// Gets a reference to a static `Location` indicating where it was called.
|
/// Gets a reference to a static `Location` indicating where it was called.
|
||||||
///
|
///
|
||||||
|
|
|
@ -682,7 +682,8 @@ pub unsafe fn zeroed<T>() -> T {
|
||||||
pub unsafe fn uninitialized<T>() -> T {
|
pub unsafe fn uninitialized<T>() -> T {
|
||||||
// SAFETY: the caller must guarantee that an uninitialized value is valid for `T`.
|
// SAFETY: the caller must guarantee that an uninitialized value is valid for `T`.
|
||||||
unsafe {
|
unsafe {
|
||||||
intrinsics::assert_uninit_valid::<T>();
|
#[cfg(not(bootstrap))] // If the compiler hits this itself then it deserves the UB.
|
||||||
|
intrinsics::assert_mem_uninitialized_valid::<T>();
|
||||||
let mut val = MaybeUninit::<T>::uninit();
|
let mut val = MaybeUninit::<T>::uninit();
|
||||||
|
|
||||||
// Fill memory with 0x01, as an imperfect mitigation for old code that uses this function on
|
// Fill memory with 0x01, as an imperfect mitigation for old code that uses this function on
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
||||||
//~^ERROR: evaluation of constant value failed
|
//~^ERROR: evaluation of constant value failed
|
||||||
};
|
};
|
||||||
const _BAD2: () = {
|
const _BAD2: () = {
|
||||||
intrinsics::assert_uninit_valid::<&'static i32>();
|
intrinsics::assert_mem_uninitialized_valid::<&'static i32>();
|
||||||
//~^ERROR: evaluation of constant value failed
|
//~^ERROR: evaluation of constant value failed
|
||||||
};
|
};
|
||||||
const _BAD3: () = {
|
const _BAD3: () = {
|
||||||
|
|
|
@ -7,8 +7,8 @@ LL | MaybeUninit::<!>::uninit().assume_init();
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/assert-type-intrinsics.rs:16:9
|
--> $DIR/assert-type-intrinsics.rs:16:9
|
||||||
|
|
|
|
||||||
LL | intrinsics::assert_uninit_valid::<&'static i32>();
|
LL | intrinsics::assert_mem_uninitialized_valid::<&'static i32>();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `&i32` uninitialized, which is invalid
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `&i32` uninitialized, which is invalid
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/assert-type-intrinsics.rs:20:9
|
--> $DIR/assert-type-intrinsics.rs:20:9
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue