diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 6c95a879b24..a6d793c8b66 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-01-19 Dominique d'Humieres + + PR fortran/37835 + * resolve.c (resolve_types): Add !flag_automatic. + * symbol.c (gfc_add_save): Silence warnings. + 2019-01-19 Steven G. Kargl PR fortran/77960 diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 668e8d9bc72..dc7c037f241 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -1377,6 +1377,9 @@ The default, which is @option{-fautomatic}, uses the stack for local variables smaller than the value given by @option{-fmax-stack-var-size}. Use the option @option{-frecursive} to use no static memory. +Local variables or arrays having an explicit @code{SAVE} attribute are +silently ignored unless the @option{-pedantic} option is added. + @item -ff2c @opindex ff2c @cindex calling convention diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 3f893f1f802..2c49aeab5f9 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -16673,7 +16673,7 @@ resolve_types (gfc_namespace *ns) gfc_traverse_ns (ns, resolve_values); - if (ns->save_all) + if (ns->save_all || !flag_automatic) gfc_save_all (ns); iter_stack = NULL; diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c index 06c21d969f2..b7408ac3f21 100644 --- a/gcc/fortran/symbol.c +++ b/gcc/fortran/symbol.c @@ -1306,7 +1306,8 @@ gfc_add_save (symbol_attribute *attr, save_state s, const char *name, if (s == SAVE_EXPLICIT) gfc_unset_implicit_pure (NULL); - if (s == SAVE_EXPLICIT && attr->save == SAVE_EXPLICIT) + if (s == SAVE_EXPLICIT && attr->save == SAVE_EXPLICIT + && (flag_automatic || pedantic)) { if (!gfc_notify_std (GFC_STD_LEGACY, "Duplicate SAVE attribute specified at %L", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f3c66ee318d..ebd599e7810 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-18 Dominique d'Humieres + + PR fortran/37835 + * gfortran.dg/no-automatic.f90: New test. + 2019-01-19 Steven G. Kargl PR fortran/77960 diff --git a/gcc/testsuite/gfortran.dg/no-automatic.f90 b/gcc/testsuite/gfortran.dg/no-automatic.f90 new file mode 100644 index 00000000000..42baf4d2e0c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/no-automatic.f90 @@ -0,0 +1,20 @@ +! { dg-do run } +! { dg-options "-fno-automatic" } +! +! PR fortran/37835 +! Contributed by Tobias Burnus . +! +subroutine foo(n) + integer :: n + type t + integer :: i = 42 + end type t + type(t) :: myt + if(n==1) myt%i = 2 + print *, myt%i + if (n > 1 .and. myt%i /= 2) stop 1 +end subroutine foo + +call foo(1) +call foo(2) +end