Skip to content

Commit 38c85a4

Browse files
committed
[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
1 parent 30dc037 commit 38c85a4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

flang/lib/Optimizer/Builder/Runtime/Allocatable.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ mlir::Value fir::runtime::genMoveAlloc(fir::FirOpBuilder &builder,
2424
mlir::Value sourceLine{
2525
fir::factory::locationToLineNo(builder, loc, fTy.getInput(6))};
2626
mlir::Value declaredTypeDesc;
27-
if (fir::isPolymorphicType(from.getType())) {
27+
if (fir::isPolymorphicType(from.getType()) &&
28+
!fir::isUnlimitedPolymorphicType(from.getType())) {
2829
fir::ClassType clTy =
2930
fir::dyn_cast_ptrEleTy(from.getType()).dyn_cast<fir::ClassType>();
3031
mlir::Type derivedType = fir::unwrapInnerType(clTy.getEleTy());

flang/test/Lower/polymorphic.f90

+13
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,19 @@ subroutine test_parent_comp_in_select_type(s)
10251025
! CHECK: %[[RHS_CONV:.*]] = fir.convert %[[LOAD_P]] : (!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none>
10261026
! CHECK: %{{.*}} = fir.call @_FortranAAssign(%[[LHS_CONV]], %[[RHS_CONV]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none
10271027

1028+
subroutine move_alloc_unlimited_poly(a, b)
1029+
class(*), allocatable :: a, b
1030+
1031+
call move_alloc(a, b)
1032+
end subroutine
1033+
1034+
! CHECK-LABEL: func.func @_QMpolymorphic_testPmove_alloc_unlimited_poly(
1035+
! 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"}) {
1036+
! CHECK: %[[NULL:.*]] = fir.zero_bits !fir.ref<none>
1037+
! CHECK: %[[B_CONV:.*]] = fir.convert %[[B]] : (!fir.ref<!fir.class<!fir.heap<none>>>) -> !fir.ref<!fir.box<none>>
1038+
! CHECK: %[[A_CONV:.*]] = fir.convert %[[A]] : (!fir.ref<!fir.class<!fir.heap<none>>>) -> !fir.ref<!fir.box<none>>
1039+
! 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
1040+
10281041
end module
10291042

10301043
program test

0 commit comments

Comments
 (0)