1
- // skip-filecheck
2
1
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
3
2
// Check that DestinationPropagation does not propagate an assignment to a function argument
4
3
// (doing so can break usages of the original argument value)
@@ -9,25 +8,42 @@ fn dummy(x: u8) -> u8 {
9
8
10
9
// EMIT_MIR copy_propagation_arg.foo.DestinationPropagation.diff
11
10
fn foo ( mut x : u8 ) {
11
+ // CHECK-LABEL: fn foo(
12
+ // CHECK: debug x => [[x:_.*]];
13
+ // CHECK: dummy(move [[x]])
14
+ // CHECK: [[x]] = move {{_.*}};
12
15
// calling `dummy` to make a use of `x` that copyprop cannot eliminate
13
16
x = dummy ( x) ; // this will assign a local to `x`
14
17
}
15
18
16
19
// EMIT_MIR copy_propagation_arg.bar.DestinationPropagation.diff
17
20
fn bar ( mut x : u8 ) {
21
+ // CHECK-LABEL: fn bar(
22
+ // CHECK: debug x => [[x:_.*]];
23
+ // CHECK: dummy(move [[x]])
24
+ // CHECK: [[x]] = const 5_u8;
18
25
dummy ( x) ;
19
26
x = 5 ;
20
27
}
21
28
22
29
// EMIT_MIR copy_propagation_arg.baz.DestinationPropagation.diff
23
30
fn baz ( mut x : i32 ) -> i32 {
31
+ // CHECK-LABEL: fn baz(
32
+ // CHECK: debug x => [[x:_.*]];
33
+ // CHECK-NOT: [[x]] = {{_.*}}
24
34
// self-assignment to a function argument should be eliminated
25
35
x = x;
26
36
x
27
37
}
28
38
29
39
// EMIT_MIR copy_propagation_arg.arg_src.DestinationPropagation.diff
30
40
fn arg_src ( mut x : i32 ) -> i32 {
41
+ // CHECK-LABEL: fn arg_src(
42
+ // CHECK: debug x => [[x:_.*]];
43
+ // CHECK: debug y => [[y:_.*]];
44
+ // CHECK: [[y]] = [[x]]
45
+ // CHECK: [[x]] = const 123_i32;
46
+ // CHECK-NOT: {{_.*}} = [[y]];
31
47
let y = x;
32
48
x = 123 ; // Don't propagate this assignment to `y`
33
49
y
0 commit comments