]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/copy_propagation_arg.rs
Rollup merge of #52656 - jD91mZM2:stablize-uds, r=alexcrichton
[rust.git] / src / test / mir-opt / copy_propagation_arg.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Check that CopyPropagation does not propagate an assignment to a function argument
12 // (doing so can break usages of the original argument value)
13
14 fn dummy(x: u8) -> u8 {
15     x
16 }
17
18 fn foo(mut x: u8) {
19     // calling `dummy` to make an use of `x` that copyprop cannot eliminate
20     x = dummy(x); // this will assign a local to `x`
21 }
22
23 fn bar(mut x: u8) {
24     dummy(x);
25     x = 5;
26 }
27
28 fn baz(mut x: i32) {
29     // self-assignment to a function argument should be eliminated
30     x = x;
31 }
32
33 fn arg_src(mut x: i32) -> i32 {
34     let y = x;
35     x = 123; // Don't propagate this assignment to `y`
36     y
37 }
38
39 fn main() {
40     // Make sure the function actually gets instantiated.
41     foo(0);
42     bar(0);
43     baz(0);
44     arg_src(0);
45 }
46
47 // END RUST SOURCE
48 // START rustc.foo.CopyPropagation.before.mir
49 // bb0: {
50 //     ...
51 //     _3 = _1;
52 //     _2 = const dummy(move _3) -> bb1;
53 // }
54 // bb1: {
55 //     ...
56 //     _1 = move _2;
57 //     ...
58 // }
59 // END rustc.foo.CopyPropagation.before.mir
60 // START rustc.foo.CopyPropagation.after.mir
61 // bb0: {
62 //     ...
63 //     _3 = _1;
64 //     _2 = const dummy(move _3) -> bb1;
65 // }
66 // bb1: {
67 //     ...
68 //     _1 = move _2;
69 //     ...
70 // }
71 // END rustc.foo.CopyPropagation.after.mir
72 // START rustc.bar.CopyPropagation.before.mir
73 // bb0: {
74 //     StorageLive(_3);
75 //     _3 = _1;
76 //     _2 = const dummy(move _3) -> bb1;
77 // }
78 // bb1: {
79 //     StorageDead(_3);
80 //     _1 = const 5u8;
81 //     ...
82 //     return;
83 // }
84 // END rustc.bar.CopyPropagation.before.mir
85 // START rustc.bar.CopyPropagation.after.mir
86 // bb0: {
87 //     ...
88 //     _3 = _1;
89 //     _2 = const dummy(move _3) -> bb1;
90 // }
91 // bb1: {
92 //     ...
93 //     _1 = const 5u8;
94 //     ...
95 //     return;
96 // }
97 // END rustc.bar.CopyPropagation.after.mir
98 // START rustc.baz.CopyPropagation.before.mir
99 // bb0: {
100 //     StorageLive(_2);
101 //     _2 = _1;
102 //     _1 = move _2;
103 //     StorageDead(_2);
104 //     ...
105 //     return;
106 // }
107 // END rustc.baz.CopyPropagation.before.mir
108 // START rustc.baz.CopyPropagation.after.mir
109 // bb0: {
110 //     ...
111 //     _2 = _1;
112 //     _1 = move _2;
113 //     ...
114 //     return;
115 // }
116 // END rustc.baz.CopyPropagation.after.mir
117 // START rustc.arg_src.CopyPropagation.before.mir
118 // bb0: {
119 //      ...
120 //      _2 = _1;
121 //      ...
122 //      _1 = const 123i32;
123 //      ...
124 //      _0 = _2;
125 //      ...
126 //      return;
127 //  }
128 // END rustc.arg_src.CopyPropagation.before.mir
129 // START rustc.arg_src.CopyPropagation.after.mir
130 // bb0: {
131 //     ...
132 //     _2 = _1;
133 //     ...
134 //     _1 = const 123i32;
135 //     ...
136 //     _0 = _2;
137 //     ...
138 //     return;
139 // }
140 // END rustc.arg_src.CopyPropagation.after.mir