Please find attached three slightly different patches based on a patch for PR59107 originally developed by Janus Weil <ja...@gcc.gnu.org> and Dominique d'Humieres <domi...@lps.ens.fr> for gcc-5. The last comment regarding the patch was on 2015-03-21 consequently the code has moved on somewhat and some additional changes where required resulting in 3 slightly different patches.

Tested on x86_64 using make check-fortran.

OK to commit?

Change logs for master:

fortran/ChangeLog:

    Janus Weil <ja...@gcc.gnu.org> and
    Dominique d'Humieres  <domi...@lps.ens.fr>
    Mark Eggleston  <markeggles...@gcc.gnu.org>

    PR59107
    * gfortran.h: Rename field resolved as resolve_symbol_called
    and assign two 2 bits instead of 1.
    * interface.c (check_dtio_interface1): Use new field name.
    (gfc_find_typebound_dtio_proc): Use new field name.
    * resolve.c (gfc_resolve_intrinsic): Replace check of the formal
    field with resolve_symbol_called is at least 2, if it is not
    set the field to 2.  (resolve_typebound_procedure): Use new field
    name.  (resolve_symbol): Use new field name and check whether it
    is at least 1, if it is not set the field to 1.

testsuite/gfortran.dg/ChangeLog:

    Mark Eggleston <markeggles...@gcc.gnu.org>

    PR59107
    * gfortran.dg/pr59107.f90: New test.

The change logs for the back ports for gcc-8 and gcc-9 are included as part of the proposed commit messages at the beginning of the patch files. The back port dates will be updated when known.

--
https://www.codethink.co.uk/privacy.html

>From 5a79cef24594bf8ebfe69394efd382a61f55b0f2 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggles...@gcc.gnu.org>
Date: Thu, 23 Apr 2020 10:33:14 +0100
Subject: [PATCH] Fortran : Spurious warning message with -Wsurprising PR59107

This change is from a patch developed by

Janus Weil  <ja...@gcc.gnu.org> and
Dominique d'Humieres  <domi...@lps.ens.fr>

for gcc-5. The code has moved on since then requiring a change to
interface.c

gcc/fortran/ChangeLog:

	* gfortran.h: Rename field resolved as resolve_symbol_called
	and assign two 2 bits instead of 1.
	* interface.c (check_dtio_interface1): Use new field name.
	(gfc_find_typebound_dtio_proc): Use new field name.
	* resolve.c (gfc_resolve_intrinsic): Replace check of the formal
	field with resolve_symbol_called is at least 2, if it is not
	set the field to 2.  (resolve_typebound_procedure): Use new field
	name.  (resolve_symbol): Use new field name and check whether it
	is at least 1, if it is not set the field to 1.

gcc/testsuite/ChangeLog:

	* gfortran.dg/pr59107.f90: New test.
---
 gcc/fortran/gfortran.h                |  2 +-
 gcc/fortran/interface.c               |  5 +++--
 gcc/fortran/resolve.c                 | 10 ++++++----
 gcc/testsuite/gfortran.dg/pr59107.f90 | 11 +++++++++++
 4 files changed, 21 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr59107.f90

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 4e1da8c88a0..ab9c325a28c 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1621,7 +1621,7 @@ typedef struct gfc_symbol
   /* Set if the symbol is used in a function result specification .  */
   unsigned fn_result_spec:1;
   /* Used to avoid multiple resolutions of a single symbol.  */
-  unsigned resolved:1;
+  unsigned resolve_symbol_called:2;
   /* Set if this is a module function or subroutine with the
      abreviated declaration in a submodule.  */
   unsigned abr_modproc_decl:1;
diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index ba1c8bc322e..f33c6632b45 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -5015,7 +5015,7 @@ check_dtio_interface1 (gfc_symbol *derived, gfc_symtree *tb_io_st,
     gfc_error ("DTIO procedure %qs at %L must be a subroutine",
 	       dtio_sub->name, &dtio_sub->declared_at);
 
-  if (!dtio_sub->resolved)
+  if (!dtio_sub->resolve_symbol_called)
     gfc_resolve_formal_arglist (dtio_sub);
 
   arg_num = 0;
@@ -5149,7 +5149,8 @@ gfc_find_typebound_dtio_proc (gfc_symbol *derived, bool write, bool formatted)
   gfc_symtree *tb_io_st = NULL;
   bool t = false;
 
-  if (!derived || !derived->resolved || derived->attr.flavor != FL_DERIVED)
+  if (!derived || !derived->resolve_symbol_called
+      || derived->attr.flavor != FL_DERIVED)
     return NULL;
 
   /* Try to find a typebound DTIO binding.  */
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index fd3b025a84f..88ba88d8bf3 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -1753,9 +1753,11 @@ gfc_resolve_intrinsic (gfc_symbol *sym, locus *loc)
   gfc_intrinsic_sym* isym = NULL;
   const char* symstd;
 
-  if (sym->formal)
+  if (sym->resolve_symbol_called >= 2)
     return true;
 
+  sym->resolve_symbol_called = 2;
+
   /* Already resolved.  */
   if (sym->from_intmod && sym->ts.type != BT_UNKNOWN)
     return true;
@@ -13909,7 +13911,7 @@ resolve_typebound_procedure (gfc_symtree* stree)
     {
       /* If proc has not been resolved at this point, proc->name may
 	 actually be a USE associated entity. See PR fortran/89647. */
-      if (!proc->resolved
+      if (!proc->resolve_symbol_called
 	  && proc->attr.function == 0 && proc->attr.subroutine == 0)
 	{
 	  gfc_symbol *tmp;
@@ -15154,9 +15156,9 @@ resolve_symbol (gfc_symbol *sym)
   gfc_array_spec *as;
   bool saved_specification_expr;
 
-  if (sym->resolved)
+  if (sym->resolve_symbol_called >= 1)
     return;
-  sym->resolved = 1;
+  sym->resolve_symbol_called = 1;
 
   /* No symbol will ever have union type; only components can be unions.
      Union type declaration symbols have type BT_UNKNOWN but flavor FL_UNION
diff --git a/gcc/testsuite/gfortran.dg/pr59107.f90 b/gcc/testsuite/gfortran.dg/pr59107.f90
new file mode 100644
index 00000000000..a84328f0851
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr59107.f90
@@ -0,0 +1,11 @@
+! { dg-compile }
+! { dg-options "-Wsurprising" }
+
+! There should be no surprising warnings
+
+program p
+  Integer :: nargs
+  intrinsic :: command_argument_count
+  nargs = command_argument_count()
+end
+
-- 
2.11.0

>From 4430cf9394aca0f08892a2cece9118cda1b778e5 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggles...@gcc.gnu.org>
Date: Thu, 23 Apr 2020 14:27:53 +0100
Subject: [PATCH] Fortran : Spurious warning message with -Wsurprising PR59107

This change is from a patch developed by

Janus Weil  <ja...@gcc.gnu.org> and
Dominique d'Humieres  <domi...@lps.ens.fr>

for gcc-5. The code has moved on since then requiring a change to
interface.c

gcc/fortran/ChangeLog:

	Backport from master
	2020-04-??  Mark Eggleston  <markeggles...@gcc.gnu.org>

	PR59107
	* gfortran.h: Rename field resolved as resolve_symbol_called
	and assign two 2 bits instead of 1.
	* interface.c (gfc_find_typebound_dtio_proc): Use new field name.
	* resolve.c (gfc_resolve_intrinsic): Replace check of the formal
	field with resolve_symbol_called is at least 2, if it is not
	set the field to 2.  (resolve_typebound_procedure): Use new field
	name.  (resolve_symbol): Use new field name and check whether it
	is at least 1, if it is not set the field to 1.

gcc/testsuite/ChangeLog:

        Backport from master
	020-04-??  Mark Eggleston  <markeggles...@gcc.gnu.org>

	PR59107
	* gfortran.dg/pr59107.f90: New test.
---
 gcc/fortran/gfortran.h                |  2 +-
 gcc/fortran/interface.c               |  3 ++-
 gcc/fortran/resolve.c                 | 10 ++++++----
 gcc/testsuite/gfortran.dg/pr59107.f90 | 11 +++++++++++
 4 files changed, 20 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr59107.f90

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index d7071ae5fcf..f477d29ecd3 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1602,7 +1602,7 @@ typedef struct gfc_symbol
   /* Set if the symbol is used in a function result specification .  */
   unsigned fn_result_spec:1;
   /* Used to avoid multiple resolutions of a single symbol.  */
-  unsigned resolved:1;
+  unsigned resolve_symbol_called:2;
   /* Set if this is a module function or subroutine with the
      abreviated declaration in a submodule.  */
   unsigned abr_modproc_decl:1;
diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index b5701b1a59a..29af409dde0 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -4979,7 +4979,8 @@ gfc_find_typebound_dtio_proc (gfc_symbol *derived, bool write, bool formatted)
   gfc_symtree *tb_io_st = NULL;
   bool t = false;
 
-  if (!derived || !derived->resolved || derived->attr.flavor != FL_DERIVED)
+  if (!derived || !derived->resolve_symbol_called
+      || derived->attr.flavor != FL_DERIVED)
     return NULL;
 
   /* Try to find a typebound DTIO binding.  */
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index a3df534180c..52d29a42e8e 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -1754,9 +1754,11 @@ gfc_resolve_intrinsic (gfc_symbol *sym, locus *loc)
   gfc_intrinsic_sym* isym = NULL;
   const char* symstd;
 
-  if (sym->formal)
+  if (sym->resolve_symbol_called >= 2)
     return true;
 
+  sym->resolve_symbol_called = 2;
+
   /* Already resolved.  */
   if (sym->from_intmod && sym->ts.type != BT_UNKNOWN)
     return true;
@@ -13541,7 +13543,7 @@ resolve_typebound_procedure (gfc_symtree* stree)
     {
       /* If proc has not been resolved at this point, proc->name may
 	 actually be a USE associated entity. See PR fortran/89647. */
-      if (!proc->resolved
+      if (!proc->resolve_symbol_called
 	  && proc->attr.function == 0 && proc->attr.subroutine == 0)
 	{
 	  gfc_symbol *tmp;
@@ -14791,9 +14793,9 @@ resolve_symbol (gfc_symbol *sym)
   gfc_array_spec *as;
   bool saved_specification_expr;
 
-  if (sym->resolved)
+  if (sym->resolve_symbol_called >= 1)
     return;
-  sym->resolved = 1;
+  sym->resolve_symbol_called = 1;
 
   /* No symbol will ever have union type; only components can be unions.
      Union type declaration symbols have type BT_UNKNOWN but flavor FL_UNION
diff --git a/gcc/testsuite/gfortran.dg/pr59107.f90 b/gcc/testsuite/gfortran.dg/pr59107.f90
new file mode 100644
index 00000000000..a84328f0851
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr59107.f90
@@ -0,0 +1,11 @@
+! { dg-compile }
+! { dg-options "-Wsurprising" }
+
+! There should be no surprising warnings
+
+program p
+  Integer :: nargs
+  intrinsic :: command_argument_count
+  nargs = command_argument_count()
+end
+
-- 
2.11.0

>From 7d38721e418d179420161acf05d9b1a85a53fa7c Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggles...@gcc.gnu.org>
Date: Thu, 23 Apr 2020 11:58:31 +0100
Subject: [PATCH] Fortran : Spurious warning message with -Wsurprising PR59107

This change is from a patch developed by

Janus Weil  <ja...@gcc.gnu.org> and
Dominique d'Humieres  <domi...@lps.ens.fr>

for gcc-5. The code has moved on since then requiring a change to
interface.c

gcc/fortran/ChangeLog:

	Backport from master
	2020-04-??  Mark Eggleston  <markeggles...@gcc.gnu.org>

	PR59107
	* gfortran.h: Rename field resolved as resolve_symbol_called
	and assign two 2 bits instead of 1.
	* interface.c (gfc_find_typebound_dtio_proc): Use new field name.
	* resolve.c (gfc_resolve_intrinsic): Replace check of the formal
	field with resolve_symbol_called is at least 2, if it is not
	set the field to 2.  (resolve_symbol): Use new field name and
	check whether it is at least 1, if it is not set the field to 1.

gcc/testsuite/ChangeLog:

        Backport from master
	020-04-??  Mark Eggleston  <markeggles...@gcc.gnu.org>

	PR59107
	* gfortran.dg/pr59107.f90: New test.
---
 gcc/fortran/gfortran.h                |  2 +-
 gcc/fortran/interface.c               |  3 ++-
 gcc/fortran/resolve.c                 |  8 +++++---
 gcc/testsuite/gfortran.dg/pr59107.f90 | 11 +++++++++++
 4 files changed, 19 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr59107.f90

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index b2e80a6b0a9..8ef8aea255d 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1587,7 +1587,7 @@ typedef struct gfc_symbol
   /* Set if the symbol is used in a function result specification .  */
   unsigned fn_result_spec:1;
   /* Used to avoid multiple resolutions of a single symbol.  */
-  unsigned resolved:1;
+  unsigned resolve_symbol_called:2;
   /* Set if this is a module function or subroutine with the
      abreviated declaration in a submodule.  */
   unsigned abr_modproc_decl:1;
diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index 04850b0406c..689c30210d7 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -4940,7 +4940,8 @@ gfc_find_typebound_dtio_proc (gfc_symbol *derived, bool write, bool formatted)
   gfc_symtree *tb_io_st = NULL;
   bool t = false;
 
-  if (!derived || !derived->resolved || derived->attr.flavor != FL_DERIVED)
+  if (!derived || !derived->resolve_symbol_called
+      || derived->attr.flavor != FL_DERIVED)
     return NULL;
 
   /* Try to find a typebound DTIO binding.  */
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 69d877ed55b..d34d3dc66fd 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -1746,9 +1746,11 @@ gfc_resolve_intrinsic (gfc_symbol *sym, locus *loc)
   gfc_intrinsic_sym* isym = NULL;
   const char* symstd;
 
-  if (sym->formal)
+  if (sym->resolve_symbol_called >= 2)
     return true;
 
+  sym->resolve_symbol_called = 2;
+
   /* Already resolved.  */
   if (sym->from_intmod && sym->ts.type != BT_UNKNOWN)
     return true;
@@ -14601,9 +14603,9 @@ resolve_symbol (gfc_symbol *sym)
   gfc_array_spec *as;
   bool saved_specification_expr;
 
-  if (sym->resolved)
+  if (sym->resolve_symbol_called >= 1)
     return;
-  sym->resolved = 1;
+  sym->resolve_symbol_called = 1;
 
   /* No symbol will ever have union type; only components can be unions.
      Union type declaration symbols have type BT_UNKNOWN but flavor FL_UNION
diff --git a/gcc/testsuite/gfortran.dg/pr59107.f90 b/gcc/testsuite/gfortran.dg/pr59107.f90
new file mode 100644
index 00000000000..a84328f0851
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr59107.f90
@@ -0,0 +1,11 @@
+! { dg-compile }
+! { dg-options "-Wsurprising" }
+
+! There should be no surprising warnings
+
+program p
+  Integer :: nargs
+  intrinsic :: command_argument_count
+  nargs = command_argument_count()
+end
+
-- 
2.11.0

Reply via email to