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