[flang-commits] [flang] 38c85a4 - [flang] Do not query type_desc for unlimited polymoprhic entities in move_alloc

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Mon Mar 6 08:57:21 PST 2023


Author: Valentin Clement
Date: 2023-03-06T17:57:02+01:00
New Revision: 38c85a419605417b818bc017aff734ab2f2007f5

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

LOG: [flang] Do not query type_desc for unlimited polymoprhic entities in move_alloc

In D144997, the dynamic type of polymorphic entities is reset to the declared
type when the FROM is deallocated. To do this, the declared type was passed as
a fir.type_desc op. For unlimited polymorphic entities, this should just be a
null pointer.

Reviewed By: PeteSteinfeld

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

Added: 
    

Modified: 
    flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp
    flang/test/Lower/polymorphic.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp
index 221d32b9490f9..c05d66230f401 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp
@@ -24,7 +24,8 @@ mlir::Value fir::runtime::genMoveAlloc(fir::FirOpBuilder &builder,
   mlir::Value sourceLine{
       fir::factory::locationToLineNo(builder, loc, fTy.getInput(6))};
   mlir::Value declaredTypeDesc;
-  if (fir::isPolymorphicType(from.getType())) {
+  if (fir::isPolymorphicType(from.getType()) &&
+      !fir::isUnlimitedPolymorphicType(from.getType())) {
     fir::ClassType clTy =
         fir::dyn_cast_ptrEleTy(from.getType()).dyn_cast<fir::ClassType>();
     mlir::Type derivedType = fir::unwrapInnerType(clTy.getEleTy());

diff  --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90
index 04613a7b848c3..bbd1ef7e35760 100644
--- a/flang/test/Lower/polymorphic.f90
+++ b/flang/test/Lower/polymorphic.f90
@@ -1025,6 +1025,19 @@ subroutine test_parent_comp_in_select_type(s)
 ! CHECK:  %[[RHS_CONV:.*]] = fir.convert %[[LOAD_P]] : (!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none>
 ! CHECK:  %{{.*}} = fir.call @_FortranAAssign(%[[LHS_CONV]], %[[RHS_CONV]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none
 
+  subroutine move_alloc_unlimited_poly(a, b)
+    class(*), allocatable :: a, b
+
+    call move_alloc(a, b)
+  end subroutine
+
+! CHECK-LABEL: func.func @_QMpolymorphic_testPmove_alloc_unlimited_poly(
+! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.class<!fir.heap<none>>> {fir.bindc_name = "a"}, %[[B:.*]]: !fir.ref<!fir.class<!fir.heap<none>>> {fir.bindc_name = "b"}) {
+! CHECK: %[[NULL:.*]] = fir.zero_bits !fir.ref<none>
+! CHECK: %[[B_CONV:.*]] = fir.convert %[[B]] : (!fir.ref<!fir.class<!fir.heap<none>>>) -> !fir.ref<!fir.box<none>>
+! CHECK: %[[A_CONV:.*]] = fir.convert %[[A]] : (!fir.ref<!fir.class<!fir.heap<none>>>) -> !fir.ref<!fir.box<none>>
+! CHECK: %{{.*}} = fir.call @_FortranAMoveAlloc(%[[B_CONV]], %[[A_CONV]], %[[NULL]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.ref<!fir.box<none>>, !fir.ref<none>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32
+
 end module
 
 program test


        


More information about the flang-commits mailing list