aboutsummaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorValentin Clement <clementval@gmail.com>2022-10-07 14:22:36 +0200
committerValentin Clement <clementval@gmail.com>2022-10-07 14:23:27 +0200
commit551a242ceefea90f014edf68919b2015ddfdc103 (patch)
tree216a69d5c3c79777c5188e71c412c1e8c9cdfb6c /flang
parent39db5e1ed87363a9ffea81e53520b542201b3262 (diff)
downloadllvm-551a242ceefea90f014edf68919b2015ddfdc103.zip
llvm-551a242ceefea90f014edf68919b2015ddfdc103.tar.gz
llvm-551a242ceefea90f014edf68919b2015ddfdc103.tar.bz2
[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
Diffstat (limited to 'flang')
-rw-r--r--flang/include/flang/Optimizer/Dialect/FIRTypes.td4
-rw-r--r--flang/test/Lower/polymorphic.f9030
2 files changed, 32 insertions, 2 deletions
diff --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index b63d76c..8fc4f53c 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 0000000..03e917b
--- /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