about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJannis Christopher Köhl <mail@koehl.dev>2022-10-07 01:11:06 +0200
committerJannis Christopher Köhl <mail@koehl.dev>2022-11-07 10:35:21 +0100
commit7a52e7350e3772ea9c04610f4d5ccd2b5b72403f (patch)
treeb350590f308efd884025f6fed2541846eb541c13
parent3c0f3b04b52134b870baf2ca8cedc5067cc5cb7e (diff)
downloadrust-7a52e7350e3772ea9c04610f4d5ccd2b5b72403f.tar.gz
rust-7a52e7350e3772ea9c04610f4d5ccd2b5b72403f.zip
Add tests for Stacked Borrows behavior
-rw-r--r--src/test/mir-opt/dataflow-const-prop/ref_with_sb.main.DataflowConstProp.diff46
-rw-r--r--src/test/mir-opt/dataflow-const-prop/ref_with_sb.rs15
-rw-r--r--src/test/mir-opt/dataflow-const-prop/ref_without_sb.main.DataflowConstProp.diff45
-rw-r--r--src/test/mir-opt/dataflow-const-prop/ref_without_sb.rs14
4 files changed, 120 insertions, 0 deletions
diff --git a/src/test/mir-opt/dataflow-const-prop/ref_with_sb.main.DataflowConstProp.diff b/src/test/mir-opt/dataflow-const-prop/ref_with_sb.main.DataflowConstProp.diff
new file mode 100644
index 00000000000..6a9de6af8c5
--- /dev/null
+++ b/src/test/mir-opt/dataflow-const-prop/ref_with_sb.main.DataflowConstProp.diff
@@ -0,0 +1,46 @@
+- // MIR for `main` before DataflowConstProp
++ // MIR for `main` after DataflowConstProp
+  
+  fn main() -> () {
+      let mut _0: ();                      // return place in scope 0 at $DIR/ref_with_sb.rs:+0:11: +0:11
+      let mut _1: i32;                     // in scope 0 at $DIR/ref_with_sb.rs:+1:9: +1:14
+      let _2: ();                          // in scope 0 at $DIR/ref_with_sb.rs:+2:5: +2:15
+      let mut _3: &i32;                    // in scope 0 at $DIR/ref_with_sb.rs:+2:12: +2:14
+      let _4: &i32;                        // in scope 0 at $DIR/ref_with_sb.rs:+2:12: +2:14
+      scope 1 {
+          debug a => _1;                   // in scope 1 at $DIR/ref_with_sb.rs:+1:9: +1:14
+          let _5: i32;                     // in scope 1 at $DIR/ref_with_sb.rs:+6:9: +6:10
+          scope 2 {
+              debug b => _5;               // in scope 2 at $DIR/ref_with_sb.rs:+6:9: +6:10
+          }
+      }
+  
+      bb0: {
+          StorageLive(_1);                 // scope 0 at $DIR/ref_with_sb.rs:+1:9: +1:14
+          _1 = const 0_i32;                // scope 0 at $DIR/ref_with_sb.rs:+1:17: +1:18
+          StorageLive(_2);                 // scope 1 at $DIR/ref_with_sb.rs:+2:5: +2:15
+          StorageLive(_3);                 // scope 1 at $DIR/ref_with_sb.rs:+2:12: +2:14
+          StorageLive(_4);                 // scope 1 at $DIR/ref_with_sb.rs:+2:12: +2:14
+          _4 = &_1;                        // scope 1 at $DIR/ref_with_sb.rs:+2:12: +2:14
+          _3 = &(*_4);                     // scope 1 at $DIR/ref_with_sb.rs:+2:12: +2:14
+          _2 = escape::<i32>(move _3) -> bb1; // scope 1 at $DIR/ref_with_sb.rs:+2:5: +2:15
+                                           // mir::Constant
+                                           // + span: $DIR/ref_with_sb.rs:10:5: 10:11
+                                           // + literal: Const { ty: for<'a> fn(&'a i32) {escape::<i32>}, val: Value(<ZST>) }
+      }
+  
+      bb1: {
+          StorageDead(_3);                 // scope 1 at $DIR/ref_with_sb.rs:+2:14: +2:15
+          StorageDead(_4);                 // scope 1 at $DIR/ref_with_sb.rs:+2:15: +2:16
+          StorageDead(_2);                 // scope 1 at $DIR/ref_with_sb.rs:+2:15: +2:16
+          _1 = const 1_i32;                // scope 1 at $DIR/ref_with_sb.rs:+3:5: +3:10
+          StorageLive(_5);                 // scope 1 at $DIR/ref_with_sb.rs:+6:9: +6:10
+-         _5 = _1;                         // scope 1 at $DIR/ref_with_sb.rs:+6:13: +6:14
++         _5 = const 1_i32;                // scope 1 at $DIR/ref_with_sb.rs:+6:13: +6:14
+          _0 = const ();                   // scope 0 at $DIR/ref_with_sb.rs:+0:11: +7:2
+          StorageDead(_5);                 // scope 1 at $DIR/ref_with_sb.rs:+7:1: +7:2
+          StorageDead(_1);                 // scope 0 at $DIR/ref_with_sb.rs:+7:1: +7:2
+          return;                          // scope 0 at $DIR/ref_with_sb.rs:+7:2: +7:2
+      }
+  }
+  
diff --git a/src/test/mir-opt/dataflow-const-prop/ref_with_sb.rs b/src/test/mir-opt/dataflow-const-prop/ref_with_sb.rs
new file mode 100644
index 00000000000..05f18dab4cd
--- /dev/null
+++ b/src/test/mir-opt/dataflow-const-prop/ref_with_sb.rs
@@ -0,0 +1,15 @@
+// unit-test: DataflowConstProp
+// compile-flags: -Zunsound-mir-opts
+
+#[inline(never)]
+fn escape<T>(x: &T) {}
+
+// EMIT_MIR ref_with_sb.main.DataflowConstProp.diff
+fn main() {
+    let mut a = 0;
+    escape(&a);
+    a = 1;
+    // With `-Zunsound-mir-opt`, this should be propagated
+    // (because we assume Stacked Borrows).
+    let b = a;
+}
diff --git a/src/test/mir-opt/dataflow-const-prop/ref_without_sb.main.DataflowConstProp.diff b/src/test/mir-opt/dataflow-const-prop/ref_without_sb.main.DataflowConstProp.diff
new file mode 100644
index 00000000000..66b05cdb7c1
--- /dev/null
+++ b/src/test/mir-opt/dataflow-const-prop/ref_without_sb.main.DataflowConstProp.diff
@@ -0,0 +1,45 @@
+- // MIR for `main` before DataflowConstProp
++ // MIR for `main` after DataflowConstProp
+  
+  fn main() -> () {
+      let mut _0: ();                      // return place in scope 0 at $DIR/ref_without_sb.rs:+0:11: +0:11
+      let mut _1: i32;                     // in scope 0 at $DIR/ref_without_sb.rs:+1:9: +1:14
+      let _2: ();                          // in scope 0 at $DIR/ref_without_sb.rs:+2:5: +2:15
+      let mut _3: &i32;                    // in scope 0 at $DIR/ref_without_sb.rs:+2:12: +2:14
+      let _4: &i32;                        // in scope 0 at $DIR/ref_without_sb.rs:+2:12: +2:14
+      scope 1 {
+          debug a => _1;                   // in scope 1 at $DIR/ref_without_sb.rs:+1:9: +1:14
+          let _5: i32;                     // in scope 1 at $DIR/ref_without_sb.rs:+6:9: +6:10
+          scope 2 {
+              debug b => _5;               // in scope 2 at $DIR/ref_without_sb.rs:+6:9: +6:10
+          }
+      }
+  
+      bb0: {
+          StorageLive(_1);                 // scope 0 at $DIR/ref_without_sb.rs:+1:9: +1:14
+          _1 = const 0_i32;                // scope 0 at $DIR/ref_without_sb.rs:+1:17: +1:18
+          StorageLive(_2);                 // scope 1 at $DIR/ref_without_sb.rs:+2:5: +2:15
+          StorageLive(_3);                 // scope 1 at $DIR/ref_without_sb.rs:+2:12: +2:14
+          StorageLive(_4);                 // scope 1 at $DIR/ref_without_sb.rs:+2:12: +2:14
+          _4 = &_1;                        // scope 1 at $DIR/ref_without_sb.rs:+2:12: +2:14
+          _3 = &(*_4);                     // scope 1 at $DIR/ref_without_sb.rs:+2:12: +2:14
+          _2 = escape::<i32>(move _3) -> bb1; // scope 1 at $DIR/ref_without_sb.rs:+2:5: +2:15
+                                           // mir::Constant
+                                           // + span: $DIR/ref_without_sb.rs:9:5: 9:11
+                                           // + literal: Const { ty: for<'a> fn(&'a i32) {escape::<i32>}, val: Value(<ZST>) }
+      }
+  
+      bb1: {
+          StorageDead(_3);                 // scope 1 at $DIR/ref_without_sb.rs:+2:14: +2:15
+          StorageDead(_4);                 // scope 1 at $DIR/ref_without_sb.rs:+2:15: +2:16
+          StorageDead(_2);                 // scope 1 at $DIR/ref_without_sb.rs:+2:15: +2:16
+          _1 = const 1_i32;                // scope 1 at $DIR/ref_without_sb.rs:+3:5: +3:10
+          StorageLive(_5);                 // scope 1 at $DIR/ref_without_sb.rs:+6:9: +6:10
+          _5 = _1;                         // scope 1 at $DIR/ref_without_sb.rs:+6:13: +6:14
+          _0 = const ();                   // scope 0 at $DIR/ref_without_sb.rs:+0:11: +7:2
+          StorageDead(_5);                 // scope 1 at $DIR/ref_without_sb.rs:+7:1: +7:2
+          StorageDead(_1);                 // scope 0 at $DIR/ref_without_sb.rs:+7:1: +7:2
+          return;                          // scope 0 at $DIR/ref_without_sb.rs:+7:2: +7:2
+      }
+  }
+  
diff --git a/src/test/mir-opt/dataflow-const-prop/ref_without_sb.rs b/src/test/mir-opt/dataflow-const-prop/ref_without_sb.rs
new file mode 100644
index 00000000000..4ef027a9b4d
--- /dev/null
+++ b/src/test/mir-opt/dataflow-const-prop/ref_without_sb.rs
@@ -0,0 +1,14 @@
+// unit-test: DataflowConstProp
+
+#[inline(never)]
+fn escape<T>(x: &T) {}
+
+// EMIT_MIR ref_without_sb.main.DataflowConstProp.diff
+fn main() {
+    let mut a = 0;
+    escape(&a);
+    a = 1;
+    // Without `-Zunsound-mir-opt`, this should not be propagated
+    // (because we do not assume Stacked Borrows).
+    let b = a;
+}