Auto merge of #106371 - RalfJung:no-ret-position-noalias, r=nikic
do not add noalias in return position `noalias` as a return attribute in LLVM indicates that the returned pointer does not alias anything else that is reachable from the caller, *including things reachable before this function call*. This is clearly not the case with a function like `fn id(Box<T>) -> Box<T>`, so we cannot use this attribute. Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/385 (including an actual miscompilation that `@comex` managed to produce).
This commit is contained in:
commit
442f997f98
2 changed files with 5 additions and 3 deletions
|
@ -273,9 +273,11 @@ fn adjust_for_rust_scalar<'tcx>(
|
|||
| PointerKind::UniqueBorrowed
|
||||
| PointerKind::UniqueBorrowedPinned => false,
|
||||
PointerKind::UniqueOwned => noalias_for_box,
|
||||
PointerKind::Frozen => !is_return,
|
||||
PointerKind::Frozen => true,
|
||||
};
|
||||
if no_alias {
|
||||
// We can never add `noalias` in return position; that LLVM attribute has some very surprising semantics
|
||||
// (see <https://github.com/rust-lang/unsafe-code-guidelines/issues/385#issuecomment-1368055745>).
|
||||
if no_alias && !is_return {
|
||||
attrs.set(ArgAttribute::NoAlias);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue