[flang-commits] [flang] fe20692 - [flang] Allow fir.class as fir.save_result operand #0

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Mon Nov 7 09:23:49 PST 2022


Author: Valentin Clement
Date: 2022-11-07T18:23:43+01:00
New Revision: fe2069284d10f78c6472f5934983c5740dea8039

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

LOG: [flang] Allow fir.class as fir.save_result operand #0

Reviewed By: jeanPerier, PeteSteinfeld

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index 0d06e1d118ea7..eaf43a6e908aa 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -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">;
 
 

diff  --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90
index 232dfada79194..d828c0c209349 100644
--- a/flang/test/Lower/polymorphic.f90
+++ b/flang/test/Lower/polymorphic.f90
@@ -58,4 +58,22 @@ subroutine test_allocate_unlimited_polymorphic_non_derived()
 ! 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


        


More information about the flang-commits mailing list