Skip to content

Commit 2cba138

Browse files
Add simple NRVO test
1 parent 966df3e commit 2cba138

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/test/mir-opt/nrvo-simple.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// EMIT_MIR rustc.nrvo.RenameReturnPlace.diff
2+
fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
3+
let mut buf = [0; 1024];
4+
init(&mut buf);
5+
buf
6+
}
7+
8+
fn main() {
9+
let _ = nrvo(|buf| { buf[4] = 4; });
10+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
- // MIR for `nrvo` before RenameReturnPlace
2+
+ // MIR for `nrvo` after RenameReturnPlace
3+
4+
fn nrvo(_1: for<'r> fn(&'r mut [u8; 1024])) -> [u8; 1024] {
5+
debug init => _1; // in scope 0 at $DIR/nrvo-simple.rs:2:9: 2:13
6+
- let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/nrvo-simple.rs:2:39: 2:49
7+
+ let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/nrvo-simple.rs:3:9: 3:16
8+
let mut _2: [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:3:9: 3:16
9+
let _3: (); // in scope 0 at $DIR/nrvo-simple.rs:4:5: 4:19
10+
let mut _4: for<'r> fn(&'r mut [u8; 1024]); // in scope 0 at $DIR/nrvo-simple.rs:4:5: 4:9
11+
let mut _5: &mut [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:4:10: 4:18
12+
let mut _6: &mut [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:4:10: 4:18
13+
scope 1 {
14+
- debug buf => _2; // in scope 1 at $DIR/nrvo-simple.rs:3:9: 3:16
15+
+ debug buf => _0; // in scope 1 at $DIR/nrvo-simple.rs:3:9: 3:16
16+
}
17+
18+
bb0: {
19+
- StorageLive(_2); // scope 0 at $DIR/nrvo-simple.rs:3:9: 3:16
20+
- _2 = [const 0u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:3:19: 3:28
21+
+ _0 = [const 0u8; 1024]; // scope 0 at $DIR/nrvo-simple.rs:3:19: 3:28
22+
// ty::Const
23+
// + ty: u8
24+
// + val: Value(Scalar(0x00))
25+
// mir::Constant
26+
// + span: $DIR/nrvo-simple.rs:3:20: 3:21
27+
// + literal: Const { ty: u8, val: Value(Scalar(0x00)) }
28+
StorageLive(_3); // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19
29+
- _6 = &mut _2; // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18
30+
+ _6 = &mut _0; // scope 1 at $DIR/nrvo-simple.rs:4:10: 4:18
31+
_3 = move _1(move _6) -> bb1; // scope 1 at $DIR/nrvo-simple.rs:4:5: 4:19
32+
}
33+
34+
bb1: {
35+
StorageDead(_3); // scope 1 at $DIR/nrvo-simple.rs:4:19: 4:20
36+
- _0 = _2; // scope 1 at $DIR/nrvo-simple.rs:5:5: 5:8
37+
- StorageDead(_2); // scope 0 at $DIR/nrvo-simple.rs:6:1: 6:2
38+
return; // scope 0 at $DIR/nrvo-simple.rs:6:2: 6:2
39+
}
40+
}
41+

0 commit comments

Comments
 (0)