[flang] Allow fir.class as fir.save_result operand #0
authorValentin Clement <clementval@gmail.com>
Mon, 7 Nov 2022 17:23:22 +0000 (18:23 +0100)
committerValentin Clement <clementval@gmail.com>
Mon, 7 Nov 2022 17:23:43 +0000 (18:23 +0100)
Reviewed By: jeanPerier, PeteSteinfeld

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

flang/include/flang/Optimizer/Dialect/FIRTypes.td
flang/test/Lower/polymorphic.f90

index 0d06e1d..eaf43a6 100644 (file)
@@ -635,7 +635,7 @@ def AnyAddressableLike : TypeConstraint<Or<[fir_ReferenceType.predicate,
     FunctionType.predicate]>, "any addressable">;
 
 def ArrayOrBoxOrRecord : TypeConstraint<Or<[fir_SequenceType.predicate,
-    fir_BoxType.predicate, fir_RecordType.predicate]>,
+    IsBaseBoxTypePred, fir_RecordType.predicate]>,
     "fir.box, fir.array or fir.type">;
 
 
index 232dfad..d828c0c 100644 (file)
@@ -58,4 +58,22 @@ module polymorphic_test
 ! CHECK-LABEL: test_allocate_unlimited_polymorphic_non_derived
 ! CHECK-NOT: _FortranAPointerNullifyDerived
 ! CHECK: fir.call @_FortranAPointerAllocate
+
+  function test_fct_ret_class()
+    class(p1), pointer :: test_fct_ret_class
+  end function
+
+  subroutine call_fct()
+    class(p1), pointer :: p
+    p => test_fct_ret_class()
+  end subroutine
+
+! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_fct_ret_class() -> !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>
+! CHECK: return %{{.*}} : !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>
+
+! CHECK-lABEL: func.func @_QMpolymorphic_testPcall_fct()
+! CHECK: %[[RESULT:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {bindc_name = ".result"}
+! CHECK: %[[CALL_RES:.*]] = fir.call @_QMpolymorphic_testPtest_fct_ret_class() : () -> !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>
+! CHECK: fir.save_result %[[CALL_RES]] to %[[RESULT]] : !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>
+
 end module