diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -2834,8 +2834,9 @@ // Create mutable fir.box to be passed to the runtime for the result. mlir::Type resultArrayType = builder.getVarLenSeqTy(resultType, arrayRank); - fir::MutableBoxValue resultMutableBox = - fir::factory::createTempMutableBox(builder, loc, resultArrayType); + fir::MutableBoxValue resultMutableBox = fir::factory::createTempMutableBox( + builder, loc, resultArrayType, {}, + fir::isPolymorphicType(array.getType()) ? array : mlir::Value{}); mlir::Value resultIrBox = fir::factory::getMutableIRBox(builder, loc, resultMutableBox); diff --git a/flang/test/Lower/polymorphic-temp.f90 b/flang/test/Lower/polymorphic-temp.f90 --- a/flang/test/Lower/polymorphic-temp.f90 +++ b/flang/test/Lower/polymorphic-temp.f90 @@ -121,4 +121,24 @@ ! CHECK: %[[F_BOX_NONE:.*]] = fir.convert %[[F]] : (!fir.class>>) -> !fir.box ! CHECK: %{{.*}} = fir.call @_FortranAUnpack(%[[TMP_BOX_NONE]], %[[V_BOX_NONE]], %[[M_BOX_NONE]], %[[F_BOX_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> none + subroutine check_cshift(r) + class(p1) :: r(:) + end subroutine + + subroutine test_temp_from_intrinsic_cshift(a, shift) + class(p1), intent(in) :: a(20) + integer :: shift + + call check_pack(cshift(a, shift)) + end subroutine + +! CHECK-LABEL: func.func @_QMpoly_tmpPtest_temp_from_intrinsic_cshift( +! CHECK-SAME: %[[ARRAY:.*]]: !fir.class>> {fir.bindc_name = "a"}, %[[SHIFT:.*]]: !fir.ref {fir.bindc_name = "shift"}) { +! CHECK: %[[TMP_RES:.*]] = fir.alloca !fir.class>>> +! CHECK: %[[LOAD_SHIFT:.*]] = fir.load %[[SHIFT]] : !fir.ref +! CHECK: %[[RES_BOX_NONE:.*]] = fir.convert %[[TMP_RES]] : (!fir.ref>>>>) -> !fir.ref> +! CHECK: %[[ARRAY_NONE:.*]] = fir.convert %[[ARRAY]] : (!fir.class>>) -> !fir.box +! CHECK: %[[SHIFT_I64:.*]] = fir.convert %[[LOAD_SHIFT]] : (i32) -> i64 +! CHECK: %{{.*}} = fir.call @_FortranACshiftVector(%[[RES_BOX_NONE]], %[[ARRAY_NONE]], %[[SHIFT_I64]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.box, i64, !fir.ref, i32) -> none + end module