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

            Bug ID: 64120
           Summary: [F03] Wrong handling of allocatable character string
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fxcoudert at gcc dot gnu.org

The following code shows allocatable character does not work as it should:

   call g(1)
contains
  subroutine g(x)
      integer :: x
      character(len=x), allocatable :: s
      allocate(s)
      write(*,*) x, len(s)
  end subroutine
end


It should output "1 1" but outputs "1 0". The tree dump shows that the argument
x is never used in the string allocation.


A longer testcase, including SAVE (which seems also mishandled, but it is
probably linked to this issue):

program test
   logical :: L
   L = g(1)
   write(*,*) L
   L = g(2)
   write(*,*) L
contains
  logical function g(x)
      integer :: x
      character(len=x), allocatable :: s
      save
      if(.NOT.allocated(s)) then
        allocate(s)
        g = .FALSE.
      else
        g = .TRUE.
      end if
      write(*,*) len(s)
  end function g
end

Reply via email to