* [PATCH] PR fortran/98307 - Dependency check fails when using "allocatable"
@ 2020-12-16 21:12 Harald Anlauf
2020-12-17 8:46 ` Thomas Koenig
0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2020-12-16 21:12 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 792 bytes --]
Dear all,
since the introduction of check_forall_dependencies() we mishandled the
dependencies of ALLOCATABLE components of derived types, while POINTER
was dealt with. Fix that.
Regtested on x86_64-pc-linux-gnu.
OK for master? Since we generate wrong code under the given circumstances,
what do people think about backports?
Thanks,
Harald
PR fortran/98307 - Dependency check fails when using "allocatable"
The dependency check for FORALL constructs already handled pointer
components to derived types, but missed allocatables. Fix that.
gcc/fortran/ChangeLog:
PR fortran/98307
* trans-stmt.c (check_forall_dependencies): Extend dependency
check to allocatable components of derived types.
gcc/testsuite/ChangeLog:
PR fortran/98307
* gfortran.dg/forall_19.f90: New test.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr98307.patch --]
[-- Type: text/x-patch, Size: 1860 bytes --]
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index adc6b8fefb5..112a4e8ead9 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -3949,9 +3949,10 @@ check_forall_dependencies (gfc_code *c, stmtblock_t *pre, stmtblock_t *post)
point to the copy instead. Note that the shallow copy of
the variable will not suffice for derived types with
pointer components. We therefore leave these to their
- own devices. */
+ own devices. Likewise for allocatable components. */
if (lsym->ts.type == BT_DERIVED
- && lsym->ts.u.derived->attr.pointer_comp)
+ && (lsym->ts.u.derived->attr.pointer_comp
+ || lsym->ts.u.derived->attr.alloc_comp))
return need_temp;
new_symtree = NULL;
diff --git a/gcc/testsuite/gfortran.dg/forall_19.f90 b/gcc/testsuite/gfortran.dg/forall_19.f90
new file mode 100644
index 00000000000..ef05c97ab24
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/forall_19.f90
@@ -0,0 +1,32 @@
+! { dg-do run }
+! PR fortran/98307 - Dependency check fails when using "allocatable"
+
+program forall_deps
+ implicit none
+ type t
+ logical :: valid = .true.
+ integer :: s = 0
+ integer, allocatable :: p(:)
+ end type
+ type(t) :: v(2)
+ integer :: i
+
+ allocate (v(1)%p(8))
+ allocate (v(2)%p(8))
+ v(1)%s = 8
+ v(2)%s = 6
+
+ v(1)%p(:) = [1, 2, 3, 4, 5, 6, 7, 8]
+ v(2)%p(:) = [13, 14, 15, 16, 17, 18, 19, 20]
+ forall (i=1:2)
+ v(i)%p(1:v(i)%s) = v(3-i)%p(1:v(i)%s)
+ end forall
+ if (any(v(2)%p(:) /= [1, 2, 3, 4, 5, 6, 19, 20])) stop 1
+
+ v(1)%p(:) = [1, 2, 3, 4, 5, 6, 7, 8]
+ v(2)%p(:) = [13, 14, 15, 16, 17, 18, 19, 20]
+ forall (i=1:2, v(i)%valid)
+ v(i)%p(1:v(i)%s) = v(3-i)%p(1:v(i)%s)
+ end forall
+ if (any(v(2)%p(:) /= [1, 2, 3, 4, 5, 6, 19, 20])) stop 2
+end
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-17 8:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16 21:12 [PATCH] PR fortran/98307 - Dependency check fails when using "allocatable" Harald Anlauf
2020-12-17 8:46 ` Thomas Koenig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).