]> git.lizzy.rs Git - rust.git/commitdiff
array-to-raw-elem cast: test that Retag covers entire array
authorRalf Jung <post@ralfj.de>
Fri, 7 May 2021 07:36:45 +0000 (09:36 +0200)
committerRalf Jung <post@ralfj.de>
Fri, 7 May 2021 07:36:45 +0000 (09:36 +0200)
src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir [new file with mode: 0644]
src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir
src/test/mir-opt/retag.rs

diff --git a/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir
new file mode 100644 (file)
index 0000000..c6ef403
--- /dev/null
@@ -0,0 +1,199 @@
+// MIR for `array_casts` after SimplifyCfg-elaborate-drops
+
+fn array_casts() -> () {
+    let mut _0: ();                      // return place in scope 0 at $DIR/retag.rs:57:18: 57:18
+    let mut _1: [usize; 2];              // in scope 0 at $DIR/retag.rs:58:9: 58:14
+    let mut _3: *mut [usize; 2];         // in scope 0 at $DIR/retag.rs:59:13: 59:19
+    let mut _4: &mut [usize; 2];         // in scope 0 at $DIR/retag.rs:59:13: 59:19
+    let _5: ();                          // in scope 0 at $DIR/retag.rs:60:5: 60:30
+    let mut _6: *mut usize;              // in scope 0 at $DIR/retag.rs:60:15: 60:23
+    let mut _7: *mut usize;              // in scope 0 at $DIR/retag.rs:60:15: 60:16
+    let mut _10: *const [usize; 2];      // in scope 0 at $DIR/retag.rs:63:13: 63:15
+    let _11: &[usize; 2];                // in scope 0 at $DIR/retag.rs:63:13: 63:15
+    let _12: ();                         // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _13: (&usize, &usize);       // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _14: &usize;                 // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let _15: usize;                      // in scope 0 at $DIR/retag.rs:64:16: 64:36
+    let mut _16: *const usize;           // in scope 0 at $DIR/retag.rs:64:26: 64:34
+    let mut _17: *const usize;           // in scope 0 at $DIR/retag.rs:64:26: 64:27
+    let mut _18: &usize;                 // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let _19: usize;                      // in scope 0 at $DIR/retag.rs:64:38: 64:39
+    let mut _22: bool;                   // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _23: bool;                   // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _24: usize;                  // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _25: usize;                  // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _26: !;                      // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let _28: !;                          // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _29: core::panicking::AssertKind; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _30: &usize;                 // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let _31: &usize;                     // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _32: &usize;                 // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let _33: &usize;                     // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    let mut _34: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    scope 1 {
+        debug x => _1;                   // in scope 1 at $DIR/retag.rs:58:9: 58:14
+        let _2: *mut usize;              // in scope 1 at $DIR/retag.rs:59:9: 59:10
+        scope 2 {
+            debug p => _2;               // in scope 2 at $DIR/retag.rs:59:9: 59:10
+            let _8: [usize; 2];          // in scope 2 at $DIR/retag.rs:62:9: 62:10
+            scope 3 {
+            }
+            scope 4 {
+                debug x => _8;           // in scope 4 at $DIR/retag.rs:62:9: 62:10
+                let _9: *const usize;    // in scope 4 at $DIR/retag.rs:63:9: 63:10
+                scope 5 {
+                    debug p => _9;       // in scope 5 at $DIR/retag.rs:63:9: 63:10
+                    let _20: &usize;     // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                    let _21: &usize;     // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                    let mut _35: &usize; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                    scope 6 {
+                    }
+                    scope 7 {
+                        debug left_val => _20; // in scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                        debug right_val => _21; // in scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                        let _27: core::panicking::AssertKind; // in scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                        scope 8 {
+                            debug kind => _27; // in scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    bb0: {
+        StorageLive(_1);                 // scope 0 at $DIR/retag.rs:58:9: 58:14
+        _1 = [const 0_usize, const 0_usize]; // scope 0 at $DIR/retag.rs:58:29: 58:35
+        StorageLive(_2);                 // scope 1 at $DIR/retag.rs:59:9: 59:10
+        StorageLive(_3);                 // scope 1 at $DIR/retag.rs:59:13: 59:19
+        StorageLive(_4);                 // scope 1 at $DIR/retag.rs:59:13: 59:19
+        _4 = &mut _1;                    // scope 1 at $DIR/retag.rs:59:13: 59:19
+        Retag(_4);                       // scope 1 at $DIR/retag.rs:59:13: 59:19
+        _3 = &raw mut (*_4);             // scope 1 at $DIR/retag.rs:59:13: 59:19
+        Retag([raw] _3);                 // scope 1 at $DIR/retag.rs:59:13: 59:19
+        _2 = move _3 as *mut usize (Pointer(ArrayToPointer)); // scope 1 at $DIR/retag.rs:59:13: 59:33
+        StorageDead(_3);                 // scope 1 at $DIR/retag.rs:59:32: 59:33
+        StorageDead(_4);                 // scope 1 at $DIR/retag.rs:59:33: 59:34
+        StorageLive(_5);                 // scope 2 at $DIR/retag.rs:60:5: 60:30
+        StorageLive(_6);                 // scope 3 at $DIR/retag.rs:60:15: 60:23
+        StorageLive(_7);                 // scope 3 at $DIR/retag.rs:60:15: 60:16
+        _7 = _2;                         // scope 3 at $DIR/retag.rs:60:15: 60:16
+        _6 = ptr::mut_ptr::<impl *mut usize>::add(move _7, const 1_usize) -> bb1; // scope 3 at $DIR/retag.rs:60:15: 60:23
+                                         // mir::Constant
+                                         // + span: $DIR/retag.rs:60:17: 60:20
+                                         // + literal: Const { ty: unsafe fn(*mut usize, usize) -> *mut usize {std::ptr::mut_ptr::<impl *mut usize>::add}, val: Value(Scalar(<ZST>)) }
+    }
+
+    bb1: {
+        StorageDead(_7);                 // scope 3 at $DIR/retag.rs:60:22: 60:23
+        (*_6) = const 1_usize;           // scope 3 at $DIR/retag.rs:60:14: 60:27
+        StorageDead(_6);                 // scope 3 at $DIR/retag.rs:60:27: 60:28
+        _5 = const ();                   // scope 3 at $DIR/retag.rs:60:5: 60:30
+        StorageDead(_5);                 // scope 2 at $DIR/retag.rs:60:29: 60:30
+        StorageLive(_8);                 // scope 2 at $DIR/retag.rs:62:9: 62:10
+        _8 = [const 0_usize, const 1_usize]; // scope 2 at $DIR/retag.rs:62:25: 62:31
+        StorageLive(_9);                 // scope 4 at $DIR/retag.rs:63:9: 63:10
+        StorageLive(_10);                // scope 4 at $DIR/retag.rs:63:13: 63:15
+        StorageLive(_11);                // scope 4 at $DIR/retag.rs:63:13: 63:15
+        _11 = &_8;                       // scope 4 at $DIR/retag.rs:63:13: 63:15
+        Retag(_11);                      // scope 4 at $DIR/retag.rs:63:13: 63:15
+        _10 = &raw const (*_11);         // scope 4 at $DIR/retag.rs:63:13: 63:15
+        Retag([raw] _10);                // scope 4 at $DIR/retag.rs:63:13: 63:15
+        _9 = move _10 as *const usize (Pointer(ArrayToPointer)); // scope 4 at $DIR/retag.rs:63:13: 63:31
+        StorageDead(_10);                // scope 4 at $DIR/retag.rs:63:30: 63:31
+        StorageDead(_11);                // scope 4 at $DIR/retag.rs:63:31: 63:32
+        StorageLive(_12);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_13);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_14);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_15);                // scope 5 at $DIR/retag.rs:64:16: 64:36
+        StorageLive(_16);                // scope 6 at $DIR/retag.rs:64:26: 64:34
+        StorageLive(_17);                // scope 6 at $DIR/retag.rs:64:26: 64:27
+        _17 = _9;                        // scope 6 at $DIR/retag.rs:64:26: 64:27
+        _16 = ptr::const_ptr::<impl *const usize>::add(move _17, const 1_usize) -> bb2; // scope 6 at $DIR/retag.rs:64:26: 64:34
+                                         // mir::Constant
+                                         // + span: $DIR/retag.rs:64:28: 64:31
+                                         // + literal: Const { ty: unsafe fn(*const usize, usize) -> *const usize {std::ptr::const_ptr::<impl *const usize>::add}, val: Value(Scalar(<ZST>)) }
+    }
+
+    bb2: {
+        StorageDead(_17);                // scope 6 at $DIR/retag.rs:64:33: 64:34
+        _15 = (*_16);                    // scope 6 at $DIR/retag.rs:64:25: 64:34
+        _14 = &_15;                      // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        Retag(_14);                      // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_18);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _35 = const array_casts::promoted[0]; // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                                         // ty::Const
+                                         // + ty: &usize
+                                         // + val: Unevaluated(array_casts, [], Some(promoted[0]))
+                                         // mir::Constant
+                                         // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                                         // + literal: Const { ty: &usize, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:15 ~ retag[317d]::array_casts), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }
+        Retag(_35);                      // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _18 = &(*_35);                   // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        Retag(_18);                      // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _13 = (move _14, move _18);      // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_18);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_14);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_20);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _20 = (_13.0: &usize);           // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        Retag(_20);                      // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_21);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _21 = (_13.1: &usize);           // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        Retag(_21);                      // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_22);                // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_23);                // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_24);                // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _24 = (*_20);                    // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_25);                // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _25 = (*_21);                    // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _23 = Eq(move _24, move _25);    // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_25);                // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_24);                // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _22 = Not(move _23);             // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_23);                // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        switchInt(move _22) -> [false: bb4, otherwise: bb3]; // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+    }
+
+    bb3: {
+        StorageLive(_27);                // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _27 = core::panicking::AssertKind::Eq; // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_28);                // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_29);                // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _29 = move _27;                  // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_30);                // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_31);                // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _31 = &(*_20);                   // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        Retag(_31);                      // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _30 = &(*_31);                   // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        Retag(_30);                      // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_32);                // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_33);                // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _33 = &(*_21);                   // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        Retag(_33);                      // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _32 = &(*_33);                   // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        Retag(_32);                      // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageLive(_34);                // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _34 = Option::<Arguments>::None; // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        core::panicking::assert_failed::<usize, usize>(move _29, move _30, move _32, move _34); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                                         // mir::Constant
+                                         // + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
+                                         // + literal: Const { ty: for<'r, 's, 't0> fn(core::panicking::AssertKind, &'r usize, &'s usize, std::option::Option<std::fmt::Arguments<'t0>>) -> ! {core::panicking::assert_failed::<usize, usize>}, val: Value(Scalar(<ZST>)) }
+    }
+
+    bb4: {
+        _12 = const ();                  // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_22);                // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_21);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_20);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_16);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_15);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_13);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        StorageDead(_12);                // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+        _0 = const ();                   // scope 0 at $DIR/retag.rs:57:18: 65:2
+        StorageDead(_9);                 // scope 4 at $DIR/retag.rs:65:1: 65:2
+        StorageDead(_8);                 // scope 2 at $DIR/retag.rs:65:1: 65:2
+        StorageDead(_2);                 // scope 1 at $DIR/retag.rs:65:1: 65:2
+        StorageDead(_1);                 // scope 0 at $DIR/retag.rs:65:1: 65:2
+        return;                          // scope 0 at $DIR/retag.rs:65:2: 65:2
+    }
+}
index 894f64c77672d76bf2ef4cc192b31fd479694d58..4bab5a974881a6b4f05cd6f7490c26092bd19907 100644 (file)
@@ -21,6 +21,7 @@ fn main() -> () {
     let _23: &i32;                       // in scope 0 at $DIR/retag.rs:47:21: 47:23
     let _24: i32;                        // in scope 0 at $DIR/retag.rs:47:22: 47:23
     let mut _26: *const i32;             // in scope 0 at $DIR/retag.rs:50:14: 50:28
+    let _27: ();                         // in scope 0 at $DIR/retag.rs:52:5: 52:18
     scope 1 {
         debug x => _1;                   // in scope 1 at $DIR/retag.rs:30:9: 30:14
         let _3: &mut i32;                // in scope 1 at $DIR/retag.rs:32:13: 32:14
@@ -46,7 +47,7 @@ fn main() -> () {
             scope 7 {
                 debug _w => _15;         // in scope 7 at $DIR/retag.rs:44:9: 44:11
                 let _25: *const i32;     // in scope 7 at $DIR/retag.rs:50:9: 50:11
-                let mut _27: &i32;       // in scope 7 at $DIR/retag.rs:47:21: 47:23
+                let mut _28: &i32;       // in scope 7 at $DIR/retag.rs:47:21: 47:23
                 scope 8 {
                     debug _w => _25;     // in scope 8 at $DIR/retag.rs:50:9: 50:11
                 }
@@ -70,7 +71,7 @@ fn main() -> () {
         Retag(_7);                       // scope 1 at $DIR/retag.rs:32:29: 32:35
         _6 = &mut (*_7);                 // scope 1 at $DIR/retag.rs:32:29: 32:35
         Retag([2phase] _6);              // scope 1 at $DIR/retag.rs:32:29: 32:35
-        _3 = Test::foo(move _4, move _6) -> [return: bb1, unwind: bb7]; // scope 1 at $DIR/retag.rs:32:17: 32:36
+        _3 = Test::foo(move _4, move _6) -> [return: bb1, unwind: bb8]; // scope 1 at $DIR/retag.rs:32:17: 32:36
                                          // mir::Constant
                                          // + span: $DIR/retag.rs:32:25: 32:28
                                          // + literal: Const { ty: for<'r, 'x> fn(&'r Test, &'x mut i32) -> &'x mut i32 {Test::foo}, val: Value(Scalar(<ZST>)) }
@@ -81,7 +82,7 @@ fn main() -> () {
         StorageDead(_6);                 // scope 1 at $DIR/retag.rs:32:35: 32:36
         StorageDead(_4);                 // scope 1 at $DIR/retag.rs:32:35: 32:36
         StorageDead(_7);                 // scope 1 at $DIR/retag.rs:32:36: 32:37
-        drop(_5) -> [return: bb2, unwind: bb8]; // scope 1 at $DIR/retag.rs:32:36: 32:37
+        drop(_5) -> [return: bb2, unwind: bb9]; // scope 1 at $DIR/retag.rs:32:36: 32:37
     }
 
     bb2: {
@@ -146,19 +147,19 @@ fn main() -> () {
         Retag(_20);                      // scope 7 at $DIR/retag.rs:47:5: 47:12
         StorageLive(_22);                // scope 7 at $DIR/retag.rs:47:21: 47:23
         StorageLive(_23);                // scope 7 at $DIR/retag.rs:47:21: 47:23
-        _27 = const main::promoted[0];   // scope 7 at $DIR/retag.rs:47:21: 47:23
+        _28 = const main::promoted[0];   // scope 7 at $DIR/retag.rs:47:21: 47:23
                                          // ty::Const
                                          // + ty: &i32
                                          // + val: Unevaluated(main, [], Some(promoted[0]))
                                          // mir::Constant
                                          // + span: $DIR/retag.rs:47:21: 47:23
                                          // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:13 ~ retag[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }
-        Retag(_27);                      // scope 7 at $DIR/retag.rs:47:21: 47:23
-        _23 = &(*_27);                   // scope 7 at $DIR/retag.rs:47:21: 47:23
+        Retag(_28);                      // scope 7 at $DIR/retag.rs:47:21: 47:23
+        _23 = &(*_28);                   // scope 7 at $DIR/retag.rs:47:21: 47:23
         Retag(_23);                      // scope 7 at $DIR/retag.rs:47:21: 47:23
         _22 = &(*_23);                   // scope 7 at $DIR/retag.rs:47:21: 47:23
         Retag(_22);                      // scope 7 at $DIR/retag.rs:47:21: 47:23
-        _19 = Test::foo_shr(move _20, move _22) -> [return: bb4, unwind: bb6]; // scope 7 at $DIR/retag.rs:47:5: 47:24
+        _19 = Test::foo_shr(move _20, move _22) -> [return: bb4, unwind: bb7]; // scope 7 at $DIR/retag.rs:47:5: 47:24
                                          // mir::Constant
                                          // + span: $DIR/retag.rs:47:13: 47:20
                                          // + literal: Const { ty: for<'r, 'x> fn(&'r Test, &'x i32) -> &'x i32 {Test::foo_shr}, val: Value(Scalar(<ZST>)) }
@@ -169,7 +170,7 @@ fn main() -> () {
         StorageDead(_22);                // scope 7 at $DIR/retag.rs:47:23: 47:24
         StorageDead(_20);                // scope 7 at $DIR/retag.rs:47:23: 47:24
         StorageDead(_23);                // scope 7 at $DIR/retag.rs:47:24: 47:25
-        drop(_21) -> [return: bb5, unwind: bb8]; // scope 7 at $DIR/retag.rs:47:24: 47:25
+        drop(_21) -> [return: bb5, unwind: bb9]; // scope 7 at $DIR/retag.rs:47:24: 47:25
     }
 
     bb5: {
@@ -181,23 +182,32 @@ fn main() -> () {
         Retag([raw] _26);                // scope 7 at $DIR/retag.rs:50:14: 50:16
         _25 = _26;                       // scope 7 at $DIR/retag.rs:50:14: 50:28
         StorageDead(_26);                // scope 7 at $DIR/retag.rs:50:28: 50:29
-        _0 = const ();                   // scope 0 at $DIR/retag.rs:29:11: 51:2
-        StorageDead(_25);                // scope 7 at $DIR/retag.rs:51:1: 51:2
-        StorageDead(_15);                // scope 6 at $DIR/retag.rs:51:1: 51:2
-        StorageDead(_13);                // scope 1 at $DIR/retag.rs:51:1: 51:2
-        StorageDead(_1);                 // scope 0 at $DIR/retag.rs:51:1: 51:2
-        return;                          // scope 0 at $DIR/retag.rs:51:2: 51:2
+        StorageLive(_27);                // scope 8 at $DIR/retag.rs:52:5: 52:18
+        _27 = array_casts() -> bb6;      // scope 8 at $DIR/retag.rs:52:5: 52:18
+                                         // mir::Constant
+                                         // + span: $DIR/retag.rs:52:5: 52:16
+                                         // + literal: Const { ty: fn() {array_casts}, val: Value(Scalar(<ZST>)) }
     }
 
-    bb6 (cleanup): {
-        drop(_21) -> bb8;                // scope 7 at $DIR/retag.rs:47:24: 47:25
+    bb6: {
+        StorageDead(_27);                // scope 8 at $DIR/retag.rs:52:18: 52:19
+        _0 = const ();                   // scope 0 at $DIR/retag.rs:29:11: 53:2
+        StorageDead(_25);                // scope 7 at $DIR/retag.rs:53:1: 53:2
+        StorageDead(_15);                // scope 6 at $DIR/retag.rs:53:1: 53:2
+        StorageDead(_13);                // scope 1 at $DIR/retag.rs:53:1: 53:2
+        StorageDead(_1);                 // scope 0 at $DIR/retag.rs:53:1: 53:2
+        return;                          // scope 0 at $DIR/retag.rs:53:2: 53:2
     }
 
     bb7 (cleanup): {
-        drop(_5) -> bb8;                 // scope 1 at $DIR/retag.rs:32:36: 32:37
+        drop(_21) -> bb9;                // scope 7 at $DIR/retag.rs:47:24: 47:25
     }
 
     bb8 (cleanup): {
-        resume;                          // scope 0 at $DIR/retag.rs:29:1: 51:2
+        drop(_5) -> bb9;                 // scope 1 at $DIR/retag.rs:32:36: 32:37
+    }
+
+    bb9 (cleanup): {
+        resume;                          // scope 0 at $DIR/retag.rs:29:1: 53:2
     }
 }
index d0ea2cfb18ba204e2a451fc093999a7d81c3602c..13568b822d4f3c6f1afe163e0d291a2c518288ab 100644 (file)
@@ -48,4 +48,18 @@ fn main() {
 
     // escape-to-raw (shr)
     let _w = _w as *const _;
+
+    array_casts();
+}
+
+/// Casting directly to an array should also go through `&raw` and thus add appropriate retags.
+// EMIT_MIR retag.array_casts.SimplifyCfg-elaborate-drops.after.mir
+fn array_casts() {
+    let mut x: [usize; 2] = [0, 0];
+    let p = &mut x as *mut usize;
+    unsafe { *p.add(1) = 1; }
+
+    let x: [usize; 2] = [0, 1];
+    let p = &x as *const usize;
+    assert_eq!(unsafe { *p.add(1) }, 1);
 }