about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2025-06-16 14:07:25 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2025-06-16 14:07:25 +0000
commit71afc6f463f141965c3a7aff70be3e4fe55c15ce (patch)
tree47f6c9b3df9c6368b5d8d16c3d4d7f0ef6270d1b /tests
parent75e7cf5f85aad82331a38deff24845b63eaf30f3 (diff)
downloadrust-71afc6f463f141965c3a7aff70be3e4fe55c15ce.tar.gz
rust-71afc6f463f141965c3a7aff70be3e4fe55c15ce.zip
Add test.
Diffstat (limited to 'tests')
-rw-r--r--tests/mir-opt/copy-prop/write_to_borrowed.main.CopyProp.diff31
-rw-r--r--tests/mir-opt/copy-prop/write_to_borrowed.rs45
2 files changed, 76 insertions, 0 deletions
diff --git a/tests/mir-opt/copy-prop/write_to_borrowed.main.CopyProp.diff b/tests/mir-opt/copy-prop/write_to_borrowed.main.CopyProp.diff
new file mode 100644
index 00000000000..eb73f8c1755
--- /dev/null
+++ b/tests/mir-opt/copy-prop/write_to_borrowed.main.CopyProp.diff
@@ -0,0 +1,31 @@
+- // MIR for `main` before CopyProp
++ // MIR for `main` after CopyProp
+  
+  fn main() -> () {
+      let mut _0: ();
+      let mut _1: *const char;
+      let mut _2: char;
+      let mut _3: char;
+      let mut _4: char;
+      let mut _5: char;
+      let mut _6: &char;
+      let mut _7: ();
+  
+      bb0: {
+          _1 = &raw const _2;
+          _3 = const 'b';
+          _5 = copy _3;
+          _6 = &_3;
+-         _4 = copy _5;
++         _3 = copy _5;
+          (*_1) = copy (*_6);
+          _6 = &_5;
+-         _7 = dump_var::<char>(copy _4) -> [return: bb1, unwind unreachable];
++         _7 = dump_var::<char>(copy _3) -> [return: bb1, unwind unreachable];
+      }
+  
+      bb1: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/copy-prop/write_to_borrowed.rs b/tests/mir-opt/copy-prop/write_to_borrowed.rs
new file mode 100644
index 00000000000..dba504fe970
--- /dev/null
+++ b/tests/mir-opt/copy-prop/write_to_borrowed.rs
@@ -0,0 +1,45 @@
+//@ test-mir-pass: CopyProp
+
+#![feature(custom_mir, core_intrinsics)]
+#![allow(internal_features)]
+
+use std::intrinsics::mir::*;
+
+#[custom_mir(dialect = "runtime")]
+fn main() {
+    mir! {
+        // Both _3 and _5 are borrowed, check that we do not unify them, and that we do not
+        // introduce a write to any of them.
+        let _1;
+        let _2;
+        let _3;
+        let _4;
+        let _5;
+        let _6;
+        let _7;
+        // CHECK: bb0: {
+        {
+            // CHECK-NEXT: _1 = &raw const _2;
+            _1 = core::ptr::addr_of!(_2);
+            // CHECK-NEXT: _3 = const 'b';
+            _3 = 'b';
+            // CHECK-NEXT: _5 = copy _3;
+            _5 = _3;
+            // CHECK-NEXT: _6 = &_3;
+            _6 = &_3;
+            // CHECK-NEXT: _3 = copy _5
+            _4 = _5;
+            // CHECK-NEXT: (*_1) = copy (*_6);
+            *_1 = *_6;
+            // CHECK-NEXT: _6 = &_5;
+            _6 = &_5;
+            // CHECK-NEXT: _7 = dump_var::<char>(copy _3)
+            Call(_7 = dump_var(_4), ReturnTo(bb1), UnwindUnreachable())
+        }
+        bb1 = { Return() }
+    }
+}
+
+fn dump_var<T>(_: T) {}
+
+// EMIT_MIR write_to_borrowed.main.CopyProp.diff