From b7a925a7ce37c5163ce81abec0fdf8d848d34ae5 Mon Sep 17 00:00:00 2001
From: Camille GILLOT <gillot.camille@gmail.com>
Date: Thu, 7 Sep 2023 15:59:05 +0000
Subject: [PATCH] Add test where slice is a const.

---
 ...n.DataflowConstProp.32bit.panic-abort.diff | 37 +++++++++++++++++--
 ....DataflowConstProp.32bit.panic-unwind.diff | 37 +++++++++++++++++--
 ...n.DataflowConstProp.64bit.panic-abort.diff | 37 +++++++++++++++++--
 ....DataflowConstProp.64bit.panic-unwind.diff | 37 +++++++++++++++++--
 .../mir-opt/dataflow-const-prop/slice_len.rs  |  5 ++-
 5 files changed, 136 insertions(+), 17 deletions(-)

diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff
index 580ac8ea4c0..be55d259dcf 100644
--- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff
+++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-abort.diff
@@ -11,15 +11,26 @@
       let _6: usize;
       let mut _7: usize;
       let mut _8: bool;
-      let mut _9: &[u32; 3];
+      let mut _10: &[u32];
+      let _11: usize;
+      let mut _12: usize;
+      let mut _13: bool;
+      let mut _14: &[u32; 3];
+      scope 1 {
+          debug local => _1;
+          let _9: u32;
+          scope 2 {
+              debug constant => _9;
+          }
+      }
   
       bb0: {
           StorageLive(_1);
           StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
-          _9 = const _;
-          _4 = _9;
+          _14 = const _;
+          _4 = _14;
           _3 = _4;
           _2 = move _3 as &[u32] (PointerCoercion(Unsize));
           StorageDead(_3);
@@ -39,8 +50,26 @@
           StorageDead(_6);
           StorageDead(_4);
           StorageDead(_2);
-          StorageDead(_1);
+          StorageLive(_9);
+          StorageLive(_10);
+          _10 = const _;
+          StorageLive(_11);
+          _11 = const 1_usize;
+          _12 = Len((*_10));
+-         _13 = Lt(_11, _12);
+-         assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable];
++         _13 = Lt(const 1_usize, _12);
++         assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind unreachable];
+      }
+  
+      bb2: {
+-         _9 = (*_10)[_11];
++         _9 = (*_10)[1 of 2];
+          StorageDead(_11);
+          StorageDead(_10);
           _0 = const ();
+          StorageDead(_9);
+          StorageDead(_1);
           return;
       }
   }
diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff
index 4792db7ac0c..f9a6c509ac8 100644
--- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff
+++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.32bit.panic-unwind.diff
@@ -11,15 +11,26 @@
       let _6: usize;
       let mut _7: usize;
       let mut _8: bool;
-      let mut _9: &[u32; 3];
+      let mut _10: &[u32];
+      let _11: usize;
+      let mut _12: usize;
+      let mut _13: bool;
+      let mut _14: &[u32; 3];
+      scope 1 {
+          debug local => _1;
+          let _9: u32;
+          scope 2 {
+              debug constant => _9;
+          }
+      }
   
       bb0: {
           StorageLive(_1);
           StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
-          _9 = const _;
-          _4 = _9;
+          _14 = const _;
+          _4 = _14;
           _3 = _4;
           _2 = move _3 as &[u32] (PointerCoercion(Unsize));
           StorageDead(_3);
@@ -39,8 +50,26 @@
           StorageDead(_6);
           StorageDead(_4);
           StorageDead(_2);
-          StorageDead(_1);
+          StorageLive(_9);
+          StorageLive(_10);
+          _10 = const _;
+          StorageLive(_11);
+          _11 = const 1_usize;
+          _12 = Len((*_10));
+-         _13 = Lt(_11, _12);
+-         assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue];
++         _13 = Lt(const 1_usize, _12);
++         assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind continue];
+      }
+  
+      bb2: {
+-         _9 = (*_10)[_11];
++         _9 = (*_10)[1 of 2];
+          StorageDead(_11);
+          StorageDead(_10);
           _0 = const ();
+          StorageDead(_9);
+          StorageDead(_1);
           return;
       }
   }
diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff
index 580ac8ea4c0..be55d259dcf 100644
--- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff
+++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-abort.diff
@@ -11,15 +11,26 @@
       let _6: usize;
       let mut _7: usize;
       let mut _8: bool;
-      let mut _9: &[u32; 3];
+      let mut _10: &[u32];
+      let _11: usize;
+      let mut _12: usize;
+      let mut _13: bool;
+      let mut _14: &[u32; 3];
+      scope 1 {
+          debug local => _1;
+          let _9: u32;
+          scope 2 {
+              debug constant => _9;
+          }
+      }
   
       bb0: {
           StorageLive(_1);
           StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
-          _9 = const _;
-          _4 = _9;
+          _14 = const _;
+          _4 = _14;
           _3 = _4;
           _2 = move _3 as &[u32] (PointerCoercion(Unsize));
           StorageDead(_3);
@@ -39,8 +50,26 @@
           StorageDead(_6);
           StorageDead(_4);
           StorageDead(_2);
-          StorageDead(_1);
+          StorageLive(_9);
+          StorageLive(_10);
+          _10 = const _;
+          StorageLive(_11);
+          _11 = const 1_usize;
+          _12 = Len((*_10));
+-         _13 = Lt(_11, _12);
+-         assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind unreachable];
++         _13 = Lt(const 1_usize, _12);
++         assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind unreachable];
+      }
+  
+      bb2: {
+-         _9 = (*_10)[_11];
++         _9 = (*_10)[1 of 2];
+          StorageDead(_11);
+          StorageDead(_10);
           _0 = const ();
+          StorageDead(_9);
+          StorageDead(_1);
           return;
       }
   }
diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff
index 4792db7ac0c..f9a6c509ac8 100644
--- a/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff
+++ b/tests/mir-opt/dataflow-const-prop/slice_len.main.DataflowConstProp.64bit.panic-unwind.diff
@@ -11,15 +11,26 @@
       let _6: usize;
       let mut _7: usize;
       let mut _8: bool;
-      let mut _9: &[u32; 3];
+      let mut _10: &[u32];
+      let _11: usize;
+      let mut _12: usize;
+      let mut _13: bool;
+      let mut _14: &[u32; 3];
+      scope 1 {
+          debug local => _1;
+          let _9: u32;
+          scope 2 {
+              debug constant => _9;
+          }
+      }
   
       bb0: {
           StorageLive(_1);
           StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
-          _9 = const _;
-          _4 = _9;
+          _14 = const _;
+          _4 = _14;
           _3 = _4;
           _2 = move _3 as &[u32] (PointerCoercion(Unsize));
           StorageDead(_3);
@@ -39,8 +50,26 @@
           StorageDead(_6);
           StorageDead(_4);
           StorageDead(_2);
-          StorageDead(_1);
+          StorageLive(_9);
+          StorageLive(_10);
+          _10 = const _;
+          StorageLive(_11);
+          _11 = const 1_usize;
+          _12 = Len((*_10));
+-         _13 = Lt(_11, _12);
+-         assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, _11) -> [success: bb2, unwind continue];
++         _13 = Lt(const 1_usize, _12);
++         assert(move _13, "index out of bounds: the length is {} but the index is {}", move _12, const 1_usize) -> [success: bb2, unwind continue];
+      }
+  
+      bb2: {
+-         _9 = (*_10)[_11];
++         _9 = (*_10)[1 of 2];
+          StorageDead(_11);
+          StorageDead(_10);
           _0 = const ();
+          StorageDead(_9);
+          StorageDead(_1);
           return;
       }
   }
diff --git a/tests/mir-opt/dataflow-const-prop/slice_len.rs b/tests/mir-opt/dataflow-const-prop/slice_len.rs
index 7937e5de7e3..41367e48497 100644
--- a/tests/mir-opt/dataflow-const-prop/slice_len.rs
+++ b/tests/mir-opt/dataflow-const-prop/slice_len.rs
@@ -5,5 +5,8 @@
 
 // EMIT_MIR slice_len.main.DataflowConstProp.diff
 fn main() {
-    (&[1u32, 2, 3] as &[u32])[1];
+    let local = (&[1u32, 2, 3] as &[u32])[1];
+
+    const SLICE: &[u32] = &[1, 2, 3];
+    let constant = SLICE[1];
 }