Skip to content

Commit 25ef277

Browse files
committed
Add mir-opt test.
1 parent ccef802 commit 25ef277

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
- // MIR for `debuginfo` before ReferencePropagation
2+
+ // MIR for `debuginfo` after ReferencePropagation
3+
4+
fn debuginfo() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/reference_prop.rs:+0:16: +0:16
6+
let _1: &mut u8; // in scope 0 at $DIR/reference_prop.rs:+3:9: +3:19
7+
let mut _2: u8; // in scope 0 at $DIR/reference_prop.rs:+3:27: +3:31
8+
let _4: debuginfo::T; // in scope 0 at $DIR/reference_prop.rs:+4:18: +4:22
9+
let _6: (); // in scope 0 at $DIR/reference_prop.rs:+9:5: +12:6
10+
let mut _7: std::option::Option<i32>; // in scope 0 at $DIR/reference_prop.rs:+9:11: +9:18
11+
let mut _8: isize; // in scope 0 at $DIR/reference_prop.rs:+10:9: +10:13
12+
let mut _10: &[i32]; // in scope 0 at $DIR/reference_prop.rs:+16:82: +16:94
13+
let _11: &[i32]; // in scope 0 at $DIR/reference_prop.rs:+16:83: +16:94
14+
let mut _12: &[i32; 10]; // in scope 0 at $DIR/reference_prop.rs:+16:83: +16:90
15+
let _13: [i32; 10]; // in scope 0 at $DIR/reference_prop.rs:+16:83: +16:90
16+
let mut _14: std::ops::RangeFull; // in scope 0 at $DIR/reference_prop.rs:+16:91: +16:93
17+
let mut _15: usize; // in scope 0 at $DIR/reference_prop.rs:+16:12: +16:79
18+
let mut _16: usize; // in scope 0 at $DIR/reference_prop.rs:+16:12: +16:79
19+
let mut _17: bool; // in scope 0 at $DIR/reference_prop.rs:+16:12: +16:79
20+
scope 1 {
21+
- debug ref_mut_u8 => _1; // in scope 1 at $DIR/reference_prop.rs:+3:9: +3:19
22+
+ debug ref_mut_u8 => &_2; // in scope 1 at $DIR/reference_prop.rs:+3:9: +3:19
23+
let _3: &u8; // in scope 1 at $DIR/reference_prop.rs:+4:9: +4:14
24+
let mut _23: &debuginfo::T; // in scope 1 at $DIR/reference_prop.rs:+4:17: +4:24
25+
scope 2 {
26+
- debug field => _3; // in scope 2 at $DIR/reference_prop.rs:+4:9: +4:14
27+
+ debug field => &((*_23).0: u8); // in scope 2 at $DIR/reference_prop.rs:+4:9: +4:14
28+
let _5: &u8; // in scope 2 at $DIR/reference_prop.rs:+7:9: +7:17
29+
scope 3 {
30+
- debug reborrow => _5; // in scope 3 at $DIR/reference_prop.rs:+7:9: +7:17
31+
+ debug reborrow => _1; // in scope 3 at $DIR/reference_prop.rs:+7:9: +7:17
32+
let _9: &i32; // in scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
33+
let mut _22: &std::option::Option<i32>; // in scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
34+
scope 4 {
35+
- debug variant_field => _9; // in scope 4 at $DIR/reference_prop.rs:+11:14: +11:31
36+
+ debug variant_field => &(((*_22) as Some).0: i32); // in scope 4 at $DIR/reference_prop.rs:+11:14: +11:31
37+
}
38+
scope 5 {
39+
- debug constant_index => _18; // in scope 5 at $DIR/reference_prop.rs:+16:16: +16:34
40+
+ debug constant_index => &(*_10)[1 of 3]; // in scope 5 at $DIR/reference_prop.rs:+16:16: +16:34
41+
debug subslice => _19; // in scope 5 at $DIR/reference_prop.rs:+16:36: +16:44
42+
debug constant_index_from_end => _20; // in scope 5 at $DIR/reference_prop.rs:+16:51: +16:78
43+
let _18: &i32; // in scope 5 at $DIR/reference_prop.rs:+16:16: +16:34
44+
let _19: &[i32]; // in scope 5 at $DIR/reference_prop.rs:+16:36: +16:44
45+
let _20: &i32; // in scope 5 at $DIR/reference_prop.rs:+16:51: +16:78
46+
let mut _21: &[i32; 10]; // in scope 5 at $DIR/reference_prop.rs:+16:83: +16:90
47+
}
48+
}
49+
}
50+
}
51+
52+
bb0: {
53+
StorageLive(_1); // scope 0 at $DIR/reference_prop.rs:+3:9: +3:19
54+
StorageLive(_2); // scope 0 at $DIR/reference_prop.rs:+3:27: +3:31
55+
_2 = const 5_u8; // scope 0 at $DIR/reference_prop.rs:+3:27: +3:31
56+
_1 = &mut _2; // scope 0 at $DIR/reference_prop.rs:+3:22: +3:31
57+
- StorageLive(_3); // scope 1 at $DIR/reference_prop.rs:+4:9: +4:14
58+
_23 = const _; // scope 1 at $DIR/reference_prop.rs:+4:17: +4:24
59+
// mir::Constant
60+
// + span: $DIR/reference_prop.rs:463:17: 463:24
61+
// + literal: Const { ty: &T, val: Unevaluated(debuginfo, [], Some(promoted[2])) }
62+
- _3 = &((*_23).0: u8); // scope 1 at $DIR/reference_prop.rs:+4:17: +4:24
63+
- StorageLive(_5); // scope 2 at $DIR/reference_prop.rs:+7:9: +7:17
64+
- _5 = &(*_1); // scope 2 at $DIR/reference_prop.rs:+7:20: +7:32
65+
- StorageLive(_6); // scope 3 at $DIR/reference_prop.rs:+9:5: +12:6
66+
StorageLive(_7); // scope 3 at $DIR/reference_prop.rs:+9:11: +9:18
67+
_7 = Option::<i32>::Some(const 0_i32); // scope 3 at $DIR/reference_prop.rs:+9:11: +9:18
68+
_8 = discriminant(_7); // scope 3 at $DIR/reference_prop.rs:+9:11: +9:18
69+
switchInt(move _8) -> [0: bb3, 1: bb1, otherwise: bb2]; // scope 3 at $DIR/reference_prop.rs:+9:5: +9:18
70+
}
71+
72+
bb1: {
73+
- StorageLive(_9); // scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
74+
_22 = const _; // scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
75+
// mir::Constant
76+
// + span: $DIR/reference_prop.rs:470:14: 470:31
77+
// + literal: Const { ty: &Option<i32>, val: Unevaluated(debuginfo, [], Some(promoted[1])) }
78+
- _9 = &(((*_22) as Some).0: i32); // scope 3 at $DIR/reference_prop.rs:+11:14: +11:31
79+
- _6 = const (); // scope 4 at $DIR/reference_prop.rs:+11:36: +11:38
80+
- StorageDead(_9); // scope 3 at $DIR/reference_prop.rs:+11:37: +11:38
81+
goto -> bb4; // scope 3 at $DIR/reference_prop.rs:+11:37: +11:38
82+
}
83+
84+
bb2: {
85+
unreachable; // scope 3 at $DIR/reference_prop.rs:+9:11: +9:18
86+
}
87+
88+
bb3: {
89+
- _6 = const (); // scope 3 at $DIR/reference_prop.rs:+10:17: +10:19
90+
goto -> bb4; // scope 3 at $DIR/reference_prop.rs:+10:17: +10:19
91+
}
92+
93+
bb4: {
94+
StorageDead(_7); // scope 3 at $DIR/reference_prop.rs:+12:5: +12:6
95+
- StorageDead(_6); // scope 3 at $DIR/reference_prop.rs:+12:5: +12:6
96+
StorageLive(_10); // scope 5 at $DIR/reference_prop.rs:+16:82: +16:94
97+
StorageLive(_11); // scope 5 at $DIR/reference_prop.rs:+16:83: +16:94
98+
StorageLive(_12); // scope 5 at $DIR/reference_prop.rs:+16:83: +16:90
99+
_21 = const _; // scope 5 at $DIR/reference_prop.rs:+16:83: +16:90
100+
// mir::Constant
101+
// + span: $DIR/reference_prop.rs:475:83: 475:90
102+
// + literal: Const { ty: &[i32; 10], val: Unevaluated(debuginfo, [], Some(promoted[0])) }
103+
_12 = &(*_21); // scope 5 at $DIR/reference_prop.rs:+16:83: +16:90
104+
StorageLive(_14); // scope 5 at $DIR/reference_prop.rs:+16:91: +16:93
105+
_14 = RangeFull; // scope 5 at $DIR/reference_prop.rs:+16:91: +16:93
106+
_11 = <[i32; 10] as Index<RangeFull>>::index(move _12, move _14) -> bb5; // scope 5 at $DIR/reference_prop.rs:+16:83: +16:94
107+
// mir::Constant
108+
// + span: $DIR/reference_prop.rs:475:83: 475:94
109+
// + literal: Const { ty: for<'a> fn(&'a [i32; 10], RangeFull) -> &'a <[i32; 10] as Index<RangeFull>>::Output {<[i32; 10] as Index<RangeFull>>::index}, val: Value(<ZST>) }
110+
}
111+
112+
bb5: {
113+
StorageDead(_14); // scope 5 at $DIR/reference_prop.rs:+16:93: +16:94
114+
StorageDead(_12); // scope 5 at $DIR/reference_prop.rs:+16:93: +16:94
115+
_10 = &(*_11); // scope 5 at $DIR/reference_prop.rs:+16:82: +16:94
116+
_15 = Len((*_10)); // scope 5 at $DIR/reference_prop.rs:+16:12: +16:79
117+
_16 = const 3_usize; // scope 5 at $DIR/reference_prop.rs:+16:12: +16:79
118+
_17 = Ge(move _15, move _16); // scope 5 at $DIR/reference_prop.rs:+16:12: +16:79
119+
switchInt(move _17) -> [0: bb7, otherwise: bb6]; // scope 5 at $DIR/reference_prop.rs:+16:12: +16:79
120+
}
121+
122+
bb6: {
123+
- StorageLive(_18); // scope 5 at $DIR/reference_prop.rs:+16:16: +16:34
124+
- _18 = &(*_10)[1 of 3]; // scope 5 at $DIR/reference_prop.rs:+16:16: +16:34
125+
StorageLive(_19); // scope 5 at $DIR/reference_prop.rs:+16:36: +16:44
126+
_19 = &(*_10)[2:-1]; // scope 5 at $DIR/reference_prop.rs:+16:36: +16:44
127+
StorageLive(_20); // scope 5 at $DIR/reference_prop.rs:+16:51: +16:78
128+
_20 = &(*_10)[-1 of 3]; // scope 5 at $DIR/reference_prop.rs:+16:51: +16:78
129+
_0 = const (); // scope 5 at $DIR/reference_prop.rs:+16:95: +17:6
130+
StorageDead(_20); // scope 3 at $DIR/reference_prop.rs:+17:5: +17:6
131+
StorageDead(_19); // scope 3 at $DIR/reference_prop.rs:+17:5: +17:6
132+
- StorageDead(_18); // scope 3 at $DIR/reference_prop.rs:+17:5: +17:6
133+
goto -> bb8; // scope 3 at $DIR/reference_prop.rs:+16:5: +17:6
134+
}
135+
136+
bb7: {
137+
_0 = const (); // scope 3 at $DIR/reference_prop.rs:+17:6: +17:6
138+
goto -> bb8; // scope 3 at $DIR/reference_prop.rs:+16:5: +17:6
139+
}
140+
141+
bb8: {
142+
- StorageDead(_5); // scope 2 at $DIR/reference_prop.rs:+18:1: +18:2
143+
- StorageDead(_3); // scope 1 at $DIR/reference_prop.rs:+18:1: +18:2
144+
StorageDead(_2); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2
145+
StorageDead(_1); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2
146+
StorageDead(_11); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2
147+
StorageDead(_10); // scope 0 at $DIR/reference_prop.rs:+18:1: +18:2
148+
return; // scope 0 at $DIR/reference_prop.rs:+18:2: +18:2
149+
}
150+
}
151+

tests/mir-opt/reference_prop.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,26 @@ fn unique_with_copies() {
456456
unsafe { opaque(*y) };
457457
}
458458

459+
fn debuginfo() {
460+
struct T(u8);
461+
462+
let ref_mut_u8 = &mut 5_u8;
463+
let field = &T(0).0;
464+
465+
// Verify that we don't emit `&*` in debuginfo.
466+
let reborrow = &*ref_mut_u8;
467+
468+
match Some(0) {
469+
None => {}
470+
Some(ref variant_field) => {}
471+
}
472+
473+
// `constant_index_from_end` and `subslice` should not be promoted, as their value depends
474+
// on the slice length.
475+
if let [_, ref constant_index, subslice @ .., ref constant_index_from_end] = &[6; 10][..] {
476+
}
477+
}
478+
459479
fn main() {
460480
let mut x = 5_usize;
461481
let mut y = 7_usize;
@@ -469,6 +489,7 @@ fn main() {
469489
maybe_dead(true);
470490
mut_raw_then_mut_shr();
471491
unique_with_copies();
492+
debuginfo();
472493
}
473494

474495
// EMIT_MIR reference_prop.reference_propagation.ReferencePropagation.diff
@@ -481,3 +502,4 @@ fn main() {
481502
// EMIT_MIR reference_prop.maybe_dead.ReferencePropagation.diff
482503
// EMIT_MIR reference_prop.mut_raw_then_mut_shr.ReferencePropagation.diff
483504
// EMIT_MIR reference_prop.unique_with_copies.ReferencePropagation.diff
505+
// EMIT_MIR reference_prop.debuginfo.ReferencePropagation.diff

0 commit comments

Comments
 (0)