diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2022-05-21 11:39:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-21 11:39:50 +0200 |
| commit | 6fef5f1e243c30deec7728616cdcf21c4547ab9e (patch) | |
| tree | d4240968f37b082ffb5261b45d0cdce26181e239 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| parent | e5c7b21f395d57e870eb90292726d0824a34cd10 (diff) | |
| parent | 31c3c0449807d22a0f10e7a290a8e4ed114b98d4 (diff) | |
| download | rust-6fef5f1e243c30deec7728616cdcf21c4547ab9e.tar.gz rust-6fef5f1e243c30deec7728616cdcf21c4547ab9e.zip | |
Rollup merge of #97219 - RalfJung:ptr-invalid, r=thomcc
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`
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
