only set noalias on Box with the global allocator
This commit is contained in:
parent
5a1e5449c8
commit
f391c0793b
17 changed files with 75 additions and 28 deletions
|
@ -969,6 +969,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Compute the information for the pointer stored at the given offset inside this type.
|
||||
/// This will recurse into fields of ADTs to find the inner pointer.
|
||||
fn ty_and_layout_pointee_info_at(
|
||||
this: TyAndLayout<'tcx>,
|
||||
cx: &C,
|
||||
|
@ -1068,15 +1070,17 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME(eddyb) This should be for `ptr::Unique<T>`, not `Box<T>`.
|
||||
// Fixup info for the first field of a `Box`. Recursive traversal will have found
|
||||
// the raw pointer, so size and align are set to the boxed type, but `pointee.safe`
|
||||
// will still be `None`.
|
||||
if let Some(ref mut pointee) = result {
|
||||
if let ty::Adt(def, _) = this.ty.kind() {
|
||||
if def.is_box() && offset.bytes() == 0 {
|
||||
let optimize = tcx.sess.opts.optimize != OptLevel::No;
|
||||
pointee.safe = Some(PointerKind::Box {
|
||||
unpin: optimize && this.ty.boxed_ty().is_unpin(tcx, cx.param_env()),
|
||||
});
|
||||
}
|
||||
if offset.bytes() == 0 && this.ty.is_box() {
|
||||
debug_assert!(pointee.safe.is_none());
|
||||
let optimize = tcx.sess.opts.optimize != OptLevel::No;
|
||||
pointee.safe = Some(PointerKind::Box {
|
||||
unpin: optimize && this.ty.boxed_ty().is_unpin(tcx, cx.param_env()),
|
||||
global: this.ty.is_box_global(tcx),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1999,6 +1999,27 @@ impl<'tcx> Ty<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Tests whether this is a Box using the global allocator.
|
||||
#[inline]
|
||||
pub fn is_box_global(self, tcx: TyCtxt<'tcx>) -> bool {
|
||||
match self.kind() {
|
||||
Adt(def, args) if def.is_box() => {
|
||||
let Some(alloc) = args.get(1) else {
|
||||
// Single-argument Box is always global. (for "minicore" tests)
|
||||
return true;
|
||||
};
|
||||
if let Some(alloc_adt) = alloc.expect_ty().ty_adt_def() {
|
||||
let global_alloc = tcx.require_lang_item(LangItem::GlobalAlloc, None);
|
||||
alloc_adt.did() == global_alloc
|
||||
} else {
|
||||
// Allocator is not an ADT...
|
||||
false
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Panics if called on any type other than `Box<T>`.
|
||||
pub fn boxed_ty(self) -> Ty<'tcx> {
|
||||
match self.kind() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue