]> git.lizzy.rs Git - rust.git/commitdiff
do not add noalias in return position
authorRalf Jung <post@ralfj.de>
Mon, 2 Jan 2023 14:11:19 +0000 (15:11 +0100)
committerRalf Jung <post@ralfj.de>
Mon, 2 Jan 2023 14:11:19 +0000 (15:11 +0100)
compiler/rustc_ty_utils/src/abi.rs
src/test/codegen/function-arguments.rs

index d644cbccea11b2df6c5080a2191ad3c1c8b8f4f1..73d2d278f93f3bb0886c518448ba59ccd25c402c 100644 (file)
@@ -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);
             }
 
index 44fee952307f29b5c43ef7ca60ae7826f5662a70..0f9e90f6ba77990d2c265057699170a5cd372dbe 100644 (file)
@@ -145,7 +145,7 @@ pub fn raw_struct(_: *const S) {
 
 // `Box` can get deallocated during execution of the function, so it should
 // not get `dereferenceable`.
-// CHECK: noalias noundef nonnull align 4 {{i32\*|ptr}} @_box({{i32\*|ptr}} noalias noundef nonnull align 4 %x)
+// CHECK: noundef nonnull align 4 {{i32\*|ptr}} @_box({{i32\*|ptr}} noalias noundef nonnull align 4 %x)
 #[no_mangle]
 pub fn _box(x: Box<i32>) -> Box<i32> {
   x