diff options
| author | bors <bors@rust-lang.org> | 2022-03-12 14:18:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-12 14:18:34 +0000 |
| commit | ed2a69c4a9f3e5535461484af6266681fd7d90d4 (patch) | |
| tree | 99d25e3425f109bb25ef1b8591e1748f144abf9c | |
| parent | 258256697b8550860be0f6194dec532ac616c2c1 (diff) | |
| parent | 9d72dd54d0fac28e3611ff553edbbd695f6e8357 (diff) | |
| download | rust-ed2a69c4a9f3e5535461484af6266681fd7d90d4.tar.gz rust-ed2a69c4a9f3e5535461484af6266681fd7d90d4.zip | |
Auto merge of #94873 - DrMeepster:box_alloc_ice3, r=oli-obk
Fix ICE when using Box<T, A>, again Sequel to #94043, fixes #94835.
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/operand.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/box/large-allocator-ice.rs | 6 |
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 66be58cf62c..858f71ebc39 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 3ef1171ff50..b3a882ff089 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<T>(val: T) { + *Box::new_in(val, &std::alloc::Global); } |
