about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authorDianQK <dianqk@dianqk.net>2024-12-09 20:25:41 +0800
committerDianQK <dianqk@dianqk.net>2024-12-09 21:06:29 +0800
commitd0986f45e094b011d132238563b05c09e4f1e20e (patch)
tree0b78a7e65bbba6f4250ae4f998a61c82b9a0a3ed /tests/ui
parent1b3fb316751227d30b1523ed0e3f00d83956d4d0 (diff)
downloadrust-d0986f45e094b011d132238563b05c09e4f1e20e.tar.gz
rust-d0986f45e094b011d132238563b05c09e4f1e20e.zip
dataflow_const_prop: do not eval a ptr address in SwitchInt
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/dataflow_const_prop/ptr-in-switch-int-issue-131227.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/ui/dataflow_const_prop/ptr-in-switch-int-issue-131227.rs b/tests/ui/dataflow_const_prop/ptr-in-switch-int-issue-131227.rs
new file mode 100644
index 00000000000..7a55e13d0ee
--- /dev/null
+++ b/tests/ui/dataflow_const_prop/ptr-in-switch-int-issue-131227.rs
@@ -0,0 +1,19 @@
+//! Issue: <https://github.com/rust-lang/rust/issues/131227>
+//! Test that constant propagation in SwitchInt does not crash
+//! when encountering a ptr-to-int transmute.
+
+//@ check-pass
+//@ compile-flags: -Zmir-enable-passes=+InstSimplify-before-inline,+DataflowConstProp
+
+#![crate_type = "lib"]
+
+static mut G: i32 = 0;
+
+pub fn myfunc() -> i32 {
+    let var = &raw mut G;
+    let u: usize = unsafe { std::mem::transmute(var) };
+    match u {
+        0 => 0,
+        _ => 1,
+    }
+}