Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the GCC backend does not assume "pointer lifetime end zap" rules #517

Open
RalfJung opened this issue May 10, 2024 · 0 comments
Open

Comments

@RalfJung
Copy link
Member

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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant