diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -1197,7 +1197,7 @@ if (fir::unwrapSequenceType(fieldType).isa()) return false; // Allocatable components need deep copy. - if (auto boxType = fieldType.dyn_cast()) + if (auto boxType = fieldType.dyn_cast()) if (boxType.getEleTy().isa()) return false; } diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -49,6 +49,10 @@ integer :: d end type + type :: p4 + class(p1), allocatable :: a(:) + end type + contains elemental subroutine assign_p1_int(lhs, rhs) @@ -951,6 +955,21 @@ ! CHECK: %[[RES_NONE:.*]] = fir.convert %[[LOAD_RES]] : (!fir.class>>) -> !fir.box ! CHECK: %{{.*}} = fir.call @_FortranAAssign(%[[A_NONE]], %[[RES_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.box, !fir.ref, i32) -> none + subroutine type_with_polymorphic_components(a, b) + type(p4) :: a, b + a = b + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPtype_with_polymorphic_components( +! CHECK-SAME: %[[A:.*]]: !fir.ref>>>}>> {fir.bindc_name = "a"}, %[[B:.*]]: !fir.ref>>>}>> {fir.bindc_name = "b"}) { +! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.box>>>}>> +! CHECK: %[[EMBOX_A:.*]] = fir.embox %[[A]] : (!fir.ref>>>}>>) -> !fir.box>>>}>> +! CHECK: %[[EMBOX_B:.*]] = fir.embox %[[B]] : (!fir.ref>>>}>>) -> !fir.box>>>}>> +! CHECK: fir.store %[[EMBOX_A]] to %[[ALLOCA]] : !fir.ref>>>}>>> +! CHECK: %[[BOX_NONE1:.*]] = fir.convert %[[ALLOCA]] : (!fir.ref>>>}>>>) -> !fir.ref> +! CHECK: %[[BOX_NONE2:.*]] = fir.convert %[[EMBOX_B]] : (!fir.box>>>}>>) -> !fir.box +! CHECK: %{{.*}} = fir.call @_FortranAAssign(%[[BOX_NONE1]], %[[BOX_NONE2]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.box, !fir.ref, i32) -> none + end module program test