Skip to content

Commit c58af72

Browse files
committed
Add additional extract_field / project_field to take into account extra level of struct nesting.
1 parent 2a91eea commit c58af72

File tree

1 file changed

+6
-2
lines changed
  • compiler/rustc_codegen_ssa/src/mir

1 file changed

+6
-2
lines changed

compiler/rustc_codegen_ssa/src/mir/place.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
448448

449449
// a box with a non-zst allocator should not be directly dereferenced
450450
if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 1).is_zst() {
451-
let ptr = cg_base.extract_field(bx, 0).extract_field(bx, 0);
451+
// Extract `Box<T>` -> `Unique<T>` -> `NonNull<T>` -> `*const T`
452+
let ptr =
453+
cg_base.extract_field(bx, 0).extract_field(bx, 0).extract_field(bx, 0);
452454

453455
ptr.deref(bx.cx())
454456
} else {
@@ -464,7 +466,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
464466
mir::ProjectionElem::Deref => {
465467
// a box with a non-zst allocator should not be directly dereferenced
466468
if cg_base.layout.ty.is_box() && !cg_base.layout.field(cx, 1).is_zst() {
467-
let ptr = cg_base.project_field(bx, 0).project_field(bx, 0);
469+
// Project `Box<T>` -> `Unique<T>` -> `NonNull<T>` -> `*const T`
470+
let ptr =
471+
cg_base.project_field(bx, 0).project_field(bx, 0).project_field(bx, 0);
468472

469473
bx.load_operand(ptr).deref(bx.cx())
470474
} else {

0 commit comments

Comments
 (0)