]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/copy_propagation_arg.rs
Render const pointers in MIR more compactly
[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(_2);
65 //     StorageLive(_3);
66 //     _3 = _1;
67 //     _2 = const dummy(move _3) -> bb1;
68 // }
69 // bb1: {
70 //     StorageDead(_3);
71 //     StorageDead(_2);
72 //     _1 = const 5u8;
73 //     ...
74 //     return;
75 // }
76 // END rustc.bar.CopyPropagation.before.mir
77 // START rustc.bar.CopyPropagation.after.mir
78 // bb0: {
79 //     ...
80 //     _3 = _1;
81 //     _2 = const dummy(move _3) -> bb1;
82 // }
83 // bb1: {
84 //     ...
85 //     _1 = const 5u8;
86 //     ...
87 //     return;
88 // }
89 // END rustc.bar.CopyPropagation.after.mir
90 // START rustc.baz.CopyPropagation.before.mir
91 // bb0: {
92 //     StorageLive(_2);
93 //     _2 = _1;
94 //     _1 = move _2;
95 //     StorageDead(_2);
96 //     ...
97 //     return;
98 // }
99 // END rustc.baz.CopyPropagation.before.mir
100 // START rustc.baz.CopyPropagation.after.mir
101 // bb0: {
102 //     ...
103 //     _2 = _1;
104 //     _1 = move _2;
105 //     ...
106 //     return;
107 // }
108 // END rustc.baz.CopyPropagation.after.mir
109 // START rustc.arg_src.CopyPropagation.before.mir
110 // bb0: {
111 //      ...
112 //      _2 = _1;
113 //      ...
114 //      _1 = const 123i32;
115 //      ...
116 //      _0 = _2;
117 //      ...
118 //      return;
119 //  }
120 // END rustc.arg_src.CopyPropagation.before.mir
121 // START rustc.arg_src.CopyPropagation.after.mir
122 // bb0: {
123 //     ...
124 //     _2 = _1;
125 //     ...
126 //     _1 = const 123i32;
127 //     ...
128 //     _0 = _2;
129 //     ...
130 //     return;
131 // }
132 // END rustc.arg_src.CopyPropagation.after.mir