diff --git a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp --- a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp @@ -24,7 +24,8 @@ mlir::Value sourceLine{ fir::factory::locationToLineNo(builder, loc, fTy.getInput(6))}; mlir::Value declaredTypeDesc; - if (fir::isPolymorphicType(from.getType())) { + if (fir::isPolymorphicType(from.getType()) && + !fir::isUnlimitedPolymorphicType(from.getType())) { fir::ClassType clTy = fir::dyn_cast_ptrEleTy(from.getType()).dyn_cast(); mlir::Type derivedType = fir::unwrapInnerType(clTy.getEleTy()); diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -1001,6 +1001,19 @@ ! CHECK: %[[TYPE_DESC_CONV:.*]] = fir.convert %[[TYPE_DESC]] : (!fir.tdesc>) -> !fir.ref ! CHECK: %{{.*}} = fir.call @_FortranAMoveAlloc(%[[B_CONV]], %[[A_CONV]], %[[TYPE_DESC_CONV]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 + subroutine move_alloc_unlimited_poly(a, b) + class(*), allocatable :: a, b + + call move_alloc(a, b) + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPmove_alloc_unlimited_poly( +! CHECK-SAME: %[[A:.*]]: !fir.ref>> {fir.bindc_name = "a"}, %[[B:.*]]: !fir.ref>> {fir.bindc_name = "b"}) { +! CHECK: %[[NULL:.*]] = fir.zero_bits !fir.ref +! CHECK: %[[B_CONV:.*]] = fir.convert %[[B]] : (!fir.ref>>) -> !fir.ref> +! CHECK: %[[A_CONV:.*]] = fir.convert %[[A]] : (!fir.ref>>) -> !fir.ref> +! CHECK: %{{.*}} = fir.call @_FortranAMoveAlloc(%[[B_CONV]], %[[A_CONV]], %[[NULL]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 + end module program test