Posted by germanrabbit 2 days ago
Behaviour that is not defined is undefined behaviour. Integer to pointer conversion is IDB, which is the same as UB except that a conforming compiler documents what could happen. I believe it's typically documented as unpredictable, so the same as plain UB.
UB means your program is not a C program and has no semantics whatsoever past the point it reaches the UB. The compiler is thus free to assume that the point that the UB would happen can't be reached and optimize in accordance to that assumption - which many modern compilers do, with often unexpected consequences (such as the infamous case of removing an integer overflow check in Linux because an_int+1>an_int is guaranteed to be true in the C abstract model).
https://gcc.gnu.org/onlinedocs/gcc/Arrays-and-pointers-imple...
So I'm right. This is implementation-defined, and the way the implementation has defined it is to make it fully UB (except for round trips).