only set noalias on Box with the global allocator

This commit is contained in:
Ralf Jung 2024-03-05 11:32:03 +01:00
parent 5a1e5449c8
commit f391c0793b
17 changed files with 75 additions and 28 deletions

View file

@ -437,6 +437,7 @@ where
trace!("deref to {} on {:?}", val.layout.ty, *val);
if val.layout.ty.is_box() {
// Derefer should have removed all Box derefs
bug!("dereferencing {}", val.layout.ty);
}

View file

@ -359,14 +359,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Ok(Some(match ty.kind() {
ty::Ref(_, ty, _) => *ty,
ty::RawPtr(mt) => mt.ty,
// We should only accept `Box` with the default allocator.
// It's hard to test for that though so we accept every 1-ZST allocator.
ty::Adt(def, args)
if def.is_box()
&& self.layout_of(args[1].expect_ty()).is_ok_and(|l| l.is_1zst()) =>
{
args[0].expect_ty()
}
// We only accept `Box` with the default allocator.
_ if ty.is_box_global(*self.tcx) => ty.boxed_ty(),
_ => return Ok(None),
}))
};