-
Notifications
You must be signed in to change notification settings - Fork 58
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
What are the guarantees over ZST pointers #503
Comments
|
For almost all purposes related to provenance, a pointer to a ZST is not distinct from a pointer to another type. |
Sorry, my phone keeps auto correcting provenance for some reason. Or maybe it was my brain malfunction. 🤷🏻♀️ |
I thought that was still up for debate from reading this issue: #239 |
For further information on provenance, see the RFC. The pointee type and being a reference vs a raw pointer makes no difference for provenance.
Yes, we haven't made an official t-lang decision on this. But at this point it seems unlikely that provenance will affect pointer comparison. The main unknown here is how to resolve #328. On today's Rust, provenance does not affect pointer comparison.
The Rust specification does not have a notion of memory sections for statics or stack frames. All allocated objects are placed at arbitrary locations in memory and there is no guarantee whatsoever that stack allocations are in "the stack" or I think this answers all questions, or would you like further clarification? |
https://doc.rust-lang.org/reference/variables.html says that "A local variable (or stack-local allocation) holds a value directly, allocated within the stack's memory." (And https://doc.rust-lang.org/reference/memory-allocation-and-lifetime.html says something about Box and heap, but indeed does not promise that all Box allocations would be on the heap.) |
That should be fixed then, these guarantees make no sense on the level of the Rust spec. Stack and heap as distinct parts of the address space are target-specific notions that do not exist in the Abstract Machine. |
I think that would be a simple way to go about it, since these are no-op, but if I understand it correctly, a zero-size access is invalid if the pointer points to a deallocated memory, correct? I'm assuming that's because of provenance. I am curious if provenance is also taken into account if the pointer is out-of-bounds of the original object? Would a zero-size access be valid in out-of-bounds pointers? |
This used to be the case but we decided to change it and allow more code. See rust-lang/rust#117945. Once that is fully implemented, zero-sized accesses will ignore provenance.
Under the current rules as implemented by Miri today, that would be UB. But rust-lang/rust#117945 will make it allowed. |
I think this answers all my questions. Thank you! |
Sure, happy to help. :) |
Hi, we've been trying to understand what's the correct way to model ZST pointers. What is UB and what has well defined behavior.
Thanks!
The text was updated successfully, but these errors were encountered: