Skip to content

Commit b5bffb7

Browse files
committed
[flang] Support polymorphic inputs for UNPACK intrinsic
Result must carry the polymorphic type information from the vector. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D143575
1 parent a9d6a86 commit b5bffb7

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5073,8 +5073,9 @@ IntrinsicLibrary::genUnpack(mlir::Type resultType,
50735073

50745074
// Create mutable fir.box to be passed to the runtime for the result.
50755075
mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, maskRank);
5076-
fir::MutableBoxValue resultMutableBox =
5077-
fir::factory::createTempMutableBox(builder, loc, resultArrayType);
5076+
fir::MutableBoxValue resultMutableBox = fir::factory::createTempMutableBox(
5077+
builder, loc, resultArrayType, {},
5078+
fir::isPolymorphicType(vector.getType()) ? vector : mlir::Value{});
50785079
mlir::Value resultIrBox =
50795080
fir::factory::getMutableIRBox(builder, loc, resultMutableBox);
50805081

flang/test/Lower/polymorphic-temp.f90

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,23 @@ subroutine test_temp_from_intrinsic_pack(i, mask)
102102
! CHECK: %[[MASK_BOX_NONE:.*]] = fir.convert %[[EMBOXED_MASK]] : (!fir.box<!fir.array<20x20x!fir.logical<4>>>) -> !fir.box<none>
103103
! CHECK: %{{.*}} = fir.call @_FortranAPack(%[[RES_BOX_NONE]], %[[I_BOX_NONE]], %[[MASK_BOX_NONE]], %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> none
104104

105+
subroutine check_unpack(r)
106+
class(p1), intent(in) :: r(:,:)
107+
end subroutine
108+
109+
subroutine test_temp_from_unpack(v, m, f)
110+
class(p1), intent(in) :: v(:), f(:,:)
111+
logical, intent(in) :: m(:,:)
112+
call check_unpack(unpack(v,m,f))
113+
end subroutine
114+
115+
! CHECK-LABEL: func.func @_QMpoly_tmpPtest_temp_from_unpack(
116+
! CHECK-SAME: %[[V:.*]]: !fir.class<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>> {fir.bindc_name = "v"}, %[[M:.*]]: !fir.box<!fir.array<?x?x!fir.logical<4>>> {fir.bindc_name = "m"}, %[[F:.*]]: !fir.class<!fir.array<?x?x!fir.type<_QMpoly_tmpTp1{a:i32}>>> {fir.bindc_name = "f"}) {
117+
! CHECK: %[[TMP_RES:.*]] = fir.alloca !fir.class<!fir.heap<!fir.array<?x?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>>
118+
! CHECK: %[[TMP_BOX_NONE:.*]] = fir.convert %[[TMP_RES]] : (!fir.ref<!fir.class<!fir.heap<!fir.array<?x?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>>>) -> !fir.ref<!fir.box<none>>
119+
! CHECK: %[[V_BOX_NONE:.*]] = fir.convert %[[V]] : (!fir.class<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>) -> !fir.box<none>
120+
! CHECK: %[[M_BOX_NONE:.*]] = fir.convert %[[M]] : (!fir.box<!fir.array<?x?x!fir.logical<4>>>) -> !fir.box<none>
121+
! CHECK: %[[F_BOX_NONE:.*]] = fir.convert %[[F]] : (!fir.class<!fir.array<?x?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>) -> !fir.box<none>
122+
! CHECK: %{{.*}} = fir.call @_FortranAUnpack(%[[TMP_BOX_NONE]], %[[V_BOX_NONE]], %[[M_BOX_NONE]], %[[F_BOX_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> none
123+
105124
end module

0 commit comments

Comments
 (0)