[flang-commits] [flang] [Flang] Fix handling of unlimited polymorphic arrays (PR #159624)
via flang-commits
flang-commits at lists.llvm.org
Fri Sep 19 08:22:14 PDT 2025
================
@@ -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
----------------
jeanPerier wrote:
Tricky case. Your fix implies that the LHS and RHS dynamic type is the same at runtime to work properly. I do not know what is the standard required behavior here....
In, assignment-stmt polymorphic LHS are required to be allocatable in F2023 10.2.1.2 (1) so that the LHS can be reallocated to the RHS dynamic type if it is not the same.
But here, inside a masked assignment, the reallocation logic is not really specified. Lowering is not generating it because the LHS/RHS shapes are supposed to match already.
I do think it would be cleaner to forbid assignments to whole polymorphic allocatables inside WHERE statements.
Section 10.2.3 does not really say anything about it allocatable assignements inside WHERE statements, and especially in the case of polymorphic LHS, this opens the doors to many interpretation/behaviors.
@klausler, what do you think? Should this case be clarified with the J3?
https://github.com/llvm/llvm-project/pull/159624
More information about the flang-commits
mailing list