Skip to content

Commit 6b77f3f

Browse files
committed
gccrs: Fix field access on DST fat pointers
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit (FieldAccessExpr)): Handle DST fat pointers by reinterpreting the fat pointer as its field type. Signed-Off-By: Yap Zhi Heng <yapzhhg@gmail.com>
1 parent d31b74d commit 6b77f3f

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

gcc/rust/backend/rust-compile-expr.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,21 @@ CompileExpr::visit (HIR::FieldAccessExpr &expr)
717717
nullptr, &field_index);
718718
rust_assert (ok);
719719

720-
tree indirect = indirect_expression (receiver_ref, expr.get_locus ());
721-
receiver_ref = indirect;
720+
if (RS_DST_FLAG_P (TREE_TYPE (receiver_ref)))
721+
{
722+
const TyTy::StructFieldType *field
723+
= variant->get_field_at_index (field_index);
724+
tree field_type
725+
= TyTyResolveCompile::compile (ctx, field->get_field_type ());
726+
translated = fold_build1_loc (expr.get_locus (), VIEW_CONVERT_EXPR,
727+
field_type, receiver_ref);
728+
return;
729+
}
730+
else
731+
{
732+
tree indirect = indirect_expression (receiver_ref, expr.get_locus ());
733+
receiver_ref = indirect;
734+
}
722735
}
723736

724737
translated = Backend::struct_field_expression (receiver_ref, field_index,

0 commit comments

Comments
 (0)