Skip to content

Commit ed2a69c

Browse files
committed
Auto merge of rust-lang#94873 - DrMeepster:box_alloc_ice3, r=oli-obk
Fix ICE when using Box<T, A>, again Sequel to rust-lang#94043, fixes rust-lang#94835.
2 parents 2582566 + 9d72dd5 commit ed2a69c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

compiler/rustc_codegen_ssa/src/mir/operand.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,14 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
126126
.ty;
127127
let (llptr, llextra) = match self.val {
128128
OperandValue::Immediate(llptr) => (llptr, None),
129-
OperandValue::Pair(llptr, llextra) => (llptr, Some(llextra)),
129+
OperandValue::Pair(llptr, llextra) => {
130+
// if the box's allocator isn't a ZST, then "llextra" is actually the allocator
131+
if self.layout.ty.is_box() && !self.layout.field(cx, 1).is_zst() {
132+
(llptr, None)
133+
} else {
134+
(llptr, Some(llextra))
135+
}
136+
}
130137
OperandValue::Ref(..) => bug!("Deref of by-Ref operand {:?}", self),
131138
};
132139
let layout = cx.layout_of(projected_ty);

src/test/ui/box/large-allocator-ice.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// build-pass
22
#![feature(allocator_api)]
3+
#![allow(unused_must_use)]
34

45
use std::alloc::Allocator;
56

@@ -20,4 +21,9 @@ unsafe impl Allocator for BigAllocator {
2021
fn main() {
2122
Box::new_in((), &std::alloc::Global);
2223
Box::new_in((), BigAllocator([0; 2]));
24+
generic_function(0);
25+
}
26+
27+
fn generic_function<T>(val: T) {
28+
*Box::new_in(val, &std::alloc::Global);
2329
}

0 commit comments

Comments
 (0)