public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-9160] PR fortran/98307 - Dependency check fails when using "allocatable"
Date: Sat, 19 Dec 2020 20:22:13 +0000 (GMT)	[thread overview]
Message-ID: <20201219202213.6D16C3858C27@sourceware.org> (raw)

https://gcc.gnu.org/g:4e9563cda3f841f26f2ad1d9961dd6ffc9f39146

commit r10-9160-g4e9563cda3f841f26f2ad1d9961dd6ffc9f39146
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Dec 17 10:31:55 2020 +0100

    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.
    
    (cherry picked from commit c09deceb534b82ce144af3a345dcb06ab5e49ba4)

Diff:
---
 gcc/fortran/trans-stmt.c                |  5 +++--
 gcc/testsuite/gfortran.dg/forall_19.f90 | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 54b56c4f01d..2b0192e6ae5 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -3921,9 +3921,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


                 reply	other threads:[~2020-12-19 20:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201219202213.6D16C3858C27@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).