[Bug fortran/101814] New: Initialization of local variables broken in presence of SAVE
anlauf at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Aug 7 18:28:09 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101814
Bug ID: 101814
Summary: Initialization of local variables broken in presence
of SAVE
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: anlauf at gcc dot gnu.org
Target Milestone: ---
While working on PR68568, I realized that using initialization of local
variables using -finit-local-zero, -finit-integer=nnn etc. rejects
valid code in the presence of a SAVE statement.
% cat zz1.f90
subroutine s1(n)
integer, intent(in) :: n
character(len=n) :: x
save
x = 'a'
end
% gfc-12 -c zz1.f90 -finit-local-zero
zz1.f90:1:13:
1 | subroutine s1(n)
| 1
Error: non-constant initialization expression at (1)
% cat zz2.f90
subroutine s2(n)
integer, intent(in) :: n
integer :: y(n)
save
y = 1
end
% gfc-12 -c zz2.f90 -finit-local-zero
zz2.f90:3:29:
3 | integer :: y(n)
| 1
Error: Automatic array 'y' at (1) cannot have an initializer
% cat zz3.f90
subroutine s1(n)
integer, intent(in) :: n
character(len=n) :: x(n)
save
x = 'a'
end
% gfc-12 -c zz3.f90 -finit-local-zero
zz3.f90:3:29:
3 | character(len=n) :: x(n)
| 1
Error: Automatic array 'x' at (1) cannot have an initializer
Commenting out the SAVE statements or removing -finit* allows the code
to compile.
Both error messages are bogus, and the code is valid:
F2018: 8.6.14 SAVE statement
(1) (...) A SAVE statement without a saved entity list is treated as though
it contained the names of all allowed items in the same scoping unit.
As automatic objects are not allowed items they should be ignored by the SAVE
and its presence should not make any difference.
More information about the Gcc-bugs
mailing list