]> git.lizzy.rs Git - rust.git/commit
Auto merge of #45753 - sinkuu:mir_copyprop_arg, r=arielb1
authorbors <bors@rust-lang.org>
Sun, 12 Nov 2017 15:38:13 +0000 (15:38 +0000)
committerbors <bors@rust-lang.org>
Sun, 12 Nov 2017 15:38:13 +0000 (15:38 +0000)
commit3d2dc6e9402824f5fecba4f076d0bf2bcd01cbeb
treead24d3754466c77d700bb34e5a809400e702b2b8
parent4b6f7252a135a3fd1dba6f5e002b9d3d3af034b9
parent114252410d72b63bda4eefa62df77727d1f1cc41
Auto merge of #45753 - sinkuu:mir_copyprop_arg, r=arielb1

Fix MIR CopyPropagation errneously propagating assignments to function args

Compiling this code with MIR CopyPropagation activated will result in printing `5`,
because CopyProp errneously propagates the assignment of `5` to all `x`:

```rust
fn bar(mut x: u8) {
    println!("{}", x);
    x = 5;
}

fn main() {
    bar(123);
}

```

If a local is propagated, it will result in an ICE at trans due to an use-before-def:

```rust
fn dummy(x: u8) -> u8 { x }

fn foo(mut x: u8) {
    x = dummy(x); // this will assign a local to `x`
}
```
Currently CopyProp conservatively gives up if there are multiple assignments to a local,
but it is not took into account that arguments are already assigned from the beginning.
This PR fixes the problem by preventing propagation of assignments to function arguments.