]> git.proxmox.com Git - rustc.git/blob - src/test/mir-opt/dest-prop/copy_propagation_arg.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / src / test / mir-opt / dest-prop / copy_propagation_arg.rs
1 // Check that DestinationPropagation does not propagate an assignment to a function argument
2 // (doing so can break usages of the original argument value)
3 // compile-flags: -Zunsound-mir-opts
4 fn dummy(x: u8) -> u8 {
5 x
6 }
7
8 // EMIT_MIR copy_propagation_arg.foo.DestinationPropagation.diff
9 fn foo(mut x: u8) {
10 // calling `dummy` to make an use of `x` that copyprop cannot eliminate
11 x = dummy(x); // this will assign a local to `x`
12 }
13
14 // EMIT_MIR copy_propagation_arg.bar.DestinationPropagation.diff
15 fn bar(mut x: u8) {
16 dummy(x);
17 x = 5;
18 }
19
20 // EMIT_MIR copy_propagation_arg.baz.DestinationPropagation.diff
21 fn baz(mut x: i32) {
22 // self-assignment to a function argument should be eliminated
23 x = x;
24 }
25
26 // EMIT_MIR copy_propagation_arg.arg_src.DestinationPropagation.diff
27 fn arg_src(mut x: i32) -> i32 {
28 let y = x;
29 x = 123; // Don't propagate this assignment to `y`
30 y
31 }
32
33 fn main() {
34 // Make sure the function actually gets instantiated.
35 foo(0);
36 bar(0);
37 baz(0);
38 arg_src(0);
39 }