mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-31 00:53:48 +00:00
6fef5f1e24
make ptr::invalid not the same as a regular int2ptr cast In Miri, we would like to distinguish `ptr::invalid` from `ptr::from_exposed_provenance`, so that we can provide better diagnostics issues like https://github.com/rust-lang/miri/issues/2134, and so that we can detect the UB in programs like ```rust fn main() { let x = 0u8; let original_ptr = &x as *const u8; let addr = original_ptr.expose_addr(); let new_ptr: *const u8 = core::ptr::invalid(addr); unsafe { dbg!(*new_ptr); } } ``` To achieve that, the two functions need to have different implementations. Currently, both are just `as` casts. We *could* add an intrinsic for this, but it turns out `transmute` already has the right behavior, at least as far as Miri is concerned. So I propose we just use that. Cc `@Gankra` |
||
---|---|---|
.. | ||
alloc | ||
backtrace@b02ed04a7e | ||
core | ||
panic_abort | ||
panic_unwind | ||
portable-simd | ||
proc_macro | ||
profiler_builtins | ||
rtstartup | ||
rustc-std-workspace-alloc | ||
rustc-std-workspace-core | ||
rustc-std-workspace-std | ||
std | ||
stdarch@28335054b1 | ||
test | ||
unwind |