-
Notifications
You must be signed in to change notification settings - Fork 60
Stacked Borrows: not enough UB to justify noalias
on Box
#376
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
Comments
The implementation of Stacked Borrows in Miri deliberately doesn't create a protector for If the answers to my questions are yes, I wonder if we could fix this by weakening protectors so that they do not completely forbid deallocation. At least as far as I can understand, what LLVM wants is to insert speculative reads. If deallocating a protected pointer is for sure the last thing that a function does before returning, it seems to me like that would be compatible with inserting speculative reads. |
On
The speculative read could still be inserted after that last thing. I don't see how this can work. (Leaving aside the question of how to formalize "the last thing a function does before returning".) I have a pretty clear idea for a fix: we need a weaker kind of protector, that still disallows any action by other pointers that would invalidate this one, but allows this pointer itself to be used for deallocation. |
#377 describes the fix in some more detail, and rust-lang/miri#2684 implements it in Miri. |
Stack borrows: weak protectors This addresses the issue described in rust-lang/unsafe-code-guidelines#376.
…, r=saethlin Stack borrows: weak protectors This addresses the issue described in rust-lang/unsafe-code-guidelines#376.
Uh oh!
There was an error while loading. Please reload this page.
The following example passes Miri, but has UB in LLVM:
The reason for this is that we allow a
Box
pointer to be invalidated whiletest
runs (which is necessary because the function might deallocate it), so Stacked Borrows says it is fine to use an aliasing pointer (y
) whiletest
runs as long as we don't usex
again afterwards.The text was updated successfully, but these errors were encountered: