]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/copy_propagation_arg.rs
Rollup merge of #57278 - mati865:config_clippy, r=alexcrichton
[rust.git] / src / test / mir-opt / copy_propagation_arg.rs
1 // Check that CopyPropagation does not propagate an assignment to a function argument
2 // (doing so can break usages of the original argument value)
3
4 fn dummy(x: u8) -> u8 {
5     x
6 }
7
8 fn foo(mut x: u8) {
9     // calling `dummy` to make an use of `x` that copyprop cannot eliminate
10     x = dummy(x); // this will assign a local to `x`
11 }
12
13 fn bar(mut x: u8) {
14     dummy(x);
15     x = 5;
16 }
17
18 fn baz(mut x: i32) {
19     // self-assignment to a function argument should be eliminated
20     x = x;
21 }
22
23 fn arg_src(mut x: i32) -> i32 {
24     let y = x;
25     x = 123; // Don't propagate this assignment to `y`
26     y
27 }
28
29 fn main() {
30     // Make sure the function actually gets instantiated.
31     foo(0);
32     bar(0);
33     baz(0);
34     arg_src(0);
35 }
36
37 // END RUST SOURCE
38 // START rustc.foo.CopyPropagation.before.mir
39 // bb0: {
40 //     ...
41 //     _3 = _1;
42 //     _2 = const dummy(move _3) -> bb1;
43 // }
44 // bb1: {
45 //     ...
46 //     _1 = move _2;
47 //     ...
48 // }
49 // END rustc.foo.CopyPropagation.before.mir
50 // START rustc.foo.CopyPropagation.after.mir
51 // bb0: {
52 //     ...
53 //     _3 = _1;
54 //     _2 = const dummy(move _3) -> bb1;
55 // }
56 // bb1: {
57 //     ...
58 //     _1 = move _2;
59 //     ...
60 // }
61 // END rustc.foo.CopyPropagation.after.mir
62 // START rustc.bar.CopyPropagation.before.mir
63 // bb0: {
64 //     StorageLive(_3);
65 //     _3 = _1;
66 //     _2 = const dummy(move _3) -> bb1;
67 // }
68 // bb1: {
69 //     StorageDead(_3);
70 //     _1 = const 5u8;
71 //     ...
72 //     return;
73 // }
74 // END rustc.bar.CopyPropagation.before.mir
75 // START rustc.bar.CopyPropagation.after.mir
76 // bb0: {
77 //     ...
78 //     _3 = _1;
79 //     _2 = const dummy(move _3) -> bb1;
80 // }
81 // bb1: {
82 //     ...
83 //     _1 = const 5u8;
84 //     ...
85 //     return;
86 // }
87 // END rustc.bar.CopyPropagation.after.mir
88 // START rustc.baz.CopyPropagation.before.mir
89 // bb0: {
90 //     StorageLive(_2);
91 //     _2 = _1;
92 //     _1 = move _2;
93 //     StorageDead(_2);
94 //     ...
95 //     return;
96 // }
97 // END rustc.baz.CopyPropagation.before.mir
98 // START rustc.baz.CopyPropagation.after.mir
99 // bb0: {
100 //     ...
101 //     _2 = _1;
102 //     _1 = move _2;
103 //     ...
104 //     return;
105 // }
106 // END rustc.baz.CopyPropagation.after.mir
107 // START rustc.arg_src.CopyPropagation.before.mir
108 // bb0: {
109 //      ...
110 //      _2 = _1;
111 //      ...
112 //      _1 = const 123i32;
113 //      ...
114 //      _0 = _2;
115 //      ...
116 //      return;
117 //  }
118 // END rustc.arg_src.CopyPropagation.before.mir
119 // START rustc.arg_src.CopyPropagation.after.mir
120 // bb0: {
121 //     ...
122 //     _2 = _1;
123 //     ...
124 //     _1 = const 123i32;
125 //     ...
126 //     _0 = _2;
127 //     ...
128 //     return;
129 // }
130 // END rustc.arg_src.CopyPropagation.after.mir