Pattern match incorrectly optimized out (bad range info handling in LLVM?) #26468
Closed
Description
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[allow(dead_code)]
enum BarMode {
Bar1,
Bar2,
}
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[allow(dead_code)]
enum Mode {
Foo(u8),
Bar(BarMode),
}
#[inline(never)]
fn broken(mode: &Mode) -> u32 {
for _ in 0..1 {
match *mode {
Mode::Bar(BarMode::Bar1) => { return 17 }
Mode::Foo(5) => { return 19 }
_ => {}
}
}
return 42;
}
fn main() {
let mode = Mode::Foo(5);
assert_eq!(broken(&mode), 19);
}
This test program should exit quietly, but with rustc -O
, it instead fails the assertion:
thread '<main>' panicked at 'assertion failed: `(left == right) && (right == left)` (left: `42`, right: `19`)', redux.rs:29
rprichard@ryan:~/mess/redux$ rustc --version --verbose
rustc 1.2.0-nightly (20d23d8e5 2015-06-18)
binary: rustc
commit-hash: 20d23d8e57c0313c811135535d6872463cc6525d
commit-date: 2015-06-18
host: x86_64-unknown-linux-gnu
release: 1.2.0-nightly
I also tested a really old 32-bit compiler, and it also failed:
rprichard@ryan:~/mess/redux$ rustn32 --version --verbose
rustc 1.0.0-nightly (c89de2c56 2015-03-28) (built 2015-03-29)
binary: rustc
commit-hash: c89de2c56baeb61e7cc434924dcc8bedd32b26b8
commit-date: 2015-03-28
build-date: 2015-03-29
host: i686-unknown-linux-gnu
release: 1.0.0-nightly
This test case is reduced from #25919.
Metadata
Assignees
Labels
No labels