Skip to content

Commit 8b85d8e

Browse files
committed
Do it for functions involving raw pointers
1 parent f089cf8 commit 8b85d8e

File tree

1 file changed

+10
-8
lines changed
  • compiler/rustc_ty_utils/src

1 file changed

+10
-8
lines changed

compiler/rustc_ty_utils/src/abi.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::iter;
33
use rustc_abi::Primitive::Pointer;
44
use rustc_abi::{BackendRepr, ExternAbi, PointerKind, Scalar, Size};
55
use rustc_hir as hir;
6-
use rustc_hir::attrs::InlineAttr;
76
use rustc_hir::lang_items::LangItem;
87
use rustc_middle::bug;
98
use rustc_middle::query::Providers;
@@ -276,7 +275,7 @@ fn arg_attrs_for_rust_scalar<'tcx>(
276275
offset: Size,
277276
is_return: bool,
278277
drop_target_pointee: Option<Ty<'tcx>>,
279-
is_inline: bool,
278+
involves_raw_ptr: bool,
280279
) -> ArgAttributes {
281280
let mut attrs = ArgAttributes::new();
282281

@@ -353,7 +352,7 @@ fn arg_attrs_for_rust_scalar<'tcx>(
353352

354353
// We can never add `noalias` in return position; that LLVM attribute has some very surprising semantics
355354
// (see <https://github.com/rust-lang/unsafe-code-guidelines/issues/385#issuecomment-1368055745>).
356-
if no_alias && !is_inline && !is_return {
355+
if no_alias && !involves_raw_ptr && !is_return {
357356
attrs.set(ArgAttribute::NoAlias);
358357
}
359358

@@ -512,10 +511,13 @@ fn fn_abi_new_uncached<'tcx>(
512511
extra_args
513512
};
514513

515-
let is_inline = determined_fn_def_id.is_some_and(|def_id| {
516-
let inline_attrs = tcx.codegen_fn_attrs(def_id).inline;
517-
inline_attrs == InlineAttr::Always
518-
});
514+
let involves_raw_ptr = inputs
515+
.iter()
516+
.copied()
517+
.chain(extra_args.iter().copied())
518+
.chain(caller_location)
519+
.chain(Some(sig.output()))
520+
.any(|ty| matches!(ty.kind(), ty::RawPtr(_, _)));
519521

520522
let is_drop_in_place = determined_fn_def_id.is_some_and(|def_id| {
521523
tcx.is_lang_item(def_id, LangItem::DropInPlace)
@@ -550,7 +552,7 @@ fn fn_abi_new_uncached<'tcx>(
550552
offset,
551553
is_return,
552554
drop_target_pointee,
553-
is_inline,
555+
involves_raw_ptr,
554556
)
555557
});
556558

0 commit comments

Comments
 (0)