public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90)
@ 2020-12-16  3:29 xiao.liu@compiler-dev.com
  2020-12-16 20:32 ` [Bug fortran/98307] " anlauf at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: xiao.liu@compiler-dev.com @ 2020-12-16  3:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98307

            Bug ID: 98307
           Summary: use "allocatable" instead of "pointer" (forall_3.f90)
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xiao.liu@compiler-dev.com
  Target Milestone: ---

in the test case "gfortran.fortran-torture/execute/forall_3.f90", if replace
"pointer" with "allocatable", the result will be different.

program evil_forall
  implicit none
  type t
    logical valid
    integer :: s
    !integer, dimension(:), pointer :: p
    integer, dimension(:), allocatable :: p
  end type
  type (t), dimension (5) :: v
  integer i

  allocate (v(1)%p(2))
  allocate (v(2)%p(8))
  !v(3)%p => NULL()
  allocate (v(4)%p(8))
  allocate (v(5)%p(2))

  v(:)%valid = (/.true., .true., .false., .true., .true./)
  v(:)%s = (/1, 8, 999, 6, 2/)
  v(1)%p(:) = (/9, 10/)
  v(2)%p(:) = (/1, 2, 3, 4, 5, 6, 7, 8/)
  v(4)%p(:) = (/13, 14, 15, 16, 17, 18, 19, 20/)
  v(5)%p(:) = (/11, 12/)


  forall (i=1:5,v(i)%valid)
    v(i)%p(1:v(i)%s) = v(6-i)%p(1:v(i)%s)
  end forall

  if (any(v(1)%p(:) .ne. (/11, 10/))) STOP 1
  if (any(v(2)%p(:) .ne. (/13, 14, 15, 16, 17, 18, 19, 20/))) STOP 2
  if (any(v(4)%p(:) .ne. (/1, 2, 3, 4, 5, 6, 19, 20/))) STOP 3
  if (any(v(5)%p(:) .ne. (/9, 10/))) STOP 4

  ! I should really free the memory I've allocated.
end program

the result is "STOP 3"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/98307] use "allocatable" instead of "pointer" (forall_3.f90)
  2020-12-16  3:29 [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90) xiao.liu@compiler-dev.com
@ 2020-12-16 20:32 ` anlauf at gcc dot gnu.org
  2020-12-16 20:46 ` [Bug fortran/98307] Dependency check fails when using " anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-12-16 20:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98307

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org
      Known to fail|                            |10.2.1, 11.0, 8.4.1, 9.3.1
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |wrong-code
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-12-16

--- Comment #1 from anlauf at gcc dot gnu.org ---
Confirmed.

Enforcing the creation of a temporary in the forall fixes the issue.
Something is missing in the logic of check_forall_dependencies().

Reduced testcase:

program evil_forall
  implicit none
  type t
    logical :: valid = .true.
    integer :: s     = 0
    !integer, dimension(:), pointer :: p
    integer, dimension(:), 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)%valid)
  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(:) .ne. (/1, 2, 3, 4, 5, 6, 19, 20/))) stop 1
end program

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/98307] Dependency check fails when using "allocatable" instead of "pointer" (forall_3.f90)
  2020-12-16  3:29 [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90) xiao.liu@compiler-dev.com
  2020-12-16 20:32 ` [Bug fortran/98307] " anlauf at gcc dot gnu.org
@ 2020-12-16 20:46 ` anlauf at gcc dot gnu.org
  2020-12-16 21:13 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-12-16 20:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98307

--- Comment #2 from anlauf at gcc dot gnu.org ---
I'm regtesting the following patch candidate:

diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index adc6b8fefb5..e35b2f9ed34 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -3951,7 +3951,8 @@ check_forall_dependencies (gfc_code *c, stmtblock_t *pre,
stmtblock_t *post)
      pointer components.  We therefore leave these to their
      own devices.  */
   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;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/98307] Dependency check fails when using "allocatable" instead of "pointer" (forall_3.f90)
  2020-12-16  3:29 [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90) xiao.liu@compiler-dev.com
  2020-12-16 20:32 ` [Bug fortran/98307] " anlauf at gcc dot gnu.org
  2020-12-16 20:46 ` [Bug fortran/98307] Dependency check fails when using " anlauf at gcc dot gnu.org
@ 2020-12-16 21:13 ` anlauf at gcc dot gnu.org
  2020-12-17  9:32 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-12-16 21:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98307

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |anlauf at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from anlauf at gcc dot gnu.org ---
Patch: https://gcc.gnu.org/pipermail/fortran/2020-December/055430.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/98307] Dependency check fails when using "allocatable" instead of "pointer" (forall_3.f90)
  2020-12-16  3:29 [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90) xiao.liu@compiler-dev.com
                   ` (2 preceding siblings ...)
  2020-12-16 21:13 ` anlauf at gcc dot gnu.org
@ 2020-12-17  9:32 ` cvs-commit at gcc dot gnu.org
  2020-12-19 20:22 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-17  9:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98307

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:c09deceb534b82ce144af3a345dcb06ab5e49ba4

commit r11-6193-gc09deceb534b82ce144af3a345dcb06ab5e49ba4
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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/98307] Dependency check fails when using "allocatable" instead of "pointer" (forall_3.f90)
  2020-12-16  3:29 [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90) xiao.liu@compiler-dev.com
                   ` (3 preceding siblings ...)
  2020-12-17  9:32 ` cvs-commit at gcc dot gnu.org
@ 2020-12-19 20:22 ` cvs-commit at gcc dot gnu.org
  2020-12-23 19:54 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-19 20:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98307

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

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)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/98307] Dependency check fails when using "allocatable" instead of "pointer" (forall_3.f90)
  2020-12-16  3:29 [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90) xiao.liu@compiler-dev.com
                   ` (4 preceding siblings ...)
  2020-12-19 20:22 ` cvs-commit at gcc dot gnu.org
@ 2020-12-23 19:54 ` cvs-commit at gcc dot gnu.org
  2020-12-23 20:14 ` cvs-commit at gcc dot gnu.org
  2020-12-23 20:17 ` anlauf at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-23 19:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98307

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:ea8d2c77e11b7a27d29e2a438536dcd203c206a9

commit r9-9127-gea8d2c77e11b7a27d29e2a438536dcd203c206a9
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)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/98307] Dependency check fails when using "allocatable" instead of "pointer" (forall_3.f90)
  2020-12-16  3:29 [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90) xiao.liu@compiler-dev.com
                   ` (5 preceding siblings ...)
  2020-12-23 19:54 ` cvs-commit at gcc dot gnu.org
@ 2020-12-23 20:14 ` cvs-commit at gcc dot gnu.org
  2020-12-23 20:17 ` anlauf at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-23 20:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98307

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-8 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:75de7b2ace83028afa46bdb9a286d66ce1fa26b8

commit r8-10692-g75de7b2ace83028afa46bdb9a286d66ce1fa26b8
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)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/98307] Dependency check fails when using "allocatable" instead of "pointer" (forall_3.f90)
  2020-12-16  3:29 [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90) xiao.liu@compiler-dev.com
                   ` (6 preceding siblings ...)
  2020-12-23 20:14 ` cvs-commit at gcc dot gnu.org
@ 2020-12-23 20:17 ` anlauf at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-12-23 20:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98307

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #8 from anlauf at gcc dot gnu.org ---
Fixed on master for gcc-11, and backported to all open branches.  Closing.

Thanks for the report!

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-23 20:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16  3:29 [Bug fortran/98307] New: use "allocatable" instead of "pointer" (forall_3.f90) xiao.liu@compiler-dev.com
2020-12-16 20:32 ` [Bug fortran/98307] " anlauf at gcc dot gnu.org
2020-12-16 20:46 ` [Bug fortran/98307] Dependency check fails when using " anlauf at gcc dot gnu.org
2020-12-16 21:13 ` anlauf at gcc dot gnu.org
2020-12-17  9:32 ` cvs-commit at gcc dot gnu.org
2020-12-19 20:22 ` cvs-commit at gcc dot gnu.org
2020-12-23 19:54 ` cvs-commit at gcc dot gnu.org
2020-12-23 20:14 ` cvs-commit at gcc dot gnu.org
2020-12-23 20:17 ` anlauf at gcc dot gnu.org

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).