diff --git a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp index 8104e53920c27..4636cc05421a1 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp @@ -126,8 +126,9 @@ class AssignOpConversion : public mlir::OpRewritePattern { // assignment is the copy of the contents, because the dynamic // types of the LHS and the RHS must match already. We use the // runtime in this case so that the polymorphic (including - // unlimited) content is copied properly. - (lhs.isPolymorphic() && assignOp.isTemporaryLHS())) { + // unlimited) content is copied properly. This is also needed + // for unlimited polymorphic arrays in WHERE statements. + (lhs.isPolymorphic())) { // Use the runtime for simplicity. An optimization pass will be added to // inline array assignment when profitable. mlir::Value from = emboxRHS(rhsExv); diff --git a/flang/test/HLFIR/unlimited-polymorphic-where-construct.f90 b/flang/test/HLFIR/unlimited-polymorphic-where-construct.f90 new file mode 100644 index 0000000000000..8fdcfaca4e612 --- /dev/null +++ b/flang/test/HLFIR/unlimited-polymorphic-where-construct.f90 @@ -0,0 +1,25 @@ +! RUN: flang -fc1 -emit-hlfir %s -o - | FileCheck %s + +module m1 + type x + end type x + logical,parameter::t=.true.,f=.false. + logical::mask(3)=[t,f,t] +end module m1 + +subroutine s1 + use m1 + class(*),allocatable::v(:),u(:) + allocate(x::v(3)) + allocate(x::u(3)) + where(mask) + u=v + end where +! CHECK: hlfir.region_assign +! CHECK: !fir.ref>>> +end subroutine s1 + +program main + call s1 + print *,'pass' +end program main