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) { @@ -7215,16 +7221,9 @@ // y(:)%t ! just need to update the box with a slice pointing to the first // ! component of `t`. // a%t ! simple conversion to TYPE(t). -<<<<<<< HEAD fir::ExtendedValue Fortran::lower::updateBoxForParentComponent( Fortran::lower::AbstractConverter &converter, fir::ExtendedValue box, const Fortran::lower::SomeExpr &expr) { -======= -fir::ExtendedValue -Fortran::lower::updateBoxForParentComponent(Fortran::lower::AbstractConverter &converter, - fir::ExtendedValue box, - const Fortran::lower::SomeExpr &expr) { ->>>>>>> [flang] Handle parent component in intrinsic function arguments mlir::Location loc = converter.getCurrentLocation(); auto &builder = converter.getFirOpBuilder(); mlir::Value boxBase = fir::getBase(box); 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