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

--- Comment #9 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to Francois-Xavier Coudert from comment #0)
> 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

What is the expected result in the second case? That both the allocation and
the string length be saved? Or should the string length be updated to 'x' with
every call? At the moment, the latter is implemented but the former would be no
problem.

Paul

Reply via email to