about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille Gillot <gillot.camille@gmail.com>2025-09-13 17:36:46 +0000
committerCamille Gillot <gillot.camille@gmail.com>2025-09-13 17:36:46 +0000
commitd51aec7781186ae0a7ac1073f672d08729d32f6a (patch)
tree6d0d58b7681a25032d0ebd7a5c47bcc009fc0dd8
parentb50f345a2f3f49764024cabc30ef99e15c0240f7 (diff)
downloadrust-d51aec7781186ae0a7ac1073f672d08729d32f6a.tar.gz
rust-d51aec7781186ae0a7ac1073f672d08729d32f6a.zip
Add test.
-rw-r--r--tests/mir-opt/dest-prop/aggregate.rewrap.DestinationPropagation.panic-abort.diff21
-rw-r--r--tests/mir-opt/dest-prop/aggregate.rewrap.DestinationPropagation.panic-unwind.diff21
-rw-r--r--tests/mir-opt/dest-prop/aggregate.rs49
-rw-r--r--tests/mir-opt/dest-prop/aggregate.swap.DestinationPropagation.panic-abort.diff22
-rw-r--r--tests/mir-opt/dest-prop/aggregate.swap.DestinationPropagation.panic-unwind.diff22
5 files changed, 135 insertions, 0 deletions
diff --git a/tests/mir-opt/dest-prop/aggregate.rewrap.DestinationPropagation.panic-abort.diff b/tests/mir-opt/dest-prop/aggregate.rewrap.DestinationPropagation.panic-abort.diff
new file mode 100644
index 00000000000..876c871cddd
--- /dev/null
+++ b/tests/mir-opt/dest-prop/aggregate.rewrap.DestinationPropagation.panic-abort.diff
@@ -0,0 +1,21 @@
+- // MIR for `rewrap` before DestinationPropagation
++ // MIR for `rewrap` after DestinationPropagation
+  
+  fn rewrap() -> (u8,) {
+      let mut _0: (u8,);
+      let mut _1: (u8,);
+      let mut _2: (u8,);
+  
+      bb0: {
+-         (_1.0: u8) = const 0_u8;
+-         _0 = copy _1;
+-         _2 = (copy (_0.0: u8),);
+-         _0 = copy _2;
++         (_0.0: u8) = const 0_u8;
++         nop;
++         _0 = (copy (_0.0: u8),);
++         nop;
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/dest-prop/aggregate.rewrap.DestinationPropagation.panic-unwind.diff b/tests/mir-opt/dest-prop/aggregate.rewrap.DestinationPropagation.panic-unwind.diff
new file mode 100644
index 00000000000..876c871cddd
--- /dev/null
+++ b/tests/mir-opt/dest-prop/aggregate.rewrap.DestinationPropagation.panic-unwind.diff
@@ -0,0 +1,21 @@
+- // MIR for `rewrap` before DestinationPropagation
++ // MIR for `rewrap` after DestinationPropagation
+  
+  fn rewrap() -> (u8,) {
+      let mut _0: (u8,);
+      let mut _1: (u8,);
+      let mut _2: (u8,);
+  
+      bb0: {
+-         (_1.0: u8) = const 0_u8;
+-         _0 = copy _1;
+-         _2 = (copy (_0.0: u8),);
+-         _0 = copy _2;
++         (_0.0: u8) = const 0_u8;
++         nop;
++         _0 = (copy (_0.0: u8),);
++         nop;
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/dest-prop/aggregate.rs b/tests/mir-opt/dest-prop/aggregate.rs
new file mode 100644
index 00000000000..3c14d1f94f6
--- /dev/null
+++ b/tests/mir-opt/dest-prop/aggregate.rs
@@ -0,0 +1,49 @@
+//@ test-mir-pass: DestinationPropagation
+// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
+
+#![feature(custom_mir, core_intrinsics)]
+#![allow(internal_features)]
+
+use std::intrinsics::mir::*;
+use std::mem::MaybeUninit;
+
+fn dump_var<T>(_: T) {}
+
+// EMIT_MIR aggregate.rewrap.DestinationPropagation.diff
+#[custom_mir(dialect = "runtime")]
+fn rewrap() -> (u8,) {
+    // CHECK-LABEL: fn rewrap(
+    // CHECK: (_0.0: u8) = const 0_u8;
+    // CHECK: _0 = (copy (_0.0: u8),);
+    mir! {
+        let _1: (u8,);
+        let _2: (u8,);
+        {
+            _1.0 = 0;
+            RET = _1;
+            _2 = (RET.0, );
+            RET = _2;
+            Return()
+        }
+    }
+}
+
+// EMIT_MIR aggregate.swap.DestinationPropagation.diff
+#[custom_mir(dialect = "runtime")]
+fn swap() -> (MaybeUninit<[u8; 10]>, MaybeUninit<[u8; 10]>) {
+    // CHECK-LABEL: fn swap(
+    // CHECK: _0 = const
+    // CHECK: _0 = (copy (_0.1: {{.*}}), copy (_0.0: {{.*}}));
+    mir! {
+        let _1: (MaybeUninit<[u8; 10]>, MaybeUninit<[u8; 10]>);
+        let _2: (MaybeUninit<[u8; 10]>, MaybeUninit<[u8; 10]>);
+        let _3: ();
+        {
+            _1 = const { (MaybeUninit::new([0; 10]), MaybeUninit::new([1; 10])) };
+            _2 = _1;
+            _1 = (_2.1, _2.0);
+            RET = _1;
+            Return()
+        }
+    }
+}
diff --git a/tests/mir-opt/dest-prop/aggregate.swap.DestinationPropagation.panic-abort.diff b/tests/mir-opt/dest-prop/aggregate.swap.DestinationPropagation.panic-abort.diff
new file mode 100644
index 00000000000..53849573f13
--- /dev/null
+++ b/tests/mir-opt/dest-prop/aggregate.swap.DestinationPropagation.panic-abort.diff
@@ -0,0 +1,22 @@
+- // MIR for `swap` before DestinationPropagation
++ // MIR for `swap` after DestinationPropagation
+  
+  fn swap() -> (MaybeUninit<[u8; 10]>, MaybeUninit<[u8; 10]>) {
+      let mut _0: (std::mem::MaybeUninit<[u8; 10]>, std::mem::MaybeUninit<[u8; 10]>);
+      let mut _1: (std::mem::MaybeUninit<[u8; 10]>, std::mem::MaybeUninit<[u8; 10]>);
+      let mut _2: (std::mem::MaybeUninit<[u8; 10]>, std::mem::MaybeUninit<[u8; 10]>);
+      let mut _3: ();
+  
+      bb0: {
+-         _1 = const swap::{constant#6};
+-         _2 = copy _1;
+-         _1 = (copy (_2.1: std::mem::MaybeUninit<[u8; 10]>), copy (_2.0: std::mem::MaybeUninit<[u8; 10]>));
+-         _0 = copy _1;
++         _0 = const swap::{constant#6};
++         nop;
++         _0 = (copy (_0.1: std::mem::MaybeUninit<[u8; 10]>), copy (_0.0: std::mem::MaybeUninit<[u8; 10]>));
++         nop;
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/dest-prop/aggregate.swap.DestinationPropagation.panic-unwind.diff b/tests/mir-opt/dest-prop/aggregate.swap.DestinationPropagation.panic-unwind.diff
new file mode 100644
index 00000000000..53849573f13
--- /dev/null
+++ b/tests/mir-opt/dest-prop/aggregate.swap.DestinationPropagation.panic-unwind.diff
@@ -0,0 +1,22 @@
+- // MIR for `swap` before DestinationPropagation
++ // MIR for `swap` after DestinationPropagation
+  
+  fn swap() -> (MaybeUninit<[u8; 10]>, MaybeUninit<[u8; 10]>) {
+      let mut _0: (std::mem::MaybeUninit<[u8; 10]>, std::mem::MaybeUninit<[u8; 10]>);
+      let mut _1: (std::mem::MaybeUninit<[u8; 10]>, std::mem::MaybeUninit<[u8; 10]>);
+      let mut _2: (std::mem::MaybeUninit<[u8; 10]>, std::mem::MaybeUninit<[u8; 10]>);
+      let mut _3: ();
+  
+      bb0: {
+-         _1 = const swap::{constant#6};
+-         _2 = copy _1;
+-         _1 = (copy (_2.1: std::mem::MaybeUninit<[u8; 10]>), copy (_2.0: std::mem::MaybeUninit<[u8; 10]>));
+-         _0 = copy _1;
++         _0 = const swap::{constant#6};
++         nop;
++         _0 = (copy (_0.1: std::mem::MaybeUninit<[u8; 10]>), copy (_0.0: std::mem::MaybeUninit<[u8; 10]>));
++         nop;
+          return;
+      }
+  }
+