diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -2720,8 +2720,14 @@ builder.create(loc, argTy, box, mlir::Value{}, /*slice=*/mlir::Value{}); } + } else if (Fortran::lower::isParentComponent(*expr)) { + fir::ExtendedValue newExv = + Fortran::lower::updateBoxForParentComponent(converter, box, + *expr); + box = fir::getBase(newExv); } } + caller.placeInput(arg, box); } } else if (arg.passBy == PassBy::AddressAndLength) { diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -1055,6 +1055,18 @@ ! CHECK: %[[BOX_NONE_ARG1:.*]] = fir.convert %[[REBOX_ARG1]] : (!fir.box>) -> !fir.box ! CHECK: %{{.*}} = fir.call @_FortranASameTypeAs(%[[BOX_NONE_ARG0]], %[[BOX_NONE_ARG1]]) {{.*}} : (!fir.box, !fir.box) -> i1 + subroutine test_parent_comp_normal(a) + class(p2) :: a + + call print(a%p1) + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_parent_comp_normal( +! CHECK-SAME: %[[ARG0:.*]]: !fir.class> {fir.bindc_name = "a"}) { +! CHECK: %[[REBOX:.*]] = fir.rebox %[[ARG0]] : (!fir.class>) -> !fir.box> +! CHECK: %[[CONV:.*]] = fir.convert %[[REBOX]] : (!fir.box>) -> !fir.class> +! CHECK: fir.call @_QMpolymorphic_testPprint(%[[CONV]]) {{.*}} : (!fir.class>) -> () + end module program test