Pre-RFC: Conditionally-supported volatile access to address 0

Rust assumes a pointer that is bitwise equivalent with 0usize cannot be used to validily access any object. This has the particular noted effect to making references invalid for such a value. Presently, with this behaviour, trying to stick that reference into an Option<&T> may just turn that option into a None (particularily, if the Option<&T> is then subsequently accessed from a point which is opaque to those optimizations). The current stance of rust, and in particular the unsafe coding guidelines, is that even producing a null &T or NonNull<T> is undefined behaviour, even if you don't use it any further (see Why even unused data needs to be valid). Additionally, llvm may make even further blind assumptions about an access to address 0 (given the fact it thinks it cannot be done in most cases).

The avoidance of undefined behaviour that isn't assigned meaning by non-standard extensions in use, even though it will probably work, is an absolute requirement of all of my code. On principle, I do not write code that depends on undefined behaviour to evaluate properly, because inheriently, that code is broken beyond all consideration. Even if it will probably work, that doesn't mean it won't break at some point in the future, and break heavily, to the point where all of the code relying on it is now entirely non-functional.

2 Likes