diff options
| author | DrMeepster <19316085+DrMeepster@users.noreply.github.com> | 2022-03-27 13:35:29 -0700 |
|---|---|---|
| committer | DrMeepster <19316085+DrMeepster@users.noreply.github.com> | 2022-03-27 13:35:29 -0700 |
| commit | 09ccc63624f627e44f13c480c934b4d28a845258 (patch) | |
| tree | f41d2dbd6f7d594ffdeb02cbbdeee0aba33c47cc /compiler/rustc_codegen_ssa | |
| parent | ece64ed3f56f811f2122dc3dcbff85bf47f8fee3 (diff) | |
| download | rust-09ccc63624f627e44f13c480c934b4d28a845258.tar.gz rust-09ccc63624f627e44f13c480c934b4d28a845258.zip | |
fix other source of box deref
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/place.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index be8b0f3c991..17cfb6c5dfb 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -441,11 +441,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { .find(|elem| matches!(elem.1, mir::ProjectionElem::Deref)) { base = elem.0 + 1; - self.codegen_consume( + let cg_base = self.codegen_consume( bx, mir::PlaceRef { projection: &place_ref.projection[..elem.0], ..place_ref }, - ) - .deref(bx.cx()) + ); + + // 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() { + let ptr = cg_base.extract_field(bx, 0).extract_field(bx, 0); + + ptr.deref(bx.cx()) + } else { + cg_base.deref(bx.cx()) + } } else { bug!("using operand local {:?} as place", place_ref); } |
