-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Miscompile in the GVN transform #130853
Comments
Cc @rust-lang/wg-mir-opt |
Nice find, thanks. :) |
Hmm, I don't think it's a miscompile. Your unsafe code breaks the semantic of immutable borrowing. |
The test passes Miri. So no, it does not break the semantics of immutable borrowing as we understand them currently. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-high |
Cc @rust-lang/opsem |
cc @cjgillot |
...huh, the semantics of immutable borrowing can't justify unifying two reads of a reference to a reference of a Freeze type? |
I thought this was THE optimization we were doing this for? |
There are already some discussion in the linked issue and more linked issues in it. rust-lang/unsafe-code-guidelines#532 I also agree this is my intuition about the goal of aliasing analysis. But it's not for now. So at least one of the current model and this optimization should change. BTW, the optimization in this issue already exists since 1.77.0 (https://godbolt.org/z/anPK3Ef5z) which is more than 7months ago. Is there any more user data, other than this, showing that this optimization is unintended/un-intuitive? If not, I think we may need to question about the current model itself. |
Not quite, THE optimization is for reads from a reference. The nested case is a lot more complicated, and so far there's no model at all that could justify the optimization.
Yeah that issue description still needs to be rewritten to be a self-contained introduction of the problem -- see my comment there. :)
That's what rust-lang/unsafe-code-guidelines#532 is for. But we don't do optimizations that we don't have a model for, so this remains an I-unsound issue until a model is proposed (and ideally implemented in Miri). |
Yeah, we have to drop this optimization for now, not because it is unjustifiable per se but because it is unjustified at the moment. |
@cjgillot you are our main expert for the GVN transform... any chance you could take a look at this? Or leave some notes as starting points for someone else on what would be the best way to fix this? |
Do not unify dereferences of shared borrows in GVN Repost of rust-lang#132461, the last commit applies my suggestions. Fixes rust-lang#130853
Do not unify dereferences of shared borrows in GVN Repost of rust-lang/rust#132461, the last commit applies my suggestions. Fixes rust-lang/rust#130853
I tried this code:
I expected to see this happen:
This should print
false
, as I believe this is DB under both Stacked and Tree borrows(according to MIRI).Instead, this happened:
It returns
false
in Debug mode, and the GVN MIR pass makessrc()
unconditionally returntrue
in Release mode.Meta
Here's the MIR before the GVN pass:
After
It would be justified to make
src()
returntrue
if_6
was dereferenced again inbb1
, however, the write inunknown()
shouldn't invalidate the actual pointer stored in_1
if my understanding of Stacked Borrows is correct.This is present in both Stable and Nightly.
The text was updated successfully, but these errors were encountered: