This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: -fno-automatic option (PR 20592)
- From: Paul Brook <paul at codesourcery dot com>
- To: fortran at gcc dot gnu dot org
- Cc: François-Xavier Coudert <fxcoudert at gmail dot com>,"Tobias dot Schlueter at physik dot uni-muenchen dot de" <Tobias dot Schlueter at physik dot uni-muenchen dot de>,patch <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 31 Aug 2005 15:27:01 +0100
- Subject: Re: -fno-automatic option (PR 20592)
- References: <19c433eb05083104192d8250b9@mail.gmail.com> <1125489673.43159c09bf78a@www.cip.physik.uni-muenchen.de> <19c433eb0508310538c25f2b9@mail.gmail.com>
On Wednesday 31 August 2005 13:38, François-Xavier Coudert wrote:
> > I think your patch is right. Probably noone ever investigated how this
> > could be done. Consider a complete patch pre-approved, given that the
> > option handling itself will be straightforward to implement.
This option should not apply to RECURSIVE functions. It's ok for non-recursive
functions because it's just making undefined behaviour implementation
defined. However for RECURSIVE functions it breaks legal programs.
Testcase at the end of this mail.
> +Treat each program unit as if the @code{SAVE} statement was specified for
> +every local variable and array referenced in it. Does not affect common
> +blocks. (Some Fortran compilers provide this option under the name
> +@option{-static}.)
This isn't entirely accurate. It's the equivalent of adding a single "save"
statement with no saved-entity-list. This is different because it only
applies to "all allowed items in the same scoping unit" (Section 5.2.4). In
particular it does not apply to automatic (aka variable size) objects. eg.
subroutine foo(n)
integer n
integer, dimension(n) :: a
save
a = 0;
end subroutine
"a" will not be given the SAVE attribute.
> +fautomatic
> +F95
> +Do not treat local variables and COMMON blocks as if they were named in
> SAVE statements
Maybe better to say something like
"Allows local variables to be placed on the stack."
Even with -fautomatic the compiler may choose to makes some variables SAVEd.
Paul
! { dg-do run }
! { dg-options "-fno-automatic" }
! Check that -fno-automatic doesn't break recursive functions.
program recursive_1
integer n
if (foo(2) .ne. 2) call abort
contains
recursive function foo(n) result (res)
integer res, n, i, a;
i = n
if (i .gt. 0) then
a = foo(i - 1)
if (a .ne. i - 1) call abort
end if
res = i;
end function
end program