Skip to content

Commit e7cad62

Browse files
committed
do not add noalias in return position
1 parent b38a6d3 commit e7cad62

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/rustc_ty_utils/src/abi.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,11 @@ fn adjust_for_rust_scalar<'tcx>(
273273
| PointerKind::UniqueBorrowed
274274
| PointerKind::UniqueBorrowedPinned => false,
275275
PointerKind::UniqueOwned => noalias_for_box,
276-
PointerKind::Frozen => !is_return,
276+
PointerKind::Frozen => true,
277277
};
278-
if no_alias {
278+
// We can never add `noalias` in return position; that LLVM attribute has some very surprising semantics
279+
// (see <https://github.com/rust-lang/unsafe-code-guidelines/issues/385#issuecomment-1368055745>).
280+
if no_alias && !is_return {
279281
attrs.set(ArgAttribute::NoAlias);
280282
}
281283

src/test/codegen/function-arguments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn raw_struct(_: *const S) {
145145

146146
// `Box` can get deallocated during execution of the function, so it should
147147
// not get `dereferenceable`.
148-
// CHECK: noalias noundef nonnull align 4 {{i32\*|ptr}} @_box({{i32\*|ptr}} noalias noundef nonnull align 4 %x)
148+
// CHECK: noundef nonnull align 4 {{i32\*|ptr}} @_box({{i32\*|ptr}} noalias noundef nonnull align 4 %x)
149149
#[no_mangle]
150150
pub fn _box(x: Box<i32>) -> Box<i32> {
151151
x

0 commit comments

Comments
 (0)