[flang-commits] [flang] 62aa19a - [flang] Keep a fir.box type when doing an array of derived type component
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Jan 24 10:45:48 PST 2023
Author: Valentin Clement
Date: 2023-01-24T19:45:33+01:00
New Revision: 62aa19a5a529b972e6e0d92c57ff773daddd22a2
URL: https://github.com/llvm/llvm-project/commit/62aa19a5a529b972e6e0d92c57ff773daddd22a2
DIFF: https://github.com/llvm/llvm-project/commit/62aa19a5a529b972e6e0d92c57ff773daddd22a2.diff
LOG: [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
Added:
Modified:
flang/lib/Lower/ConvertExpr.cpp
flang/test/Lower/polymorphic.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 6c493024bd1cb..499d1ddead4e3 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -5580,7 +5580,7 @@ class ArrayExprLowering {
// 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<fir::ClassType>())
+ if (memref.getType().isa<fir::ClassType>() && !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 fe6ae879c540c..cded60febea33 100644
--- a/flang/test/Lower/polymorphic.f90
+++ b/flang/test/Lower/polymorphic.f90
@@ -839,6 +839,20 @@ subroutine test_poly_pointer_null()
! CHECK: fir.store %[[EMBOX]] to %[[ALLOCA]] : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>
! CHECK: fir.call @_QMpolymorphic_testPpass_poly_pointer_optional(%[[ALLOCA]]) fastmath<contract> : (!fir.ref<!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>) -> ()
+ 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.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>> {fir.bindc_name = "p"}) {
+! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>>
+! 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.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xi32>>
+! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[REBOX]] : (!fir.box<!fir.array<?xi32>>) -> !fir.box<none>
+! CHECK: %{{.*}} = fir.call @_FortranAioOutputDescriptor(%{{.*}}, %[[BOX_NONE]]) fastmath<contract> : (!fir.ref<i8>, !fir.box<none>) -> i1
+
end module
program test
More information about the flang-commits
mailing list