rust-lang / miri

An interpreter for Rust's mid-level intermediate representation
Apache License 2.0
4.17k stars 320 forks source link

Sometimes reuse stack addresses #3487

Open RalfJung opened 2 months ago

RalfJung commented 2 months ago

In real executions, when a function returns and the same function is called again, variables will often get the same address again. In Miri this never happens; address reuse is disabled for stack variables currently. This is because the reuse pool is shared among all threads, and address reuse induces synchronization, so by reusing stack addresses from different threads we basically kill weak memory emulation and data race detection as everything is always synchronized.

We could still do address reuse for stack allocations within the same thread though. This should probably be a separate per-thread reuse pool. Stack allocations are very common so we need to be careful with the performance impact.