mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
Ensure copy* intrinsics also perform the static self-init checks
This commit is contained in:
@@ -1412,8 +1412,13 @@ pub fn mem_copy_repeatedly(
|
||||
let src_alloc = self.get_alloc_raw(src_alloc_id)?;
|
||||
let src_range = alloc_range(src_offset, size);
|
||||
assert!(!self.memory.validation_in_progress.get(), "we can't be copying during validation");
|
||||
// For the overlapping case, it is crucial that we trigger the read hook
|
||||
|
||||
// Trigger read hooks.
|
||||
// For the overlapping case, it is crucial that we trigger the read hooks
|
||||
// before the write hook -- the aliasing model cares about the order.
|
||||
if let Ok((alloc_id, ..)) = self.ptr_try_get_alloc_id(src, size.bytes() as i64) {
|
||||
M::before_alloc_read(self, alloc_id)?;
|
||||
}
|
||||
M::before_memory_read(
|
||||
tcx,
|
||||
&self.machine,
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
//@ check-pass
|
||||
//! This test checks the one code path that does not go through
|
||||
//! the regular CTFE memory access (as an optimization). We forgot
|
||||
//! to duplicate the static item self-initialization check, allowing
|
||||
//! reading from the uninitialized static memory before it was
|
||||
//! initialized at the end of the static initializer.
|
||||
//!
|
||||
//! https://github.com/rust-lang/rust/issues/142532
|
||||
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
pub static X: (i32, MaybeUninit<i32>) = (1, foo(&X.0));
|
||||
//~^ ERROR: encountered static that tried to initialize itself with itself
|
||||
|
||||
const fn foo(x: &i32) -> MaybeUninit<i32> {
|
||||
let mut temp = MaybeUninit::<i32>::uninit();
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
error[E0080]: encountered static that tried to initialize itself with itself
|
||||
--> $DIR/read_before_init.rs:11:45
|
||||
|
|
||||
LL | pub static X: (i32, MaybeUninit<i32>) = (1, foo(&X.0));
|
||||
| ^^^^^^^^^ evaluation of `X` failed inside this call
|
||||
|
|
||||
note: inside `foo`
|
||||
--> $DIR/read_before_init.rs:17:9
|
||||
|
|
||||
LL | std::ptr::copy(x, temp.as_mut_ptr(), 1);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: inside `std::ptr::copy::<i32>`
|
||||
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
Reference in New Issue
Block a user