diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -1872,6 +1872,8 @@ mlir::Type genType(const Fortran::evaluate::DynamicType &dt) { if (dt.category() != Fortran::common::TypeCategory::Derived) return converter.genType(dt.category(), dt.kind()); + if (dt.IsUnlimitedPolymorphic()) + return mlir::NoneType::get(&converter.getMLIRContext()); return converter.genType(dt.GetDerivedTypeSpec()); } 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 @@ -722,6 +722,22 @@ ! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[LOAD_P]] : (!fir.class>>) -> !fir.box ! CHECK: %{{.*}} = fir.call @_FortranAioInputDescriptor(%{{.*}}, %[[BOX_NONE]]) {{.*}} : (!fir.ref, !fir.box) -> i1 + function unlimited_polymorphic_alloc_array_ret() + class(*), allocatable :: unlimited_polymorphic_alloc_array_ret(:) + end function + + subroutine test_unlimited_polymorphic_alloc_array_ret() + select type (a => unlimited_polymorphic_alloc_array_ret()) + type is (real) + print*, 'type is real' + end select + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_unlimited_polymorphic_alloc_array_ret() { +! CHECK: %[[RES_TMP:.*]] = fir.alloca !fir.class>> {bindc_name = ".result"} +! CHECK: %[[RES:.*]] = fir.call @_QMpolymorphic_testPunlimited_polymorphic_alloc_array_ret() fastmath : () -> !fir.class>> +! CHECK: fir.save_result %[[RES]] to %[[RES_TMP]] : !fir.class>>, !fir.ref>>> + end module program test