[flang-commits] [flang] 551a242 - [flang] Allow fir.class in AnyRefOrBox

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Fri Oct 7 05:23:38 PDT 2022


Author: Valentin Clement
Date: 2022-10-07T14:23:27+02:00
New Revision: 551a242ceefea90f014edf68919b2015ddfdc103

URL: https://github.com/llvm/llvm-project/commit/551a242ceefea90f014edf68919b2015ddfdc103
DIFF: https://github.com/llvm/llvm-project/commit/551a242ceefea90f014edf68919b2015ddfdc103.diff

LOG: [flang] Allow fir.class in AnyRefOrBox

Some operations are using `AnyRefOrBox` to specify the type of the
operands or attribute. This is the case for the `fir.coordinate_of`
operation. This patch updates the `AnyRefOrBox` to accept `BaseBoxType`
instead of only `BoxType`.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D135442

Added: 
    flang/test/Lower/polymorphic.f90

Modified: 
    flang/include/flang/Optimizer/Dialect/FIRTypes.td

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index b63d76cc3ff06..8fc4f53cd2eac 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -610,8 +610,8 @@ def AnyRefOrBoxLike : TypeConstraint<Or<[AnyReferenceLike.predicate,
     AnyBoxLike.predicate, FunctionType.predicate]>,
     "any reference or box like">;
 def AnyRefOrBox : TypeConstraint<Or<[fir_ReferenceType.predicate,
-    fir_HeapType.predicate, fir_PointerType.predicate, fir_BoxType.predicate]>,
-    "any reference or box">;
+    fir_HeapType.predicate, fir_PointerType.predicate,
+    IsBaseBoxTypePred]>, "any reference or box">;
 
 def AnyShapeLike : TypeConstraint<Or<[fir_ShapeType.predicate,
     fir_ShapeShiftType.predicate]>, "any legal shape type">;

diff  --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90
new file mode 100644
index 0000000000000..03e917b82f177
--- /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.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {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.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.field) -> !fir.ref<i32>
+! CHECK: %[[LOAD:.*]] = fir.load %[[COORD]] : !fir.ref<i32>
+! CHECK: %{{.*}} = fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[LOAD]]) : (!fir.ref<i8>, i32) -> i1
+
+end module


        


More information about the flang-commits mailing list