Rust's Provenance APIs Let You Tell the Compiler Exactly What You Mean

Pointer Provenance in Rust vs. C++: Pointers Are Not Just Glorified Ints

Rust's Provenance APIs Let You Tell the Compiler Exactly What You Mean

Pointer provenance is the hidden compiler bookkeeping that tracks which allocation a pointer came from, and it's why Clang can optimize away a reload of a local even when an opaque function receives a pointer. Casting a pointer to an integer in C++ exposes that provenance and forces the optimizer to give up. Rust's addr(), with_addr(), and without_provenance() let you state your intent explicitly, and Miri enforces the rules.

Provenance, in short, is a hidden piece of information tracking "which allocation" a pointer originates from, which LLVM uses for optimizations.
  1. afdbcreid

    Ralf Jung's series (one of the prominent developers behind Rust's memory model and author of RustBelt) about pointers is very recommended:

    https://www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html

    https://www.ralfj.de/blog/2020/12/14/provenance.html

    https://www.ralfj.de/blog/2022/04/11/provenance-exposed.html

  2. uecker

    As far as I know, provenance is still a mess both on LLVM and GCC.

  3. jayd16

    Does C++ pointer arithmetic invalidate this post or is there some other magic there?

More from this day

2026-11-09