Skip to content

Commit ab1da60

Browse files
committed
Added FileCheck to copy prop storage tests
1 parent ee9bf23 commit ab1da60

14 files changed

+213
-547
lines changed

tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
//@ test-mir-pass: CopyProp
32
//@ compile-flags: -Zlint-mir=false
43

@@ -9,10 +8,15 @@ use std::intrinsics::mir::*;
98

109
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
1110
pub fn f(_1: &mut usize) {
11+
// CHECK-LABEL: fn f(
1212
mir! {
1313
let _2: usize;
1414
let _3: usize;
15+
// CHECK: bb0: {
1516
{
17+
// CHECK: StorageLive(_2);
18+
// CHECK: (*_1) = copy _2;
19+
// CHECK: StorageDead(_2);
1620
StorageLive(_2);
1721
_2 = 0;
1822
_3 = _2;

tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.rs renamed to tests/mir-opt/copy-prop/copy_prop_storage_removed_when_local_borrowed.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
// skip-filecheck
1+
//! Check that we remove the storage statements if one of the locals is borrowed,
2+
//! and the head isn't borrowed.
23
//@ test-mir-pass: CopyProp
34

45
#![feature(custom_mir, core_intrinsics, freeze)]
56

6-
// Check that we remove the storage statements if one of the locals is borrowed,
7-
// and the head isn't borrowed.
8-
97
use std::intrinsics::mir::*;
108
use std::marker::Freeze;
119

12-
// EMIT_MIR copy_prop_borrowed_storage_not_removed.f.CopyProp.diff
10+
// EMIT_MIR copy_prop_storage_removed_when_local_borrowed.f.CopyProp.diff
1311

1412
#[custom_mir(dialect = "runtime")]
1513
pub fn f<T: Copy + Freeze>(_1: (T, T)) -> T {
14+
// CHECK-LABEL: fn f(
1615
mir! {
1716
let _2: T;
1817
let _3: T;
1918
let _4: &T;
19+
// CHECK: bb0: {
2020
{
21+
// CHECK-NOT: StorageLive(_2);
22+
// CHECK: _4 = &_2;
23+
// CHECK-NOT: StorageDead(_2);
2124
StorageLive(_2);
2225
_2 = _1.0;
2326
_3 = _2;

tests/mir-opt/copy-prop/copy_prop_storage_twice.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
//@ test-mir-pass: CopyProp
32
//@ compile-flags: -Zlint-mir=false
43

@@ -10,45 +9,55 @@
109
use std::intrinsics::mir::*;
1110

1211
// EMIT_MIR copy_prop_storage_twice.dead_twice.CopyProp.diff
13-
// EMIT_MIR copy_prop_storage_twice.live_twice.CopyProp.diff
14-
1512
#[custom_mir(dialect = "runtime")]
1613
pub fn dead_twice<T: Copy>(_1: T) -> T {
14+
// CHECK-LABEL: fn dead_twice(
1715
mir! {
1816
let _2: T;
1917
let _3: T;
2018
{
19+
// CHECK-NOT: StorageLive(_2);
2120
StorageLive(_2);
2221
Call(_2 = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable())
2322
}
2423
bb1 = {
24+
// CHECK-NOT: StorageDead(_2);
25+
// CHECK-NOT: StorageLive(_2);
26+
// CHECK: _0 = opaque::<T>(move _2) -> [return: bb2, unwind unreachable];
2527
let _3 = Move(_2);
2628
StorageDead(_2);
2729
StorageLive(_2);
2830
Call(RET = opaque(Move(_3)), ReturnTo(bb2), UnwindUnreachable())
2931
}
3032
bb2 = {
33+
// CHECK-NOT: StorageDead(_2);
3134
StorageDead(_2);
3235
Return()
3336
}
3437
}
3538
}
3639

40+
// EMIT_MIR copy_prop_storage_twice.live_twice.CopyProp.diff
3741
#[custom_mir(dialect = "runtime")]
3842
pub fn live_twice<T: Copy>(_1: T) -> T {
43+
// CHECK-LABEL: fn live_twice(
3944
mir! {
4045
let _2: T;
4146
let _3: T;
4247
{
48+
// CHECK-NOT: StorageLive(_2);
4349
StorageLive(_2);
4450
Call(_2 = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable())
4551
}
4652
bb1 = {
53+
// CHECK-NOT: StorageLive(_2);
54+
// CHECK: _0 = opaque::<T>(copy _2) -> [return: bb2, unwind unreachable];
4755
let _3 = Move(_2);
4856
StorageLive(_2);
4957
Call(RET = opaque(_3), ReturnTo(bb2), UnwindUnreachable())
5058
}
5159
bb2 = {
60+
// CHECK-NOT: StorageDead(_2);
5261
StorageDead(_2);
5362
Return()
5463
}

tests/mir-opt/copy-prop/copy_prop_storage_unreachable.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
// skip-filecheck
1+
//! Check that we do not remove the storage statements if the head
2+
//! is uninitialized in an unreachable block.
23
//@ test-mir-pass: CopyProp
34

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

6-
// Check that we do not remove the storage statements if the head
7-
// is uninitialized in an unreachable block.
8-
97
use std::intrinsics::mir::*;
108

119
// EMIT_MIR copy_prop_storage_unreachable.f.CopyProp.diff
1210

1311
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
1412
pub fn f(_1: &mut usize) {
13+
// CHECK-LABEL: fn f(
1514
mir! {
1615
let _2: usize;
1716
let _3: usize;
1817
{
18+
// CHECK: StorageLive(_2);
19+
// CHECK: (*_1) = copy _2;
20+
// CHECK: StorageDead(_2);
1921
StorageLive(_2);
2022
_2 = 42;
2123
_3 = _2;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
- // MIR for `f_head_borrowed` before CopyProp
2+
+ // MIR for `f_head_borrowed` after CopyProp
3+
4+
fn f_head_borrowed() -> () {
5+
let mut _0: ();
6+
let mut _1: S;
7+
let mut _2: S;
8+
let mut _3: S;
9+
let mut _4: &S;
10+
let mut _5: &S;
11+
12+
bb0: {
13+
StorageLive(_1);
14+
_1 = S(const 1_u32, const 2_u32);
15+
- StorageLive(_2);
16+
_4 = &_1;
17+
- _2 = copy _1;
18+
- _3 = opaque::<S>(move _1) -> [return: bb1, unwind unreachable];
19+
+ _3 = opaque::<S>(copy _1) -> [return: bb1, unwind unreachable];
20+
}
21+
22+
bb1: {
23+
- StorageDead(_2);
24+
StorageDead(_1);
25+
_5 = opaque::<&S>(move _4) -> [return: bb2, unwind unreachable];
26+
}
27+
28+
bb2: {
29+
return;
30+
}
31+
}
32+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- // MIR for `f_move` before CopyProp
2+
+ // MIR for `f_move` after CopyProp
3+
4+
fn f_move() -> () {
5+
let mut _0: ();
6+
let mut _1: S;
7+
let mut _2: S;
8+
let mut _3: S;
9+
10+
bb0: {
11+
StorageLive(_1);
12+
_1 = S(const 1_u32, const 2_u32);
13+
- StorageLive(_2);
14+
- _2 = copy _1;
15+
- _3 = opaque::<S>(move _1) -> [return: bb1, unwind unreachable];
16+
+ _3 = opaque::<S>(copy _1) -> [return: bb1, unwind unreachable];
17+
}
18+
19+
bb1: {
20+
- StorageDead(_2);
21+
StorageDead(_1);
22+
return;
23+
}
24+
}
25+

tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-abort.diff

Lines changed: 0 additions & 142 deletions
This file was deleted.

0 commit comments

Comments
 (0)