https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102390
Bug ID: 102390 Summary: IMPLICIT SAVE not properly implemented 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 pr102366, it became clear that we do not properly handle some situations where the Fortran standard requires variables to be IMPLICIT SAVE. F2018 8.5.16 SAVE attribute (4) A variable, common block, or procedure pointer declared in the scoping unit of a main program, module, or submodule implicitly has the SAVE attribute, which may be confirmed by explicit specification. If a common block has the SAVE attribute in any other kind of scoping unit, it shall have the SAVE attribute in every scoping unit that is not of a main program, module, or submodule. There is code in decl.c:match_attr_spec that attempts to handle this for modules and submodules. However, the program real(kind=4) :: a(10) a=1.0 end fails to place array a in static memory (for default values of option -fmax-stack-var-size). As long as there is no program statement, we do not have the proper context to set IMPLICIT_SAVE. But even with a program statement the current gfortran will place a in static memory unless one sets e.g. -fmax-stack-var-size=1 . For standard conforming code and -std=f2018 (or earlier) this needs fixing.