-
Notifications
You must be signed in to change notification settings - Fork 13.3k
GVN misunderstands aliasing, can create overlapping assignments #141038
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
Labels
A-mir-opt
Area: MIR optimizations
A-mir-opt-GVN
Area: MIR opt Global Value Numbering (GVN)
A-rustlantis
A miscompilation found by Rustlantis
C-bug
Category: This is a bug.
I-miscompile
Issue: Correct Rust code lowers to incorrect machine code
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
P-medium
Medium priority
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
Found a similar issue with GVN, the reproducer looks different but I suspect it's the same aliasing problem: #![feature(custom_mir, core_intrinsics)]
#![allow(internal_features)]
use std::intrinsics::mir::*;
#[custom_mir(dialect = "runtime")]
fn main() {
mir!{
let _1;
let _2: &'static i32;
let _3;
let _4;
let _5;
let _6: &'static i32;
let _7;
let _8;
let _9;
{
_4 = 0;
_5 = 0;
_6 = &_4;
_2 = _6;
_7 = [*_2, *_2, *_2, *_2, *_2];
Goto(bb1)
}
bb1 = {
_3 = 0;
match _5 {
0 => bb2,
_ => bb1,
}
}
bb2 = {
_6 = &_9;
_8 = &_7[_5];
_5 = 5;
match _3 {
0 => bb3,
_ => bb2,
}
}
bb3 = {
_1 = *_8;
Return()
}
}
}
bb2: {
_6 = &_9;
_8 = &_7[_5];
_5 = const 5_usize;
- switchInt(copy _3) -> [0: bb3, otherwise: bb2];
+ switchInt(const 0_i32) -> [0: bb3, otherwise: bb2];
}
bb3: {
- _1 = copy (*_8);
+ _1 = copy _7[_5];
return;
} |
#141218 fixes the first one. |
fmease
added a commit
to fmease/rust
that referenced
this issue
May 18, 2025
gvn: avoid creating overlapping assignments Quick fix rust-lang#141038, as I couldn't find a way to avoid in-place modification. I'm considering handling all `ravlue` modifications within the `visit_statement` function. r? mir-opt
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
May 18, 2025
Rollup merge of rust-lang#141218 - dianqk:gvn-overlapping, r=oli-obk gvn: avoid creating overlapping assignments Quick fix rust-lang#141038, as I couldn't find a way to avoid in-place modification. I'm considering handling all `ravlue` modifications within the `visit_statement` function. r? mir-opt
Reopen for the second one. |
I think this could be a new issue: #141251. Also, I'd like to backport this fix. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-mir-opt
Area: MIR optimizations
A-mir-opt-GVN
Area: MIR opt Global Value Numbering (GVN)
A-rustlantis
A miscompilation found by Rustlantis
C-bug
Category: This is a bug.
I-miscompile
Issue: Correct Rust code lowers to incorrect machine code
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
P-medium
Medium priority
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Reduced example from rustlantis, which is accepted by Miri without optimizations enabled:
If I run this under Miri with
-Zmir-enable-passes=+GVN
, I see:The MIR diff for GVN is:
The text was updated successfully, but these errors were encountered: