Skip to content

Unsound mir-opt level 4 with loops and .try_into().unwrap_or() #108360

Closed
@lukas-code

Description

@lukas-code

I tried this code:

fn main() {
    for x in 0..1 {
        let mut value = 0u8;
        value = x.try_into().unwrap_or(42);
        assert_eq!(value, 0);
    }
}

run with

RUSTFLAGS=-Zmir-opt-level=4 cargo run

I expected to see this happen: doesn't panic

Instead, this happened:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `42`,
 right: `0`', src/main.rs:5:9

Meta

rustc --version --verbose:

rustc 1.69.0-nightly (246eae2fa 2023-02-21)
binary: rustc
commit-hash: 246eae2fab54a5139365c4e1a08c5724fb385fbf
commit-date: 2023-02-21
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Bisect

searched nightlies: from nightly-2023-02-16 to nightly-2023-02-22
regressed nightly: nightly-2023-02-17
searched commit range: 2d14db3...9a7cc6c
regressed commit: 639377e -> #107449

bisected with cargo-bisect-rustc v0.6.5

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --script=script.sh 

script.sh:

#!/bin/sh
RUSTFLAGS=-Zmir-opt-level=4 cargo run

@rustbot label A-mir-opt requires-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions