Skip to content

Commit

Permalink
fix another assumption about box
Browse files Browse the repository at this point in the history
  • Loading branch information
beepster4096 committed Mar 12, 2022
1 parent c5a43b8 commit 9d72dd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
.ty;
let (llptr, llextra) = match self.val {
OperandValue::Immediate(llptr) => (llptr, None),
OperandValue::Pair(llptr, llextra) => (llptr, Some(llextra)),
OperandValue::Pair(llptr, llextra) => {
// if the box's allocator isn't a ZST, then "llextra" is actually the allocator
if self.layout.ty.is_box() && !self.layout.field(cx, 1).is_zst() {
(llptr, None)
} else {
(llptr, Some(llextra))
}
}
OperandValue::Ref(..) => bug!("Deref of by-Ref operand {:?}", self),
};
let layout = cx.layout_of(projected_ty);
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/box/large-allocator-ice.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// build-pass
#![feature(allocator_api)]
#![allow(unused_must_use)]

use std::alloc::Allocator;

Expand All @@ -20,4 +21,9 @@ unsafe impl Allocator for BigAllocator {
fn main() {
Box::new_in((), &std::alloc::Global);
Box::new_in((), BigAllocator([0; 2]));
generic_function(0);
}

fn generic_function<T>(val: T) {
*Box::new_in(val, &std::alloc::Global);
}

0 comments on commit 9d72dd5

Please sign in to comment.