From 9d72dd54d0fac28e3611ff553edbbd695f6e8357 Mon Sep 17 00:00:00 2001 From: DrMeepster <19316085+DrMeepster@users.noreply.github.com> Date: Fri, 11 Mar 2022 17:00:56 -0800 Subject: [PATCH] fix another assumption about box --- compiler/rustc_codegen_ssa/src/mir/operand.rs | 9 ++++++++- src/test/ui/box/large-allocator-ice.rs | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 66be58cf62ca0..858f71ebc3933 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -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); diff --git a/src/test/ui/box/large-allocator-ice.rs b/src/test/ui/box/large-allocator-ice.rs index 3ef1171ff50d9..b3a882ff089b0 100644 --- a/src/test/ui/box/large-allocator-ice.rs +++ b/src/test/ui/box/large-allocator-ice.rs @@ -1,5 +1,6 @@ // build-pass #![feature(allocator_api)] +#![allow(unused_must_use)] use std::alloc::Allocator; @@ -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(val: T) { + *Box::new_in(val, &std::alloc::Global); }