The following program:

MODULE m
  IMPLICIT NONE
  INTEGER, TARGET :: arr(3)

CONTAINS

  SUBROUTINE foobar (arg)
    INTEGER, TARGET :: arg(:)

    arr(2:3) = arg(1:2)
  END SUBROUTINE foobar

END MODULE m

PROGRAM main
  USE :: m
  IMPLICIT NONE

  arr = (/ 1, 2, 3 /)
  CALL foobar (arr)
  PRINT *, arr
END PROGRAM main

does not create a temporary array inside foobar and prints "1 1 1", while I
think it should print "1 1 2".

In the Fortran 2008 standard, 12.5.2.13, 3b):

(3) Action that affects the value of the entity or any subobject of it shall be
taken only through the dummy argument unless
a) ... or
b) the dummy argument has the TARGET attribute, the dummy argument does not
have INTENT(IN), the dummy argument is a scalar object or an assumed-shape
array without the CONTIGUOUS attribute, and the actual argument is a target
other than an array section with a vector subscript.

It seems to me that this allows the code above.


-- 
           Summary: Aliasing of TARGET dummy argument not detected correctly
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: domob at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45019

Reply via email to