This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -fno-automatic option (PR 20592)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]