Skip to content

Commit 0a86f9c

Browse files
committed
[flang] Support polymorphic inputs for CSHIFT intrinsic
Result must carry the polymorphic type information from the array. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D143649
1 parent 079c488 commit 0a86f9c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

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

28352835
// Create mutable fir.box to be passed to the runtime for the result.
28362836
mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, arrayRank);
2837-
fir::MutableBoxValue resultMutableBox =
2838-
fir::factory::createTempMutableBox(builder, loc, resultArrayType);
2837+
fir::MutableBoxValue resultMutableBox = fir::factory::createTempMutableBox(
2838+
builder, loc, resultArrayType, {},
2839+
fir::isPolymorphicType(array.getType()) ? array : mlir::Value{});
28392840
mlir::Value resultIrBox =
28402841
fir::factory::getMutableIRBox(builder, loc, resultMutableBox);
28412842

flang/test/Lower/polymorphic-temp.f90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,24 @@ subroutine test_temp_from_unpack(v, m, f)
121121
! CHECK: %[[F_BOX_NONE:.*]] = fir.convert %[[F]] : (!fir.class<!fir.array<?x?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>) -> !fir.box<none>
122122
! 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
123123

124+
subroutine check_cshift(r)
125+
class(p1) :: r(:)
126+
end subroutine
127+
128+
subroutine test_temp_from_intrinsic_cshift(a, shift)
129+
class(p1), intent(in) :: a(20)
130+
integer :: shift
131+
132+
call check_pack(cshift(a, shift))
133+
end subroutine
134+
135+
! CHECK-LABEL: func.func @_QMpoly_tmpPtest_temp_from_intrinsic_cshift(
136+
! CHECK-SAME: %[[ARRAY:.*]]: !fir.class<!fir.array<20x!fir.type<_QMpoly_tmpTp1{a:i32}>>> {fir.bindc_name = "a"}, %[[SHIFT:.*]]: !fir.ref<i32> {fir.bindc_name = "shift"}) {
137+
! CHECK: %[[TMP_RES:.*]] = fir.alloca !fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>>
138+
! CHECK: %[[LOAD_SHIFT:.*]] = fir.load %[[SHIFT]] : !fir.ref<i32>
139+
! CHECK: %[[RES_BOX_NONE:.*]] = fir.convert %[[TMP_RES]] : (!fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpoly_tmpTp1{a:i32}>>>>>) -> !fir.ref<!fir.box<none>>
140+
! CHECK: %[[ARRAY_NONE:.*]] = fir.convert %[[ARRAY]] : (!fir.class<!fir.array<20x!fir.type<_QMpoly_tmpTp1{a:i32}>>>) -> !fir.box<none>
141+
! CHECK: %[[SHIFT_I64:.*]] = fir.convert %[[LOAD_SHIFT]] : (i32) -> i64
142+
! CHECK: %{{.*}} = fir.call @_FortranACshiftVector(%[[RES_BOX_NONE]], %[[ARRAY_NONE]], %[[SHIFT_I64]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, i64, !fir.ref<i8>, i32) -> none
143+
124144
end module

0 commit comments

Comments
 (0)