diff options
| author | bors <bors@rust-lang.org> | 2022-06-21 11:00:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-21 11:00:39 +0000 |
| commit | a25b1315ee968146a5b206a8f3c670c5b307ebfe (patch) | |
| tree | 725cc7bfd11f72a19a2ac5d0212dcb83cfe7ed37 /compiler/rustc_codegen_ssa | |
| parent | abace0a1f17986d89aedf610819deab2b4afee56 (diff) | |
| parent | 28ff0df6ede91c8bfadb29d5f966cff15b15c9df (diff) | |
| download | rust-a25b1315ee968146a5b206a8f3c670c5b307ebfe.tar.gz rust-a25b1315ee968146a5b206a8f3c670c5b307ebfe.zip | |
Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obk
Remove dereferencing of Box from codegen Through #94043, #94414, #94873, and #95328, I've been fixing issues caused by Box being treated like a pointer when it is not a pointer. However, these PRs just introduced special cases for Box. This PR removes those special cases and instead transforms a deref of Box into a deref of the pointer it contains. Hopefully, this is the end of the Box<T, A> ICEs.
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/operand.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/place.rs | 24 |
2 files changed, 8 insertions, 30 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 08be4c0a7b6..2e655ae94cc 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -118,22 +118,20 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { } pub fn deref<Cx: LayoutTypeMethods<'tcx>>(self, cx: &Cx) -> PlaceRef<'tcx, V> { + if self.layout.ty.is_box() { + bug!("dereferencing {:?} in codegen", self.layout.ty); + } + let projected_ty = self .layout .ty .builtin_deref(true) .unwrap_or_else(|| bug!("deref of non-pointer {:?}", self)) .ty; + let (llptr, llextra) = match self.val { OperandValue::Immediate(llptr) => (llptr, None), - 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::Pair(llptr, llextra) => (llptr, Some(llextra)), OperandValue::Ref(..) => bug!("Deref of by-Ref operand {:?}", self), }; let layout = cx.layout_of(projected_ty); diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 3185b952ab8..5b88635982f 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -446,16 +446,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::PlaceRef { projection: &place_ref.projection[..elem.0], ..place_ref }, ); - // a box with a non-zst allocator should not be directly dereferenced - if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 1).is_zst() { - // Extract `Box<T>` -> `Unique<T>` -> `NonNull<T>` -> `*const T` - let ptr = - cg_base.extract_field(bx, 0).extract_field(bx, 0).extract_field(bx, 0); - - ptr.deref(bx.cx()) - } else { - cg_base.deref(bx.cx()) - } + cg_base.deref(bx.cx()) } else { bug!("using operand local {:?} as place", place_ref); } @@ -463,18 +454,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { }; for elem in place_ref.projection[base..].iter() { cg_base = match *elem { - mir::ProjectionElem::Deref => { - // a box with a non-zst allocator should not be directly dereferenced - if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 1).is_zst() { - // Project `Box<T>` -> `Unique<T>` -> `NonNull<T>` -> `*const T` - let ptr = - cg_base.project_field(bx, 0).project_field(bx, 0).project_field(bx, 0); - - bx.load_operand(ptr).deref(bx.cx()) - } else { - bx.load_operand(cg_base).deref(bx.cx()) - } - } + mir::ProjectionElem::Deref => bx.load_operand(cg_base).deref(bx.cx()), mir::ProjectionElem::Field(ref field, _) => { cg_base.project_field(bx, field.index()) } |
