|
| 1 | +See https://github.com/rust-lang/rust/issues/107975 |
| 2 | + |
| 3 | +Basically, if you have two pointers with the same address |
| 4 | +but from two different allocations, |
| 5 | +and then you do something with their addresses as integers, |
| 6 | +the compiler may make some very strange assumptions during the compilation, |
| 7 | +resulting in some self-contradictory behavior of the compiled code. |
| 8 | + |
| 9 | +This folder contains some examples. |
| 10 | +They all boil down to allocating a variable on the stack, taking its address, |
| 11 | +getting rid of the variable, and then doing it all again. |
| 12 | +This way we end up with two addresses stored in two `usize`s (`a` and `b`). |
| 13 | +The addresses are (probably) equal but (definitely) come from two different allocations. |
| 14 | +Logically, we would expect that exactly one of the following options holds true: |
| 15 | +1. `a == b` |
| 16 | +2. `a != b` |
| 17 | +Sadly, the compiler does not always agree. |
| 18 | + |
| 19 | +Due to Rust having at least three meaningfully different ways |
| 20 | +to get a variable's address as an `usize`, |
| 21 | +each example is provided in three versions, each in the corresponding subfolder: |
| 22 | +1. `./as-cast/` for `&v as *const _ as usize`, |
| 23 | +2. `./strict-provenance/` for `addr_of!(v).addr()`, |
| 24 | +2. `./exposed-provenance/` for `addr_of!(v).expose_provenance()`. |
0 commit comments