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 @@ -5580,7 +5580,7 @@ // value. The value of the box is forwarded in the continuation. mlir::Type reduceTy = reduceRank(arrTy, slice); mlir::Type boxTy = fir::BoxType::get(reduceTy); - if (memref.getType().isa()) + if (memref.getType().isa() && !components.hasComponents()) boxTy = fir::ClassType::get(reduceTy); if (components.substring) { // Adjust char length to substring size. 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 @@ -824,6 +824,20 @@ ! CHECK: } ! CHECK: fir.call @_QMpolymorphic_testPsub_with_poly_array_optional(%[[BOX]]) {{.*}} : (!fir.class>) -> () + subroutine test_poly_array_component_output(p) + class(p1), pointer :: p(:) + print*, p(:)%a + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_poly_array_component_output( +! CHECK-SAME: %[[P]]: !fir.ref>>>> {fir.bindc_name = "p"}) { +! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref>>>> +! CHECK: %[[FIELD_INDEX_A:.*]] = fir.field_index a, !fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}> +! CHECK: %[[SLICE:.*]] = fir.slice %{{.*}}#0, %{{.*}}, %{{.*}} path %[[FIELD_INDEX_A]] : (index, index, index, !fir.field) -> !fir.slice<1> +! CHECK: %[[REBOX:.*]] = fir.rebox %[[LOAD_P]](%{{.*}}) [%[[SLICE]]] : (!fir.class>>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box> +! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[REBOX]] : (!fir.box>) -> !fir.box +! CHECK: %{{.*}} = fir.call @_FortranAioOutputDescriptor(%{{.*}}, %[[BOX_NONE]]) fastmath : (!fir.ref, !fir.box) -> i1 + end module program test