Skip to content

Commit ca3f742

Browse files
committed
MIR pre-codegen test for mem::replace
1 parent 831c929 commit ca3f742

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// MIR for `manual_replace` after PreCodegen
2+
3+
fn manual_replace(_1: &mut u32, _2: u32) -> u32 {
4+
debug r => _1; // in scope 0 at $DIR/mem_replace.rs:+0:23: +0:24
5+
debug v => _2; // in scope 0 at $DIR/mem_replace.rs:+0:36: +0:37
6+
let mut _0: u32; // return place in scope 0 at $DIR/mem_replace.rs:+1:9: +1:13
7+
scope 1 {
8+
debug temp => _0; // in scope 1 at $DIR/mem_replace.rs:+1:9: +1:13
9+
}
10+
11+
bb0: {
12+
_0 = (*_1); // scope 0 at $DIR/mem_replace.rs:+1:16: +1:18
13+
(*_1) = _2; // scope 1 at $DIR/mem_replace.rs:+2:5: +2:11
14+
return; // scope 0 at $DIR/mem_replace.rs:+4:2: +4:2
15+
}
16+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// MIR for `mem_replace` after PreCodegen
2+
3+
fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
4+
debug r => _1; // in scope 0 at $DIR/mem_replace.rs:+0:20: +0:21
5+
debug v => _2; // in scope 0 at $DIR/mem_replace.rs:+0:33: +0:34
6+
let mut _0: u32; // return place in scope 0 at $DIR/mem_replace.rs:+0:44: +0:47
7+
scope 1 (inlined std::mem::replace::<u32>) { // at $DIR/mem_replace.rs:16:5: 16:28
8+
debug dest => _1; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
9+
debug src => _2; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
10+
let mut _3: *const u32; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
11+
let mut _4: *mut u32; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
12+
let mut _5: u32; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
13+
scope 2 {
14+
scope 3 {
15+
debug result => _0; // in scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
16+
scope 7 (inlined std::ptr::write::<u32>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
17+
debug dst => _4; // in scope 7 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
18+
debug src => _5; // in scope 7 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
19+
let mut _7: *const u32; // in scope 7 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
20+
let _8: &u32; // in scope 7 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
21+
let mut _9: *mut u32; // in scope 7 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
22+
scope 8 {
23+
scope 9 (inlined std::ptr::write::runtime::<u32>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
24+
debug dst => _9; // in scope 9 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
25+
}
26+
}
27+
}
28+
}
29+
scope 4 (inlined std::ptr::read::<u32>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
30+
debug src => _3; // in scope 4 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
31+
let mut _6: *const u32; // in scope 4 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
32+
scope 5 {
33+
scope 6 (inlined std::ptr::read::runtime::<u32>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
34+
debug src => _6; // in scope 6 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
35+
}
36+
}
37+
}
38+
}
39+
}
40+
41+
bb0: {
42+
StorageLive(_3); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
43+
_3 = &raw const (*_1); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
44+
StorageLive(_6); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
45+
_0 = (*_3); // scope 5 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
46+
StorageDead(_6); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
47+
StorageDead(_3); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
48+
StorageLive(_4); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
49+
_4 = &raw mut (*_1); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
50+
StorageLive(_5); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
51+
_5 = _2; // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
52+
StorageLive(_9); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
53+
StorageLive(_7); // scope 8 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
54+
StorageLive(_8); // scope 8 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
55+
_8 = &_5; // scope 8 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
56+
_7 = &raw const (*_8); // scope 8 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
57+
copy_nonoverlapping(dst = _4, src = move _7, count = const 1_usize); // scope 8 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
58+
StorageDead(_7); // scope 8 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
59+
StorageDead(_8); // scope 8 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
60+
StorageDead(_9); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
61+
StorageDead(_5); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
62+
StorageDead(_4); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
63+
return; // scope 0 at $DIR/mem_replace.rs:+2:2: +2:2
64+
}
65+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
2+
// only-64bit
3+
// ignore-debug
4+
5+
#![crate_type = "lib"]
6+
7+
// EMIT_MIR mem_replace.manual_replace.PreCodegen.after.mir
8+
pub fn manual_replace(r: &mut u32, v: u32) -> u32 {
9+
let temp = *r;
10+
*r = v;
11+
temp
12+
}
13+
14+
// EMIT_MIR mem_replace.mem_replace.PreCodegen.after.mir
15+
pub fn mem_replace(r: &mut u32, v: u32) -> u32 {
16+
std::mem::replace(r, v)
17+
}

0 commit comments

Comments
 (0)