! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s ! Tests the different possible type involving polymorphic entities. module polymorphic_types type p1 integer :: a integer :: b contains procedure :: polymorphic_dummy end type contains ! ------------------------------------------------------------------------------ ! Test polymorphic entity types ! ------------------------------------------------------------------------------ subroutine polymorphic_dummy(p) class(p1) :: p end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPpolymorphic_dummy( ! CHECK-SAME: %{{.*}}: !fir.class> subroutine polymorphic_dummy_assumed_shape_array(pa) class(p1) :: pa(:) end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPpolymorphic_dummy_assumed_shape_array( ! CHECK-SAME: %{{.*}}: !fir.class>> subroutine polymorphic_dummy_explicit_shape_array(pa) class(p1) :: pa(10) end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPpolymorphic_dummy_explicit_shape_array( ! CHECK-SAME: %{{.*}}: !fir.class>> subroutine polymorphic_allocatable(p) class(p1), allocatable :: p end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPpolymorphic_allocatable( ! CHECK-SAME: %{{.*}}: !fir.ref>>> subroutine polymorphic_pointer(p) class(p1), pointer :: p end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPpolymorphic_pointer( ! CHECK-SAME: %{{.*}}: !fir.ref>>> subroutine polymorphic_allocatable_intentout(p) class(p1), allocatable, intent(out) :: p end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPpolymorphic_allocatable_intentout( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>>> ! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.ref>>>) -> !fir.ref> ! CHECK: %{{.*}} = fir.call @_FortranAAllocatableDeallocatePolymorphic(%[[BOX_NONE]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 ! ------------------------------------------------------------------------------ ! Test unlimited polymorphic dummy argument types ! ------------------------------------------------------------------------------ subroutine unlimited_polymorphic_dummy(u) class(*) :: u end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPunlimited_polymorphic_dummy( ! CHECK-SAME: %{{.*}}: !fir.class subroutine unlimited_polymorphic_assumed_shape_array(ua) class(*) :: ua(:) end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPunlimited_polymorphic_assumed_shape_array( ! CHECK-SAME: %{{.*}}: !fir.class> subroutine unlimited_polymorphic_explicit_shape_array(ua) class(*) :: ua(20) end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPunlimited_polymorphic_explicit_shape_array( ! CHECK-SAME: %{{.*}}: !fir.class> subroutine unlimited_polymorphic_allocatable(p) class(*), allocatable :: p end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPunlimited_polymorphic_allocatable( ! CHECK-SAME: %{{.*}}: !fir.ref>> subroutine unlimited_polymorphic_pointer(p) class(*), pointer :: p end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPunlimited_polymorphic_pointer( ! CHECK-SAME: %{{.*}}: !fir.ref>> subroutine unlimited_polymorphic_allocatable_intentout(p) class(*), allocatable, intent(out) :: p end subroutine ! CHECK-LABEL: func.func @_QMpolymorphic_typesPunlimited_polymorphic_allocatable_intentout( ! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>> ! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.ref>>) -> !fir.ref> ! CHECK: %{{.*}} = fir.call @_FortranAAllocatableDeallocatePolymorphic(%[[BOX_NONE]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref>, !fir.ref, i1, !fir.box, !fir.ref, i32) -> i32 ! ------------------------------------------------------------------------------ ! Test polymorphic function return types ! ------------------------------------------------------------------------------ function ret_polymorphic_allocatable() result(ret) class(p1), allocatable :: ret end function ! CHECK-LABEL: func.func @_QMpolymorphic_typesPret_polymorphic_allocatable() -> !fir.class>> ! CHECK: %[[MEM:.*]] = fir.alloca !fir.class>> {bindc_name = "ret", uniq_name = "_QMpolymorphic_typesFret_polymorphic_allocatableEret"} ! CHECK: %[[ZERO:.*]] = fir.zero_bits !fir.heap> ! CHECK: %[[BOX:.*]] = fir.embox %[[ZERO]] : (!fir.heap>) -> !fir.class>> ! CHECK: fir.store %[[BOX]] to %[[MEM]] : !fir.ref>>> ! CHECK: %[[LOAD:.*]] = fir.load %[[MEM]] : !fir.ref>>> ! CHECK: return %[[LOAD]] : !fir.class>> function ret_polymorphic_pointer() result(ret) class(p1), pointer :: ret end function ! CHECK-LABEL: func.func @_QMpolymorphic_typesPret_polymorphic_pointer() -> !fir.class>> ! CHECK: %[[MEM:.*]] = fir.alloca !fir.class>> {bindc_name = "ret", uniq_name = "_QMpolymorphic_typesFret_polymorphic_pointerEret"} ! CHECK: %[[ZERO:.*]] = fir.zero_bits !fir.ptr> ! CHECK: %[[BOX:.*]] = fir.embox %[[ZERO]] : (!fir.ptr>) -> !fir.class>> ! CHECK: fir.store %[[BOX]] to %[[MEM]] : !fir.ref>>> ! CHECK: %[[LOAD:.*]] = fir.load %[[MEM]] : !fir.ref>>> ! CHECK: return %[[LOAD]] : !fir.class>> ! ------------------------------------------------------------------------------ ! Test unlimited polymorphic function return types ! ------------------------------------------------------------------------------ function ret_unlimited_polymorphic_allocatable() result(ret) class(*), allocatable :: ret end function ! CHECK-LABEL: func.func @_QMpolymorphic_typesPret_unlimited_polymorphic_allocatable() -> !fir.class> ! CHECK: %[[MEM:.*]] = fir.alloca !fir.class> {bindc_name = "ret", uniq_name = "_QMpolymorphic_typesFret_unlimited_polymorphic_allocatableEret"} ! CHECK: %[[ZERO:.*]] = fir.zero_bits !fir.heap ! CHECK: %[[BOX:.*]] = fir.embox %[[ZERO]] : (!fir.heap) -> !fir.class> ! CHECK: fir.store %[[BOX]] to %[[MEM]] : !fir.ref>> ! CHECK: %[[LOAD:.*]] = fir.load %[[MEM]] : !fir.ref>> ! CHECK: return %[[LOAD]] : !fir.class> function ret_unlimited_polymorphic_pointer() result(ret) class(*), pointer :: ret end function ! CHECK-LABEL: func.func @_QMpolymorphic_typesPret_unlimited_polymorphic_pointer() -> !fir.class> ! CHECK: %[[MEM:.*]] = fir.alloca !fir.class> {bindc_name = "ret", uniq_name = "_QMpolymorphic_typesFret_unlimited_polymorphic_pointerEret"} ! CHECK: %[[ZERO:.*]] = fir.zero_bits !fir.ptr ! CHECK: %[[BOX:.*]] = fir.embox %[[ZERO]] : (!fir.ptr) -> !fir.class> ! CHECK: fir.store %[[BOX]] to %[[MEM]] : !fir.ref>> ! CHECK: %[[LOAD:.*]] = fir.load %[[MEM]] : !fir.ref>> ! CHECK: return %[[LOAD]] : !fir.class> ! ------------------------------------------------------------------------------ ! Test assumed type argument types ! ------------------------------------------------------------------------------ subroutine assumed_type_dummy(a) bind(c) type(*) :: a end subroutine assumed_type_dummy ! CHECK-LABEL: func.func @assumed_type_dummy( ! CHECK-SAME: %{{.*}}: !fir.ref subroutine assumed_type_dummy_array(a) bind(c) type(*) :: a(:) end subroutine assumed_type_dummy_array ! CHECK-LABEL: func.func @assumed_type_dummy_array( ! CHECK-SAME: %{{.*}}: !fir.box> end module