Skip to content

Commit bdbe392

Browse files
committed
Auto merge of #105613 - Nilstrieb:rename-assert_uninit_valid, r=RalfJung
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 is actually not fully correct though, as it does still panic for all uninit with `-Zstrict-init-checks`. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag? I don't think having it makes a lot of sense anymore with the direction that we have chose to go. It could be relevant again if #100423 lands so removing it may be a bit over eager. r? `@RalfJung`
2 parents b569c9d + 6f21ba4 commit bdbe392

File tree

9 files changed

+24
-19
lines changed

9 files changed

+24
-19
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
644644
let res = CValue::by_val(res, arg.layout());
645645
ret.write_cvalue(fx, res);
646646
}
647-
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
647+
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_mem_uninitialized_valid => {
648648
intrinsic_args!(fx, args => (); intrinsic);
649649

650650
let layout = fx.layout_of(substs.type_at(0));
@@ -673,7 +673,9 @@ fn codegen_regular_intrinsic_call<'tcx>(
673673
return;
674674
}
675675

676-
if intrinsic == sym::assert_uninit_valid && !fx.tcx.permits_uninit_init(layout) {
676+
if intrinsic == sym::assert_mem_uninitialized_valid
677+
&& !fx.tcx.permits_uninit_init(layout)
678+
{
677679
with_no_trimmed_paths!({
678680
crate::base::codegen_panic(
679681
fx,

compiler/rustc_codegen_ssa/src/mir/block.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
663663
enum AssertIntrinsic {
664664
Inhabited,
665665
ZeroValid,
666-
UninitValid,
666+
MemUninitializedValid,
667667
}
668668
let panic_intrinsic = intrinsic.and_then(|i| match i {
669669
sym::assert_inhabited => Some(AssertIntrinsic::Inhabited),
670670
sym::assert_zero_valid => Some(AssertIntrinsic::ZeroValid),
671-
sym::assert_uninit_valid => Some(AssertIntrinsic::UninitValid),
671+
sym::assert_mem_uninitialized_valid => Some(AssertIntrinsic::MemUninitializedValid),
672672
_ => None,
673673
});
674674
if let Some(intrinsic) = panic_intrinsic {
@@ -679,7 +679,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
679679
let do_panic = match intrinsic {
680680
Inhabited => layout.abi.is_uninhabited(),
681681
ZeroValid => !bx.tcx().permits_zero_init(layout),
682-
UninitValid => !bx.tcx().permits_uninit_init(layout),
682+
MemUninitializedValid => !bx.tcx().permits_uninit_init(layout),
683683
};
684684
Some(if do_panic {
685685
let msg_str = with_no_visible_paths!({

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
428428
sym::transmute => {
429429
self.copy_op(&args[0], dest, /*allow_transmute*/ true)?;
430430
}
431-
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
431+
sym::assert_inhabited
432+
| sym::assert_zero_valid
433+
| sym::assert_mem_uninitialized_valid => {
432434
let ty = instance.substs.type_at(0);
433435
let layout = self.layout_of(ty)?;
434436

@@ -460,7 +462,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
460462
}
461463
}
462464

463-
if intrinsic_name == sym::assert_uninit_valid {
465+
if intrinsic_name == sym::assert_mem_uninitialized_valid {
464466
let should_panic = !self.tcx.permits_uninit_init(layout);
465467

466468
if should_panic {

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
7575
sym::abort
7676
| sym::assert_inhabited
7777
| sym::assert_zero_valid
78-
| sym::assert_uninit_valid
78+
| sym::assert_mem_uninitialized_valid
7979
| sym::size_of
8080
| sym::min_align_of
8181
| sym::needs_drop
@@ -193,9 +193,9 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
193193
}
194194
sym::rustc_peek => (1, vec![param(0)], param(0)),
195195
sym::caller_location => (0, vec![], tcx.caller_location_ty()),
196-
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
197-
(1, Vec::new(), tcx.mk_unit())
198-
}
196+
sym::assert_inhabited
197+
| sym::assert_zero_valid
198+
| sym::assert_mem_uninitialized_valid => (1, Vec::new(), tcx.mk_unit()),
199199
sym::forget => (1, vec![param(0)], tcx.mk_unit()),
200200
sym::transmute => (2, vec![param(0)], param(1)),
201201
sym::prefetch_read_data

compiler/rustc_span/src/symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ symbols! {
376376
assert_eq_macro,
377377
assert_inhabited,
378378
assert_macro,
379+
assert_mem_uninitialized_valid,
379380
assert_ne_macro,
380381
assert_receiver_is_total_eq,
381-
assert_uninit_valid,
382382
assert_zero_valid,
383383
asserting,
384384
associated_const_equality,

library/core/src/intrinsics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -959,13 +959,13 @@ extern "rust-intrinsic" {
959959
#[rustc_safe_intrinsic]
960960
pub fn assert_zero_valid<T>();
961961

962-
/// A guard for unsafe functions that cannot ever be executed if `T` has invalid
963-
/// bit patterns: This will statically either panic, or do nothing.
962+
/// A guard for `std::mem::uninitialized`. This will statically either panic, or do nothing.
964963
///
965964
/// This intrinsic does not have a stable counterpart.
966965
#[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
967966
#[rustc_safe_intrinsic]
968-
pub fn assert_uninit_valid<T>();
967+
#[cfg(not(bootstrap))]
968+
pub fn assert_mem_uninitialized_valid<T>();
969969

970970
/// Gets a reference to a static `Location` indicating where it was called.
971971
///

library/core/src/mem/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ pub unsafe fn zeroed<T>() -> T {
682682
pub unsafe fn uninitialized<T>() -> T {
683683
// SAFETY: the caller must guarantee that an uninitialized value is valid for `T`.
684684
unsafe {
685-
intrinsics::assert_uninit_valid::<T>();
685+
#[cfg(not(bootstrap))] // If the compiler hits this itself then it deserves the UB.
686+
intrinsics::assert_mem_uninitialized_valid::<T>();
686687
let mut val = MaybeUninit::<T>::uninit();
687688

688689
// Fill memory with 0x01, as an imperfect mitigation for old code that uses this function on

src/test/ui/consts/assert-type-intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
//~^ERROR: evaluation of constant value failed
1414
};
1515
const _BAD2: () = {
16-
intrinsics::assert_uninit_valid::<&'static i32>();
16+
intrinsics::assert_mem_uninitialized_valid::<&'static i32>();
1717
//~^ERROR: evaluation of constant value failed
1818
};
1919
const _BAD3: () = {

src/test/ui/consts/assert-type-intrinsics.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | MaybeUninit::<!>::uninit().assume_init();
77
error[E0080]: evaluation of constant value failed
88
--> $DIR/assert-type-intrinsics.rs:16:9
99
|
10-
LL | intrinsics::assert_uninit_valid::<&'static i32>();
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `&i32` uninitialized, which is invalid
10+
LL | intrinsics::assert_mem_uninitialized_valid::<&'static i32>();
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `&i32` uninitialized, which is invalid
1212

1313
error[E0080]: evaluation of constant value failed
1414
--> $DIR/assert-type-intrinsics.rs:20:9

0 commit comments

Comments
 (0)