about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-10-30 20:17:42 +0800
committer许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-10-31 13:12:22 +0800
commit4d8bda335e23b7ff10ff0c645c825a90fc2646bb (patch)
treeacf4bfd5ee381d2c6b1b65ab3854c983ee9c8de3
parent75eff9a5749411ba5a0b37cc3299116c4e263075 (diff)
downloadrust-4d8bda335e23b7ff10ff0c645c825a90fc2646bb.tar.gz
rust-4d8bda335e23b7ff10ff0c645c825a90fc2646bb.zip
Add a regression test for #132353
To catch at least one pattern that was miscompiled. The test is a
minimization of the MCVE reported in
<https://github.com/rust-lang/rust/issues/132353>.
-rw-r--r--tests/ui/mir/clone-canonicalization-miscompile-132353.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/mir/clone-canonicalization-miscompile-132353.rs b/tests/ui/mir/clone-canonicalization-miscompile-132353.rs
new file mode 100644
index 00000000000..ba740c10f90
--- /dev/null
+++ b/tests/ui/mir/clone-canonicalization-miscompile-132353.rs
@@ -0,0 +1,25 @@
+//! The mir-opt added in <https://github.com/rust-lang/rust/pull/128299> unfortunately seems to lead
+//! to a miscompile (reported in <https://github.com/rust-lang/rust/issues/132353>, minimization
+//! reproduced in this test file).
+//@ revisions: release debug
+// Note: it's not strictly cargo's release profile, but any non-zero opt-level was sufficient to
+// reproduce the miscompile.
+//@[release] compile-flags: -C opt-level=1
+//@[debug] compile-flags: -C opt-level=0
+//@ run-pass
+
+fn pop_min(mut score2head: Vec<Option<usize>>) -> Option<usize> {
+    loop {
+        if let Some(col) = score2head[0] {
+            score2head[0] = None;
+            return Some(col);
+        }
+    }
+}
+
+fn main() {
+    let min = pop_min(vec![Some(1)]);
+    println!("min: {:?}", min);
+    // panic happened on 1.83.0 beta in release mode but not debug mode.
+    let _ = min.unwrap();
+}