-
Notifications
You must be signed in to change notification settings - Fork 13k
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
InstCombine introduces an incorrect use of a local after its storage has ended #78192
Comments
I will open a PR to disable problematic part of InstCombine for now. |
Did you bisect the regression to #76683? |
Disable "optimization to avoid load of address" in InstCombine The transformation is incorrect rust-lang#78192. Disable it.
I see that we've disabled the optimization, can't we also add a regression test for it? cc @tmiasko EDIT (camelid): See the relevant discussion in wg-prioritization. |
Assigning |
Is the cause of the unsoundness in this code? I haven't done MIR stuff before, but it looks like to me like it's not checking that the storage is live... rust/compiler/rustc_mir/src/transform/instcombine.rs Lines 149 to 167 in 1d27267
|
The optimization starts by locating a dereference of a local:
is changed as follows (there is an additional change in the diff, but it is a separate optimization, so lets ignore it):
In this case, the primary issue is that reading |
Example that leads to an end-to-end miscompilation: fn main() {
let a = 1u32;
let b = 2u32;
let mut c: *const u32 = &a;
let d: &u32 = &b;
let x = unsafe { &*c };
c = d;
let z = *x;
assert_eq!(1, z);
} |
Fix rust-lang#78192 Check which places are marked dead. Fixes rust-lang#78192
Fix rust-lang#78192 Check which places are marked dead. Fixes rust-lang#78192
Fix rust-lang#78192 Check which places are marked dead. Fixes rust-lang#78192
Rollup of 10 pull requests Successful merges: - rust-lang#74477 (`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm) - rust-lang#77836 (transmute_copy: explain that alignment is handled correctly) - rust-lang#78126 (Properly define va_arg and va_list for aarch64-apple-darwin) - rust-lang#78137 (Initialize tracing subscriber in compiletest tool) - rust-lang#78161 (Add issue template link to IRLO) - rust-lang#78214 (Tweak match arm semicolon removal suggestion to account for futures) - rust-lang#78247 (Fix rust-lang#78192) - rust-lang#78252 (Add codegen test for rust-lang#45964) - rust-lang#78268 (Do not try to report on closures to avoid ICE) - rust-lang#78295 (Add some regression tests) Failed merges: r? `@ghost`
This is now enabled by default again, and still an issue. Example from #78192 (comment): $ rustc +stage1 -Aunused a.rs -Zmir-opt-level=0 && ./a
$ rustc +stage1 -Aunused a.rs && ./a
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `1`,
right: `2`', a.rs:12:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace |
Assigning |
I will have time to investigate this after today 1700(utc+1). If anyone finds the cause or arrives at a solution before, go ahead and open a PR. |
This optimization should stay disabled by default until we're sure that it is sound. |
Opened #78434 to disable it |
Do not apply the optimization if we deref a mutable ref
Why was this reopened and then closed? |
I closed it because the code responsible is no longer there. |
Found by MIR validator #77369 & #78147.
cc @simonvandel #76683
The text was updated successfully, but these errors were encountered: