diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index 16dced798296e..cc01e49854a23 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -4930,7 +4930,8 @@ IntrinsicLibrary::genTransfer(mlir::Type resultType, ? resultType : builder.getVarLenSeqTy(resultType, 1); fir::MutableBoxValue resultMutableBox = - fir::factory::createTempMutableBox(builder, loc, type); + fir::factory::createTempMutableBox(builder, loc, type, {}, + fir::isPolymorphicType(mold.getType()) ? mold : mlir::Value{}); if (moldRank == 0 && absentSize) { // This result is a scalar in this case. diff --git a/flang/test/Lower/polymorphic-temp.f90 b/flang/test/Lower/polymorphic-temp.f90 index 71ea397118767..7858c9563fc1f 100644 --- a/flang/test/Lower/polymorphic-temp.f90 +++ b/flang/test/Lower/polymorphic-temp.f90 @@ -80,14 +80,14 @@ subroutine test_temp_from_intrinsic_reshape(i) ! CHECK: %[[RES_BOX_NONE:.*]] = fir.convert %[[LOAD_RES]] : (!fir.class>>) -> !fir.box ! CHECK: %{{.*}} = fir.call @_FortranAAllocatableApplyMold(%[[A_BOX_NONE]], %[[RES_BOX_NONE]], %[[RANK]]) {{.*}} : (!fir.ref>, !fir.box, i32) -> none - subroutine check_pack(r) + subroutine check(r) class(p1) :: r(:) end subroutine subroutine test_temp_from_intrinsic_pack(i, mask) class(p1), intent(in) :: i(20, 20) logical, intent(in) :: mask(20, 20) - call check_pack(pack(i, mask)) + call check(pack(i, mask)) end subroutine ! CHECK-LABEL: func.func @_QMpoly_tmpPtest_temp_from_intrinsic_pack( @@ -163,4 +163,18 @@ subroutine test_temp_from_intrinsic_eoshift(a, shift, b) ! CHECK: %[[BOUNDARY_NONE:.*]] = fir.convert %[[BOUNDARY]] : (!fir.class>) -> !fir.box ! CHECK: %{{.*}} = fir.call @_FortranAEoshiftVector(%[[RES_BOX_NONE]], %[[ARRAY_NONE]], %[[SHIFT_I64]], %[[BOUNDARY_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.box, i64, !fir.box, !fir.ref, i32) -> none + subroutine test_temp_from_intrinsic_transfer(source, mold) + class(p1), intent(in) :: source(:) + class(p1), intent(in) :: mold(:) + call check(transfer(source, mold)) + end subroutine + +! CHECK-LABEL: func.func @_QMpoly_tmpPtest_temp_from_intrinsic_transfer( +! CHECK-SAME: %[[SOURCE:.*]]: !fir.class>> {fir.bindc_name = "source"}, %[[MOLD:.*]]: !fir.class>> {fir.bindc_name = "mold"}) { +! CHECK: %[[TMP_RES:.*]] = fir.alloca !fir.class>>> +! CHECK: %[[RES_BOX_NONE:.*]] = fir.convert %[[TMP_RES]] : (!fir.ref>>>>) -> !fir.ref> +! CHECK: %[[SOURCE_NONE:.*]] = fir.convert %[[SOURCE]] : (!fir.class>>) -> !fir.box +! CHECK: %[[MOLD_NONE:.*]] = fir.convert %[[MOLD]] : (!fir.class>>) -> !fir.box +! CHECK: %{{.*}} = fir.call @_FortranATransfer(%[[RES_BOX_NONE]], %[[SOURCE_NONE]], %[[MOLD_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.box, !fir.box, !fir.ref, i32) -> none + end module