Skip to content

Commit

Permalink
Rollup merge of #94043 - DrMeepster:box_alloc_ice, r=oli-obk
Browse files Browse the repository at this point in the history
Fix ICE when using Box<T, A> with pointer sized A

Fixes #78459

Note that using `Box<T, A>` with a more than pointer sized `A` or using a pointer sized `A` with a Box of a DST will produce a different ICE (#92054) which is not fixed by this PR.
  • Loading branch information
matthiaskrgr committed Feb 17, 2022
2 parents a4be35e + d0b508e commit 6dc62f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_llvm/src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
ty::Ref(..) | ty::RawPtr(_) => {
return self.field(cx, index).llvm_type(cx);
}
ty::Adt(def, _) if def.is_box() => {
// only wide pointer boxes are handled as pointers
// thin pointer boxes with scalar allocators are handled by the general logic below
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
let ptr_ty = cx.tcx.mk_mut_ptr(self.ty.boxed_ty());
return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate);
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/box/issue-78459-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// check-pass
#![feature(allocator_api)]

fn main() {
Box::new_in((), &std::alloc::Global);
}

0 comments on commit 6dc62f4

Please sign in to comment.