Skip to content

Commit 06bcdeb

Browse files
committed
Added a GVN storage test for borrowed value
1 parent a0e538d commit 06bcdeb

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- // MIR for `f_borrowed` before GVN
2+
+ // MIR for `f_borrowed` after GVN
3+
4+
fn f_borrowed(_1: u32) -> () {
5+
let mut _0: ();
6+
let mut _2: S;
7+
let mut _3: S;
8+
let mut _4: &S;
9+
let mut _5: S;
10+
11+
bb0: {
12+
- StorageLive(_2);
13+
+ nop;
14+
_2 = S(copy _1, const 2_u32);
15+
- _3 = S(copy _1, const 2_u32);
16+
+ _3 = copy _2;
17+
_4 = &_3;
18+
- StorageDead(_2);
19+
- _5 = copy (*_4);
20+
+ nop;
21+
+ _5 = copy _2;
22+
return;
23+
}
24+
}
25+

tests/mir-opt/gvn_storage_issue_141649.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Check that we do not remove storage statements when possible.
22
//@ test-mir-pass: GVN
33
// EMIT_MIR gvn_storage_issue_141649.f.GVN.diff
4+
// EMIT_MIR gvn_storage_issue_141649.f_borrowed.GVN.diff
45

56
#![feature(custom_mir, core_intrinsics)]
67

@@ -30,3 +31,29 @@ pub fn f(_1: u32) {
3031
}
3132
}
3233
}
34+
35+
#[custom_mir(dialect = "runtime")]
36+
pub fn f_borrowed(_1: u32) {
37+
// CHECK-LABEL: fn f_borrowed(
38+
mir! {
39+
let _2: S;
40+
let _3: S;
41+
let _4: &S;
42+
let _5: S;
43+
{
44+
// CHECK-NOT: StorageLive(_2);
45+
// CHECK: _3 = copy _2;
46+
// CHECK-NOT: StorageDead(_2);
47+
// CHECK: _5 = copy _2;
48+
StorageLive(_2);
49+
_2 = S(_1, 2);
50+
_3 = S(_1, 2);
51+
_4 = &_3;
52+
StorageDead(_2);
53+
// Because `*_4` will be replaced with `_2`,
54+
// we have to remove the storage statements of `_2`.
55+
_5 = *_4;
56+
Return()
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)