diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp --- a/flang/lib/Lower/CallInterface.cpp +++ b/flang/lib/Lower/CallInterface.cpp @@ -251,7 +251,8 @@ 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 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -99,4 +99,21 @@ ! 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