Skip to content

Commit 4d8bda3

Browse files
committed
Add a regression test for rust-lang#132353
To catch at least one pattern that was miscompiled. The test is a minimization of the MCVE reported in <rust-lang#132353>.
1 parent 75eff9a commit 4d8bda3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! The mir-opt added in <https://github.com/rust-lang/rust/pull/128299> unfortunately seems to lead
2+
//! to a miscompile (reported in <https://github.com/rust-lang/rust/issues/132353>, minimization
3+
//! reproduced in this test file).
4+
//@ revisions: release debug
5+
// Note: it's not strictly cargo's release profile, but any non-zero opt-level was sufficient to
6+
// reproduce the miscompile.
7+
//@[release] compile-flags: -C opt-level=1
8+
//@[debug] compile-flags: -C opt-level=0
9+
//@ run-pass
10+
11+
fn pop_min(mut score2head: Vec<Option<usize>>) -> Option<usize> {
12+
loop {
13+
if let Some(col) = score2head[0] {
14+
score2head[0] = None;
15+
return Some(col);
16+
}
17+
}
18+
}
19+
20+
fn main() {
21+
let min = pop_min(vec![Some(1)]);
22+
println!("min: {:?}", min);
23+
// panic happened on 1.83.0 beta in release mode but not debug mode.
24+
let _ = min.unwrap();
25+
}

0 commit comments

Comments
 (0)