public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Dominique d'Humières" <dominiq@lps.ens.fr>
To: Paul Richard Thomas <paul.richard.thomas@gmail.com>
Cc: gfortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, Fortran] PR 37835 -fno-automatic does not work for derived types with default initalizer
Date: Fri, 18 Jan 2019 17:43:00 -0000	[thread overview]
Message-ID: <49BC4E41-05B8-40A4-8F1E-4DDB12D645AE@lps.ens.fr> (raw)

[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

Hi all!

The patch for gcc/fortran/resolve.c is the modernized version of Paul’s patch in comment 4.
It causes some regressions due to "Duplicate SAVE » warnings. 
They are silenced by the patch for gcc/fortran/symbol.c unless -pedantic is used as documented
in the change for gcc/fortran/invoke.texi.

Is it OK for trunk?

TIA

Dominique

2019-01-18  Dominique d'Humieres  <dominiq@gcc.gnu.org>

	PR fortran/37835
	* resolve.c (resolve_types): Add !flag_automatic.
	* symbol.c (gfc_add_save): Silence warnings.

2019-01-18  Dominique d'Humieres  <dominiq@gcc.gnu.org>

	PR fortran/37835
	* gfortran.dg/no-automatic.f90: New test.


[-- Attachment #2: patch-37835 --]
[-- Type: application/octet-stream, Size: 2076 bytes --]

diff -up ../_clean/gcc/fortran/resolve.c gcc/fortran/resolve.c
--- ../_clean/gcc/fortran/resolve.c	2019-01-15 23:24:11.000000000 +0100
+++ gcc/fortran/resolve.c	2019-01-17 11:45:32.000000000 +0100
@@ -16669,7 +16669,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 -up ../_clean/gcc/fortran/symbol.c gcc/fortran/symbol.c
--- ../_clean/gcc/fortran/symbol.c	2019-01-09 22:54:02.000000000 +0100
+++ gcc/fortran/symbol.c	2019-01-17 11:47:57.000000000 +0100
@@ -1306,7 +1306,8 @@ gfc_add_save (symbol_attribute *attr, sa
   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",
--- ../_clean/gcc/testsuite/gfortran.dg/no-automatic.f90	1970-01-01 01:00:00.000000000 +0100
+++ gcc/testsuite/gfortran.dg/no-automatic.f90	2019-01-16 17:34:49.000000000 +0100
@@ -0,0 +1,20 @@
+! { dg-do run }
+! { dg-options "-fno-automatic" }
+!
+! PR fortran/37835
+! Contributed by Tobias Burnus <burnus@gcc.gnu.org>.
+!
+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
--- ../_clean/gcc/fortran/invoke.texi	2019-01-09 22:54:02.000000000 +0100
+++ gcc/fortran/invoke.texi	2019-01-18 11:33:25.000000000 +0100
@@ -1377,6 +1377,9 @@ The default, which is @option{-fautomati
 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

             reply	other threads:[~2019-01-18 17:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-18 17:43 Dominique d'Humières [this message]
2019-01-19 15:50 ` Thomas Koenig
2019-01-19 21:56   ` Dominique d'Humières

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49BC4E41-05B8-40A4-8F1E-4DDB12D645AE@lps.ens.fr \
    --to=dominiq@lps.ens.fr \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=paul.richard.thomas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).