[Bug fortran/62309] New: -fno-automatic with -finit-local prevents initialization of automatics in recursive functions
fritzoreese at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Aug 29 20:08:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62309
Bug ID: 62309
Summary: -fno-automatic with -finit-local prevents
initialization of automatics in recursive functions
Product: gcc
Version: 4.8.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: fritzoreese at gmail dot com
It seems with gcc-4.8.3 -fno-automatic prevents initializers from being applied
to automatic variables. The following does not behave as I would expect it to
with (linux-x86-64):
function f (x)
implicit none
integer f, x
integer a ! should be SAVEd from -fno-automatic
a = a + x ! should increment by y every time
f = a
return
endfunction
recursive function g (x)
implicit none
integer g, x
integer b ! should be automatic from recursive
b = b + x ! should be set to y every time
g = b
return
endfunction
implicit none
integer f, g
! Should return static value of a; accumulates x
print *, f(3) ! -> 3, ok
print *, f(4) ! -> 7, ok
print *, f(2) ! -> 2, ok
! Should return automatic value of c; equal to y each time
print *, g(3) ! -> garbage, expected 3
print *, g(4) ! -> garbage, expected 4
print *, g(2) ! -> garbage, expected 2
end
$ gfortran -fno-automatic -finit-local-zero auto_test.f
$ ./a.out
3
7
9
32770
32771
32769
$
According to gfortran's manual page, -fno-automatic should "Treat each program
unit (except those marked as RECURSIVE) as if the "SAVE" statement were
specified for every local variable [...]". As far as I can tell,
-finit-local-zero should still initialize automatic variables in RECURSIVE
functions.
More information about the Gcc-bugs
mailing list