]> git.lizzy.rs Git - rust.git/commit
Fix codegen breaking aliasing rules for functions with sret results
authorBjörn Steinbrink <bsteinbr@gmail.com>
Wed, 22 Oct 2014 19:23:26 +0000 (21:23 +0200)
committerBjörn Steinbrink <bsteinbr@gmail.com>
Thu, 23 Oct 2014 09:43:48 +0000 (11:43 +0200)
commit70fe20a69827a2b1abfef338c83f9ec9be7c9376
treeda6b32606de5474d4c2d6f40566a28c9729a3854
parent2130f2221600f03129df95f3611444468806b237
Fix codegen breaking aliasing rules for functions with sret results

This reverts commit a0ec902e239b2219edf1a18b036dd32c18d3be42 "Avoid
unnecessary temporary on assignments".

Leaving out the temporary for the functions return value can lead to a
situation that conflicts with rust's aliasing rules.

Given this:

````rust
fn func(f: &mut Foo) -> Foo { /* ... */ }

fn bar() {
    let mut foo = Foo { /* ... */ };

    foo = func(&mut foo);
}
````

We effectively get two mutable references to the same variable `foo` at
the same time. One for the parameter `f`, and one for the hidden
out-pointer. So we can't just `trans_into` the destination directly, but
must use `trans` to get a new temporary slot from which the result can
be copied.
src/librustc/middle/trans/expr.rs
src/test/run-pass/out-pointer-aliasing.rs [new file with mode: 0644]