Skip to content

CopyProp miscompilation when destination is borrowed #143491

Closed
@tmiasko

Description

@tmiasko
fn main() {
    let mut a;
    let mut b;
    let mut c;
    let     d = false;
    let mut p = &raw const d;
    loop {
        a = !unsafe { *p };
        b = !unsafe { *p };
        c = a;
        p = &c as *const _;
        assert_eq!({a}, {b});
    }
}
$ rustc a.rs -Cdebug-assertions=off -Zmir-opt-level=0 && ./a
# Program terminated manually. OK.
$ rustc a.rs -Cdebug-assertions=off && ./a

thread 'main' panicked at a.rs:12:9:
assertion `left == right` failed
  left: false
 right: true
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessS-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions