diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp index 0832f101d4bb2..d26eb278069bb 100644 --- a/flang/lib/Lower/CallInterface.cpp +++ b/flang/lib/Lower/CallInterface.cpp @@ -251,7 +251,8 @@ void Fortran::lower::CallerInterface::walkResultLengths( if (std::optional length = dynamicType.GetCharLength()) visitor(toEvExpr(*length)); - } else if (dynamicType.category() == common::TypeCategory::Derived) { + } else if (dynamicType.category() == common::TypeCategory::Derived && + !dynamicType.IsUnlimitedPolymorphic()) { const Fortran::semantics::DerivedTypeSpec &derivedTypeSpec = dynamicType.GetDerivedTypeSpec(); if (Fortran::semantics::CountLenParameters(derivedTypeSpec) > 0) diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90 index dadde2c5eac89..3d25bbd4e2685 100644 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -99,4 +99,21 @@ subroutine polymorphic_to_nonpolymorphic(p) ! CHECK-LABEL: func.func @_QMpolymorphic_testPpolymorphic_to_nonpolymorphic ! Just checking that FIR is generated without error. +! Test that lowering does not crash for function return with unlimited +! polymoprhic value. + + function up_ret() + class(*), pointer :: up_ret(:) + end function + +! CHECK-LABEL: func.func @_QMpolymorphic_testPup_ret() -> !fir.class>> { + + subroutine call_up_ret() + class(*), pointer :: p(:) + p => up_ret() + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPcall_up_ret() { +! CHECK: %{{.*}} = fir.call @_QMpolymorphic_testPup_ret() {{.*}} : () -> !fir.class>> + end module