Pointer provenance is the hidden relationship between a pointer and the memory allocation it came from. It matters because compilers use that relationship to decide whether two pointers can refer to the same memory and whether a value must be reloaded after a function call. In the examples, a compiler can keep a local variable’s value in a register when an unrelated pointer is passed to an opaque function, because that pointer was not derived from the variable. Provenance is not normally stored as an extra field beside the address; it is an abstract property tracked by the compiler, illustrated through LLVM’s intermediate representation.
Converting a pointer to an integer in C++ exposes its address, so the compiler must account for the possibility that the integer could later be converted back into a pointer and used to reach the same allocation. Rust offers APIs that make these intentions clearer: addr() reads the numeric address without exposing provenance, while with_addr() changes a pointer’s address but retains its original provenance. This supports techniques such as tagging aligned pointers with status bits, provided the tagged, misaligned pointer is not dereferenced. Integer casts in older Rust code can still work, but Miri warns that they may conceal pointer errors. Conversely, without_provenance() creates a pointer with no associated allocation, which cannot be dereferenced. These distinctions help both compiler reasoning and tools that detect undefined behavior.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.