diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -3140,6 +3140,14 @@ fir::factory::CharacterExprHelper{*builder, loc}.createAssign( lhs, rhs); } else if (isDerivedCategory(lhsType->category())) { + // Handle parent component. + if (Fortran::lower::isParentComponent(assign.lhs)) { + if (!fir::getBase(lhs).getType().isa()) + lhs = fir::getBase(builder->createBox(loc, lhs)); + lhs = Fortran::lower::updateBoxForParentComponent(*this, lhs, + assign.lhs); + } + // Fortran 2018 10.2.1.3 p13 and p14 // Recursively gen an assignment on each element pair. fir::factory::genRecordAssignment(*builder, loc, lhs, rhs, diff --git a/flang/test/Lower/parent-component.f90 b/flang/test/Lower/parent-component.f90 --- a/flang/test/Lower/parent-component.f90 +++ b/flang/test/Lower/parent-component.f90 @@ -175,4 +175,23 @@ ! CHECK: %[[C1:.*]] = arith.constant 1 : index ! CHECK: %[[SLICE:.*]] = fir.slice %[[C1]], %[[C2]], %[[C1]] path %[[FIELD_C]] : (index, index, index, !fir.field) -> !fir.slice<1> ! CHECK: %{{.*}} = fir.embox %[[ALLOCA]](%[[SHAPE]]) [%[[SLICE]]] : (!fir.ref}>>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box>> + + subroutine parent_comp_lhs() + type(c) :: a + type(p) :: b + + a%p = B + end subroutine + +! CHECK-LABEL: func.func @_QFPparent_comp_lhs() +! CHECK: %[[BOX:.*]] = fir.alloca !fir.box> +! CHECK: %[[A:.*]] = fir.alloca !fir.type<_QFTc{a:i32,b:i32}> {bindc_name = "a", uniq_name = "_QFFparent_comp_lhsEa"} +! CHECK: %[[B:.*]] = fir.alloca !fir.type<_QFTp{a:i32}> {bindc_name = "b", uniq_name = "_QFFparent_comp_lhsEb"} +! CHECK: %[[EMBOX_A:.*]] = fir.embox %[[A]] : (!fir.ref>) -> !fir.box> +! CHECK: %[[EMBOX_B:.*]] = fir.embox %[[B]] : (!fir.ref>) -> !fir.box> +! CHECK: fir.store %[[EMBOX_A]] to %[[BOX]] : !fir.ref>> +! CHECK: %[[A_NONE:.*]] = fir.convert %[[BOX]] : (!fir.ref>>) -> !fir.ref> +! CHECK: %[[B_NONE:.*]] = fir.convert %[[EMBOX_B]] : (!fir.box>) -> !fir.box +! CHECK: %{{.*}} = fir.call @_FortranAAssign(%[[A_NONE]], %[[B_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.box, !fir.ref, i32) -> none + end