Skip to content

Commit 6dc62f4

Browse files
authored
Rollup merge of #94043 - DrMeepster:box_alloc_ice, r=oli-obk
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.
2 parents a4be35e + d0b508e commit 6dc62f4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

compiler/rustc_codegen_llvm/src/type_of.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
330330
ty::Ref(..) | ty::RawPtr(_) => {
331331
return self.field(cx, index).llvm_type(cx);
332332
}
333-
ty::Adt(def, _) if def.is_box() => {
333+
// only wide pointer boxes are handled as pointers
334+
// thin pointer boxes with scalar allocators are handled by the general logic below
335+
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
334336
let ptr_ty = cx.tcx.mk_mut_ptr(self.ty.boxed_ty());
335337
return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate);
336338
}

src/test/ui/box/issue-78459-ice.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// check-pass
2+
#![feature(allocator_api)]
3+
4+
fn main() {
5+
Box::new_in((), &std::alloc::Global);
6+
}

0 commit comments

Comments
 (0)