-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Incorrect code generated by MIR optimization on nightly #101973
Comments
@rustbot prioritize |
@rustbot label regression-from-stable-to-nightly, I-unsound, A-mir-opt, T-compiler |
Can someone execute the snippet with |
I’ve made a gist originally, too, but it looks like you can’t see all the files there. (Afaict only 300 of the 401 files show up.) Edit: One downside of a repo (compared to a gist) is that I might want to get rid of it eventually; AFAIK, this shouldn’t be needed for too long anyway though. |
With an assertion instead of println: $ cat a.sh
#!/bin/bash
rustc -O -C debug-assertions=on a.rs && ./a
$ cargo-bisect-rustc --preserve --without-cargo --script ./a.sh
...
********************************************************************************
Regression in bc4b39c271bbd36736cbf1c0a1ac23d5df38d365
******************************************************************************** Individual builds from #101152 (comment), point to #100239 cc @RalfJung |
Ouch. That probably means the unsoundness was already possible before my PR (as explained there, the check it removes was ineffective), but is easier to trigger now. Cc @oli-obk @rust-lang/wg-mir-opt something is wrong in ConstProp handling of shifts and/or casts and/or bit-ops. Is there a reproducer that does not need shifts and casts and a bitop? That would make the issue easier to track down. |
FWIW it prints 0xfffffffff0000000 in Miri so the interpreter is probably fine, and it's probably a problem with the ConstProp pass itself. |
The original code was much more complex. I minimized it as much as I could, but at this point even removing a useless |
Yeah I quite appreciate that it does fit in a few lines now. :) |
The ConstProp code is super hard to read and full of subtle (usually barely documented) invariants, so... this could be an interesting one to track down. |
The inlined code looks fine, but it has the basic blocks in a strange order, which might explain why the ConstProp bug only occurs if inlining happens first. The code just before ConstProp has this
One possible explanation would be if ConstProp iterated the basic blocks in order, then by the time it reaches |
Turns out the actual problem was an early return that I added which skipped more code than it should have -- fixed by #102045. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-critical |
…, r=oli-obk fix ConstProp handling of written_only_inside_own_block_locals Fixes a regression introduced by rust-lang#100239, which adds an early return and thus skips some code in `visit_terminator` that must be run for soundness. Fixes rust-lang#101973
This code normally prints
0xfffffffff0000000
but when compiled withO -C debug-assertions=on -Zmir-opt-level=2
it produces0x0
instead. This was noticed because MIR optimization is enabled by default on the current nightly.This is the LLVM IR for the
inner
function with-C no-prepopulate-passes
. Notice how the inputs tollvm.fshr.i32
(used byrotate_right
) are0
, which is incorrect.The text was updated successfully, but these errors were encountered: