diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp --- a/flang/lib/Lower/Allocatable.cpp +++ b/flang/lib/Lower/Allocatable.cpp @@ -482,6 +482,10 @@ if (!typeSpec) typeSpec = &alloc.type; + // Do not generate calls for non derived-type type spec. + if (!typeSpec->AsDerived()) + return; + assert(typeSpec && "type spec missing for polymorphic allocation"); std::string typeName = Fortran::lower::mangle::mangleName(typeSpec->derivedTypeSpec()); 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 @@ -49,4 +49,13 @@ ! CHECK: %[[BOX2:.*]] = fir.embox %[[DT2]] : (!fir.ref>) -> !fir.class> ! CHECK: %[[CLASS2:.*]] = fir.convert %[[BOX2]] : (!fir.class>) -> !fir.class> ! CHECK: fir.call @_QMpolymorphic_testPprint(%[[CLASS2]]) : (!fir.class>) -> () + + subroutine test_allocate_unlimited_polymorphic_non_derived() + class(*), pointer :: u + allocate(integer::u) + end subroutine + +! CHECK-LABEL: test_allocate_unlimited_polymorphic_non_derived +! CHECK-NOT: _FortranAPointerNullifyDerived +! CHECK: fir.call @_FortranAPointerAllocate end module