-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Miscompile in the GVN transform #130853
Copy link
Copy link
Closed
Labels
A-codegenArea: Code generationArea: Code generationA-mir-optArea: MIR optimizationsArea: MIR optimizationsA-mir-opt-GVNArea: MIR opt Global Value Numbering (GVN)Area: MIR opt Global Value Numbering (GVN)I-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-mir-optWorking group: MIR optimizationsWorking group: MIR optimizations
Metadata
Metadata
Assignees
Labels
A-codegenArea: Code generationArea: Code generationA-mir-optArea: MIR optimizationsArea: MIR optimizationsA-mir-opt-GVNArea: MIR opt Global Value Numbering (GVN)Area: MIR opt Global Value Numbering (GVN)I-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.WG-mir-optWorking group: MIR optimizationsWorking group: MIR optimizations
Type
Fields
Give feedbackNo fields configured for issues without a type.
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
falsein Debug mode, and the GVN MIR pass makessrc()unconditionally returntruein Release mode.$ cargo miri run Compiling sus v0.1.0 (/Users/jwong3/test/sus) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s Running `/Users/jwong3/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner target/miri/aarch64-apple-darwin/debug/sus` false$ cargo run -r Compiling sus v0.1.0 (/Users/jwong3/test/sus) Finished `release` profile [optimized] target(s) in 0.31s Running `target/release/sus` trueMeta
Here's the MIR before the GVN pass:
After
It would be justified to make
src()returntrueif_6was dereferenced again inbb1, however, the write inunknown()shouldn't invalidate the actual pointer stored in_1if my understanding of Stacked Borrows is correct.This is present in both Stable and Nightly.