diff --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td --- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td +++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td @@ -635,7 +635,7 @@ FunctionType.predicate]>, "any addressable">; def ArrayOrBoxOrRecord : TypeConstraint, + IsBaseBoxTypePred, fir_RecordType.predicate]>, "fir.box, fir.array or fir.type">; 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 @@ -58,4 +58,22 @@ ! CHECK-LABEL: test_allocate_unlimited_polymorphic_non_derived ! CHECK-NOT: _FortranAPointerNullifyDerived ! CHECK: fir.call @_FortranAPointerAllocate + + function test_fct_ret_class() + class(p1), pointer :: test_fct_ret_class + end function + + subroutine call_fct() + class(p1), pointer :: p + p => test_fct_ret_class() + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_fct_ret_class() -> !fir.class>> +! CHECK: return %{{.*}} : !fir.class>> + +! CHECK-lABEL: func.func @_QMpolymorphic_testPcall_fct() +! CHECK: %[[RESULT:.*]] = fir.alloca !fir.class>> {bindc_name = ".result"} +! CHECK: %[[CALL_RES:.*]] = fir.call @_QMpolymorphic_testPtest_fct_ret_class() : () -> !fir.class>> +! CHECK: fir.save_result %[[CALL_RES]] to %[[RESULT]] : !fir.class>>, !fir.ref>>> + end module