Rollup merge of #122018 - RalfJung:box-custom-alloc, r=oli-obk

only set noalias on Box with the global allocator

As discovered in https://github.com/rust-lang/miri/issues/3341, `noalias` and custom allocators don't go well together.

rustc can now check whether a Box uses the global allocator. This replaces the previous ad-hoc and rather unprincipled check for a zero-sized allocator.

This is the rustc part of fixing that; Miri will also need a patch.
This commit is contained in:
Matthias Krüger 2024-03-05 22:10:02 +01:00 committed by GitHub
commit b08837f180
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 75 additions and 28 deletions

View file

@ -452,7 +452,7 @@ fn adjust_for_rust_scalar<'tcx>(
let no_alias = match kind {
PointerKind::SharedRef { frozen } => frozen,
PointerKind::MutableRef { unpin } => unpin && noalias_mut_ref,
PointerKind::Box { unpin } => unpin && noalias_for_box,
PointerKind::Box { unpin, global } => unpin && global && noalias_for_box,
};
// 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>).