Skip to content

Commit 2bafe96

Browse files
committed
Auto merge of #85023 - RalfJung:array-to-raw-elem, r=Mark-Simulacrum
array-to-raw-elem cast: test that Retag covers entire array Make sure that we `Retag` *before* doing the `ArrayToPointer` cast.
2 parents 506e75c + 2d2ed21 commit 2bafe96

File tree

3 files changed

+241
-18
lines changed

3 files changed

+241
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
// MIR for `array_casts` after SimplifyCfg-elaborate-drops
2+
3+
fn array_casts() -> () {
4+
let mut _0: (); // return place in scope 0 at $DIR/retag.rs:57:18: 57:18
5+
let mut _1: [usize; 2]; // in scope 0 at $DIR/retag.rs:58:9: 58:14
6+
let mut _3: *mut [usize; 2]; // in scope 0 at $DIR/retag.rs:59:13: 59:19
7+
let mut _4: &mut [usize; 2]; // in scope 0 at $DIR/retag.rs:59:13: 59:19
8+
let _5: (); // in scope 0 at $DIR/retag.rs:60:5: 60:30
9+
let mut _6: *mut usize; // in scope 0 at $DIR/retag.rs:60:15: 60:23
10+
let mut _7: *mut usize; // in scope 0 at $DIR/retag.rs:60:15: 60:16
11+
let mut _10: *const [usize; 2]; // in scope 0 at $DIR/retag.rs:63:13: 63:15
12+
let _11: &[usize; 2]; // in scope 0 at $DIR/retag.rs:63:13: 63:15
13+
let _12: (); // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
14+
let mut _13: (&usize, &usize); // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
15+
let mut _14: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
16+
let _15: usize; // in scope 0 at $DIR/retag.rs:64:16: 64:36
17+
let mut _16: *const usize; // in scope 0 at $DIR/retag.rs:64:26: 64:34
18+
let mut _17: *const usize; // in scope 0 at $DIR/retag.rs:64:26: 64:27
19+
let mut _18: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
20+
let _19: usize; // in scope 0 at $DIR/retag.rs:64:38: 64:39
21+
let mut _22: bool; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
22+
let mut _23: bool; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
23+
let mut _24: usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
24+
let mut _25: usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
25+
let mut _26: !; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
26+
let _28: !; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
27+
let mut _29: core::panicking::AssertKind; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
28+
let mut _30: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
29+
let _31: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
30+
let mut _32: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
31+
let _33: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
32+
let mut _34: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
33+
scope 1 {
34+
debug x => _1; // in scope 1 at $DIR/retag.rs:58:9: 58:14
35+
let _2: *mut usize; // in scope 1 at $DIR/retag.rs:59:9: 59:10
36+
scope 2 {
37+
debug p => _2; // in scope 2 at $DIR/retag.rs:59:9: 59:10
38+
let _8: [usize; 2]; // in scope 2 at $DIR/retag.rs:62:9: 62:10
39+
scope 3 {
40+
}
41+
scope 4 {
42+
debug x => _8; // in scope 4 at $DIR/retag.rs:62:9: 62:10
43+
let _9: *const usize; // in scope 4 at $DIR/retag.rs:63:9: 63:10
44+
scope 5 {
45+
debug p => _9; // in scope 5 at $DIR/retag.rs:63:9: 63:10
46+
let _20: &usize; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
47+
let _21: &usize; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
48+
let mut _35: &usize; // in scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
49+
scope 6 {
50+
}
51+
scope 7 {
52+
debug left_val => _20; // in scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
53+
debug right_val => _21; // in scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
54+
let _27: core::panicking::AssertKind; // in scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
55+
scope 8 {
56+
debug kind => _27; // in scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}
63+
64+
bb0: {
65+
StorageLive(_1); // scope 0 at $DIR/retag.rs:58:9: 58:14
66+
_1 = [const 0_usize, const 0_usize]; // scope 0 at $DIR/retag.rs:58:29: 58:35
67+
StorageLive(_2); // scope 1 at $DIR/retag.rs:59:9: 59:10
68+
StorageLive(_3); // scope 1 at $DIR/retag.rs:59:13: 59:19
69+
StorageLive(_4); // scope 1 at $DIR/retag.rs:59:13: 59:19
70+
_4 = &mut _1; // scope 1 at $DIR/retag.rs:59:13: 59:19
71+
Retag(_4); // scope 1 at $DIR/retag.rs:59:13: 59:19
72+
_3 = &raw mut (*_4); // scope 1 at $DIR/retag.rs:59:13: 59:19
73+
Retag([raw] _3); // scope 1 at $DIR/retag.rs:59:13: 59:19
74+
_2 = move _3 as *mut usize (Pointer(ArrayToPointer)); // scope 1 at $DIR/retag.rs:59:13: 59:33
75+
StorageDead(_3); // scope 1 at $DIR/retag.rs:59:32: 59:33
76+
StorageDead(_4); // scope 1 at $DIR/retag.rs:59:33: 59:34
77+
StorageLive(_5); // scope 2 at $DIR/retag.rs:60:5: 60:30
78+
StorageLive(_6); // scope 3 at $DIR/retag.rs:60:15: 60:23
79+
StorageLive(_7); // scope 3 at $DIR/retag.rs:60:15: 60:16
80+
_7 = _2; // scope 3 at $DIR/retag.rs:60:15: 60:16
81+
_6 = ptr::mut_ptr::<impl *mut usize>::add(move _7, const 1_usize) -> bb1; // scope 3 at $DIR/retag.rs:60:15: 60:23
82+
// mir::Constant
83+
// + span: $DIR/retag.rs:60:17: 60:20
84+
// + literal: Const { ty: unsafe fn(*mut usize, usize) -> *mut usize {std::ptr::mut_ptr::<impl *mut usize>::add}, val: Value(Scalar(<ZST>)) }
85+
}
86+
87+
bb1: {
88+
StorageDead(_7); // scope 3 at $DIR/retag.rs:60:22: 60:23
89+
(*_6) = const 1_usize; // scope 3 at $DIR/retag.rs:60:14: 60:27
90+
StorageDead(_6); // scope 3 at $DIR/retag.rs:60:27: 60:28
91+
_5 = const (); // scope 3 at $DIR/retag.rs:60:5: 60:30
92+
StorageDead(_5); // scope 2 at $DIR/retag.rs:60:29: 60:30
93+
StorageLive(_8); // scope 2 at $DIR/retag.rs:62:9: 62:10
94+
_8 = [const 0_usize, const 1_usize]; // scope 2 at $DIR/retag.rs:62:25: 62:31
95+
StorageLive(_9); // scope 4 at $DIR/retag.rs:63:9: 63:10
96+
StorageLive(_10); // scope 4 at $DIR/retag.rs:63:13: 63:15
97+
StorageLive(_11); // scope 4 at $DIR/retag.rs:63:13: 63:15
98+
_11 = &_8; // scope 4 at $DIR/retag.rs:63:13: 63:15
99+
Retag(_11); // scope 4 at $DIR/retag.rs:63:13: 63:15
100+
_10 = &raw const (*_11); // scope 4 at $DIR/retag.rs:63:13: 63:15
101+
Retag([raw] _10); // scope 4 at $DIR/retag.rs:63:13: 63:15
102+
_9 = move _10 as *const usize (Pointer(ArrayToPointer)); // scope 4 at $DIR/retag.rs:63:13: 63:31
103+
StorageDead(_10); // scope 4 at $DIR/retag.rs:63:30: 63:31
104+
StorageDead(_11); // scope 4 at $DIR/retag.rs:63:31: 63:32
105+
StorageLive(_12); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
106+
StorageLive(_13); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
107+
StorageLive(_14); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
108+
StorageLive(_15); // scope 5 at $DIR/retag.rs:64:16: 64:36
109+
StorageLive(_16); // scope 6 at $DIR/retag.rs:64:26: 64:34
110+
StorageLive(_17); // scope 6 at $DIR/retag.rs:64:26: 64:27
111+
_17 = _9; // scope 6 at $DIR/retag.rs:64:26: 64:27
112+
_16 = ptr::const_ptr::<impl *const usize>::add(move _17, const 1_usize) -> bb2; // scope 6 at $DIR/retag.rs:64:26: 64:34
113+
// mir::Constant
114+
// + span: $DIR/retag.rs:64:28: 64:31
115+
// + literal: Const { ty: unsafe fn(*const usize, usize) -> *const usize {std::ptr::const_ptr::<impl *const usize>::add}, val: Value(Scalar(<ZST>)) }
116+
}
117+
118+
bb2: {
119+
StorageDead(_17); // scope 6 at $DIR/retag.rs:64:33: 64:34
120+
_15 = (*_16); // scope 6 at $DIR/retag.rs:64:25: 64:34
121+
_14 = &_15; // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
122+
Retag(_14); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
123+
StorageLive(_18); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
124+
_35 = const array_casts::promoted[0]; // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
125+
// ty::Const
126+
// + ty: &usize
127+
// + val: Unevaluated(array_casts, [], Some(promoted[0]))
128+
// mir::Constant
129+
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
130+
// + 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]) }) }
131+
Retag(_35); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
132+
_18 = &(*_35); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
133+
Retag(_18); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
134+
_13 = (move _14, move _18); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
135+
StorageDead(_18); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
136+
StorageDead(_14); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
137+
StorageLive(_20); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
138+
_20 = (_13.0: &usize); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
139+
Retag(_20); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
140+
StorageLive(_21); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
141+
_21 = (_13.1: &usize); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
142+
Retag(_21); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
143+
StorageLive(_22); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
144+
StorageLive(_23); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
145+
StorageLive(_24); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
146+
_24 = (*_20); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
147+
StorageLive(_25); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
148+
_25 = (*_21); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
149+
_23 = Eq(move _24, move _25); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
150+
StorageDead(_25); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
151+
StorageDead(_24); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
152+
_22 = Not(move _23); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
153+
StorageDead(_23); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
154+
switchInt(move _22) -> [false: bb4, otherwise: bb3]; // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
155+
}
156+
157+
bb3: {
158+
StorageLive(_27); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
159+
_27 = core::panicking::AssertKind::Eq; // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
160+
StorageLive(_28); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
161+
StorageLive(_29); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
162+
_29 = move _27; // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
163+
StorageLive(_30); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
164+
StorageLive(_31); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
165+
_31 = &(*_20); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
166+
Retag(_31); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
167+
_30 = &(*_31); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
168+
Retag(_30); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
169+
StorageLive(_32); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
170+
StorageLive(_33); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
171+
_33 = &(*_21); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
172+
Retag(_33); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
173+
_32 = &(*_33); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
174+
Retag(_32); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
175+
StorageLive(_34); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
176+
_34 = Option::<Arguments>::None; // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
177+
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
178+
// mir::Constant
179+
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
180+
// + 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>)) }
181+
}
182+
183+
bb4: {
184+
_12 = const (); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
185+
StorageDead(_22); // scope 7 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
186+
StorageDead(_21); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
187+
StorageDead(_20); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
188+
StorageDead(_16); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
189+
StorageDead(_15); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
190+
StorageDead(_13); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
191+
StorageDead(_12); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
192+
_0 = const (); // scope 0 at $DIR/retag.rs:57:18: 65:2
193+
StorageDead(_9); // scope 4 at $DIR/retag.rs:65:1: 65:2
194+
StorageDead(_8); // scope 2 at $DIR/retag.rs:65:1: 65:2
195+
StorageDead(_2); // scope 1 at $DIR/retag.rs:65:1: 65:2
196+
StorageDead(_1); // scope 0 at $DIR/retag.rs:65:1: 65:2
197+
return; // scope 0 at $DIR/retag.rs:65:2: 65:2
198+
}
199+
}

0 commit comments

Comments
 (0)