[flang-commits] [flang] 0d7e4d0 - [flang] Deallocate polymorphic and unlimited polymorphic intent(out) allocatable with runtime

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Oct 5 07:37:55 PDT 2022


Author: Valentin Clement
Date: 2022-10-05T16:07:12+02:00
New Revision: 0d7e4d099e9b04da588a73e8d4c441a79ed7c5b5

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

LOG: [flang] Deallocate polymorphic and unlimited polymorphic intent(out) allocatable with runtime

Polymorphic and unlimited polymorphic entities should be handled by runtime. This patch
update the condition in `genDeallocate` to force polymorphic and unlimited polymorphic entities
to be deallocated through a runtime call and not inlined.

Depends on D135143

Reviewed By: jeanPerier, PeteSteinfeld

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

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Builder/BoxValue.h
    flang/lib/Lower/Allocatable.cpp
    flang/test/Lower/polymorphic-types.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Builder/BoxValue.h b/flang/include/flang/Optimizer/Builder/BoxValue.h
index 988c8e34970fa..0764e62dc8dfc 100644
--- a/flang/include/flang/Optimizer/Builder/BoxValue.h
+++ b/flang/include/flang/Optimizer/Builder/BoxValue.h
@@ -250,9 +250,12 @@ class AbstractIrBox : public AbstractBox, public AbstractArrayBox {
     return fir::isRecordWithTypeParameters(getEleTy());
   }
 
-  /// Is this a CLASS(*)/TYPE(*) ?
+  /// Is this a polymorphic entity?
+  bool isPolymorphic() const { return fir::isPolymorphicType(getBoxTy()); }
+
+  /// Is this a CLASS(*)/TYPE(*)?
   bool isUnlimitedPolymorphic() const {
-    return fir::isUnlimitedPolymorphicType(getBaseTy());
+    return fir::isUnlimitedPolymorphicType(getBoxTy());
   }
 };
 

diff  --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp
index 8d0db01f9388d..5fe4dfad32c75 100644
--- a/flang/lib/Lower/Allocatable.cpp
+++ b/flang/lib/Lower/Allocatable.cpp
@@ -511,7 +511,9 @@ static void genDeallocate(fir::FirOpBuilder &builder, mlir::Location loc,
                           const fir::MutableBoxValue &box,
                           ErrorManager &errorManager) {
   // Deallocate intrinsic types inline.
-  if (!box.isDerived() && !errorManager.hasStatSpec() && !useAllocateRuntime) {
+  if (!box.isDerived() && !box.isPolymorphic() &&
+      !box.isUnlimitedPolymorphic() && !errorManager.hasStatSpec() &&
+      !useAllocateRuntime) {
     fir::factory::genInlinedDeallocate(builder, loc, box);
     return;
   }

diff  --git a/flang/test/Lower/polymorphic-types.f90 b/flang/test/Lower/polymorphic-types.f90
index 49175ec564f53..bc4f34e300703 100644
--- a/flang/test/Lower/polymorphic-types.f90
+++ b/flang/test/Lower/polymorphic-types.f90
@@ -98,6 +98,15 @@ subroutine unlimited_polymorphic_pointer(p)
 ! CHECK-LABEL: func.func @_QMpolymorphic_typesPunlimited_polymorphic_pointer(
 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.class<!fir.ptr<none>>>
 
+  subroutine unlimited_polymorphic_allocatable_intentout(p)
+    class(*), allocatable, intent(out) :: p
+  end subroutine
+
+! CHECK-LABEL: func.func @_QMpolymorphic_typesPunlimited_polymorphic_allocatable_intentout(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.class<!fir.heap<none>>>
+! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.ref<!fir.class<!fir.heap<none>>>) -> !fir.ref<!fir.box<none>>
+! CHECK: %{{.*}} = fir.call @_FortranAAllocatableDeallocate(%[[BOX_NONE]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) : (!fir.ref<!fir.box<none>>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32
+
 ! ------------------------------------------------------------------------------
 ! Test polymorphic function return types
 ! ------------------------------------------------------------------------------


        


More information about the flang-commits mailing list