diff options
| author | bors <bors@rust-lang.org> | 2017-11-26 16:38:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-11-26 16:38:36 +0000 |
| commit | 71b21ed0daa9d81d44f2168d16b00f681bb7286a (patch) | |
| tree | 91e56e01f1e4aef95fb8d015e3734751534efa13 | |
| parent | 0400312e173f3247f84890222134b9a86e6b3d8f (diff) | |
| parent | 5eed95ede9d68e9c18c5798aad60b5f94b8a213b (diff) | |
| download | rust-71b21ed0daa9d81d44f2168d16b00f681bb7286a.tar.gz rust-71b21ed0daa9d81d44f2168d16b00f681bb7286a.zip | |
Auto merge of #46253 - eddyb:return-aliasing, r=nagisa
rustc_trans: don't apply noalias on returned references. In #45225 frozen returned `&T` were accidentally maked `noalias`, unlike `&mut T`. Return value `noalias` is only sound for functions that return dynamic allocations, e.g. `Box`, and using it on anything else can lead to miscompilation, as LLVM assumes certain usage patterns. Fixes #46239.
| -rw-r--r-- | src/librustc_trans/abi.rs | 3 | ||||
| -rw-r--r-- | src/test/run-make/issue-46239/Makefile | 5 | ||||
| -rw-r--r-- | src/test/run-make/issue-46239/main.rs | 18 |
3 files changed, 25 insertions, 1 deletions
diff --git a/src/librustc_trans/abi.rs b/src/librustc_trans/abi.rs index 54828044de6..1cd138d4ee6 100644 --- a/src/librustc_trans/abi.rs +++ b/src/librustc_trans/abi.rs @@ -792,7 +792,8 @@ impl<'a, 'tcx> FnType<'tcx> { // dependencies rather than pointer equality let no_alias = match kind { PointerKind::Shared => false, - PointerKind::Frozen | PointerKind::UniqueOwned => true, + PointerKind::UniqueOwned => true, + PointerKind::Frozen | PointerKind::UniqueBorrowed => !is_return }; if no_alias { diff --git a/src/test/run-make/issue-46239/Makefile b/src/test/run-make/issue-46239/Makefile new file mode 100644 index 00000000000..698a605f7e9 --- /dev/null +++ b/src/test/run-make/issue-46239/Makefile @@ -0,0 +1,5 @@ +-include ../tools.mk + +all: + $(RUSTC) main.rs -C opt-level=1 + $(call RUN,main) diff --git a/src/test/run-make/issue-46239/main.rs b/src/test/run-make/issue-46239/main.rs new file mode 100644 index 00000000000..3b3289168ab --- /dev/null +++ b/src/test/run-make/issue-46239/main.rs @@ -0,0 +1,18 @@ +// 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. + +fn project<T>(x: &(T,)) -> &T { &x.0 } + +fn dummy() {} + +fn main() { + let f = (dummy as fn(),); + (*project(&f))(); +} |
