From 62aa19a5a529b972e6e0d92c57ff773daddd22a2 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Tue, 24 Jan 2023 16:37:52 +0100 Subject: [PATCH] [flang] Keep a fir.box type when doing an array of derived type component When referencing a single component from a polymorphic array in an expression, the rebox operation should output a boxed array of that component type and not a polymorphic boxed array as it was done. Reviewed By: PeteSteinfeld Differential Revision: https://reviews.llvm.org/D142462 --- flang/lib/Lower/ConvertExpr.cpp | 2 +- flang/test/Lower/polymorphic.f90 | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp index 6c49302..499d1dd 100644 --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -5580,7 +5580,7 @@ private: // 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 index fe6ae87..cded60f 100644 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -839,6 +839,20 @@ module polymorphic_test ! CHECK: fir.store %[[EMBOX]] to %[[ALLOCA]] : !fir.ref>>> ! CHECK: fir.call @_QMpolymorphic_testPpass_poly_pointer_optional(%[[ALLOCA]]) fastmath : (!fir.ref>>>) -> () + 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 -- 2.7.4