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