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 @@ -610,8 +610,8 @@ AnyBoxLike.predicate, FunctionType.predicate]>, "any reference or box like">; def AnyRefOrBox : TypeConstraint, - "any reference or box">; + fir_HeapType.predicate, fir_PointerType.predicate, + IsBaseBoxTypePred]>, "any reference or box">; def AnyShapeLike : TypeConstraint, "any legal shape type">; diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/polymorphic.f90 @@ -0,0 +1,30 @@ +! RUN: bbc -polymorphic-type -emit-fir %s -o - | FileCheck %s + +! Tests various aspect of the lowering of polymorphic entities. + +module polymorphic_test + type p1 + integer :: a + integer :: b + end type + + type, extends(p1) :: p2 + real :: c + end type + + contains + + ! Test correct access to polymorphic entity component. + subroutine component_access(p) + class(p1) :: p + print*, p%a + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPcomponent_access( +! CHECK-SAME: %[[P:.*]]: !fir.class> {fir.bindc_name = "p"}) { +! CHECK: %[[FIELD:.*]] = fir.field_index a, !fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}> +! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[P]], %[[FIELD]] : (!fir.class>, !fir.field) -> !fir.ref +! CHECK: %[[LOAD:.*]] = fir.load %[[COORD]] : !fir.ref +! CHECK: %{{.*}} = fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[LOAD]]) : (!fir.ref, i32) -> i1 + +end module