C has some very peculiar UB. For instance, when an allocation gets freed, then all pointers to that allocation become indeterminate values. This is sometimes called "pointer lifetime end zap". This means the following code has UB in C:
int *x = malloc(100);
free(x);
// Looking at x again is UB!
if ((uintptr_t)x == 1024) { printf("Hello!\n"); }
Obviously, the equivalent code in Rust is well-defined. Therefore, it would be good to make sure that whatever parts of GCC the backend is using are aware that Rust does not have pointer-lifetime-end-zap. I am somewhat concerned that GCC is modeled closely after C semantics and hence implicitly applies rules like that -- but I don't know how one would even begin to figure this out. Is there something like a LangRef for the GCC IR(s)?
C has some very peculiar UB. For instance, when an allocation gets freed, then all pointers to that allocation become indeterminate values. This is sometimes called "pointer lifetime end zap". This means the following code has UB in C:
Obviously, the equivalent code in Rust is well-defined. Therefore, it would be good to make sure that whatever parts of GCC the backend is using are aware that Rust does not have pointer-lifetime-end-zap. I am somewhat concerned that GCC is modeled closely after C semantics and hence implicitly applies rules like that -- but I don't know how one would even begin to figure this out. Is there something like a LangRef for the GCC IR(s)?