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 @@ -1153,10 +1153,11 @@ fromCoor, indices); } if (auto fieldEleTy = fir::unwrapSequenceType(lFieldTy); - fieldEleTy.isa()) { - assert( - fieldEleTy.cast().getEleTy().isa() && - "allocatable members require deep copy"); + fieldEleTy.isa()) { + assert(fieldEleTy.cast() + .getEleTy() + .isa() && + "allocatable members require deep copy"); auto fromPointerValue = builder.create(loc, fromCoor); auto castTo = builder.createConvert(loc, fieldEleTy, fromPointerValue); builder.create(loc, castTo, toCoor); @@ -1201,8 +1202,8 @@ // Box operands may be polymorphic, it is not entirely clear from 10.2.1.3 // if the assignment is performed on the dynamic of declared type. Use the // runtime assuming it is performed on the dynamic type. - bool hasBoxOperands = fir::getBase(lhs).getType().isa() || - fir::getBase(rhs).getType().isa(); + bool hasBoxOperands = fir::getBase(lhs).getType().isa() || + fir::getBase(rhs).getType().isa(); auto recTy = baseTy.dyn_cast(); assert(recTy && "must be a record type"); if (hasBoxOperands || !recordTypeCanBeMemCopied(recTy)) { 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 @@ -24,6 +24,10 @@ procedure :: get_tmp end type + type p3 + class(p3), pointer :: p(:) + end type + contains ! Test correct access to polymorphic entity component. @@ -182,4 +186,10 @@ ! CHECK: %[[REBOX:.*]] = fir.rebox %[[CLASS]] : (!fir.class>>>) -> !fir.box>> ! CHECK: fir.call @_QMpolymorphic_testPsub_with_type_array(%[[REBOX]]) {{.*}} : (!fir.box>>) -> () + subroutine derived_type_assignment_with_class() + type(p3) :: a + type(p3), target :: b(10) + a = p3(b) + end subroutine + end module