diff mbox series

[committed] Backport to GCC 9: [Patch,Fortran] PR93309 – permit repeated 'implicit none(external)' in sub-scoping unit

Message ID dcc938a1-055b-66e5-115c-0f5f966e38bd@codesourcery.com
State New
Headers show
Series [committed] Backport to GCC 9: [Patch,Fortran] PR93309 – permit repeated 'implicit none(external)' in sub-scoping unit | expand

Commit Message

Tobias Burnus Feb. 3, 2020, 11:07 a.m. UTC
Backported to GCC 9, cf. attachment.

Tobias

On 1/20/20 3:55 PM, Tobias Burnus wrote:
> Using "implicit none" multiple times in a scoping unit is not 
> permitted – and checked for.
>
> However, using one in the parent name space and re-confirming it in 
> the current name space is permitted – but was before rejected.
>
> OK for the trunk?
>
> Tobias
>
diff mbox series

Patch

commit 5c80a1bd426a4aeccff0da54ab80d93d7973590e
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Mon Feb 3 11:48:17 2020 +0100

    Fortran] PR93309 – permit repeated 'implicit none(external)'
    
            Backported from mainline
            2020-01-21  Tobias Burnus  <tobias@codesourcery.com>
    
            PR fortran/93309
            * interface.c (gfc_procedure_use): Also check parent namespace for
            'implict none (external)'.
            * symbol.c (gfc_get_namespace): Don't set has_implicit_none_export
            to parent namespace's setting.
    
            Backported from mainline
            2020-01-21  Tobias Burnus  <tobias@codesourcery.com>
    
            PR fortran/93309
            * gfortran.dg/external_implicit_none_2.f90: New.
---
 gcc/fortran/ChangeLog                              | 13 +++++++++-
 gcc/fortran/interface.c                            |  7 +++++-
 gcc/fortran/symbol.c                               |  3 ---
 gcc/testsuite/ChangeLog                            |  8 +++++++
 .../gfortran.dg/external_implicit_none_2.f90       | 28 ++++++++++++++++++++++
 5 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index e0a34420e36..ec87cc9e6cf 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,14 @@ 
+2020-02-03  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backported from mainline
+	2020-01-21  Tobias Burnus  <tobias@codesourcery.com>
+
+	PR fortran/93309
+	* interface.c (gfc_procedure_use): Also check parent namespace for
+	'implict none (external)'.
+	* symbol.c (gfc_get_namespace): Don't set has_implicit_none_export
+	to parent namespace's setting.
+
 2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
 	* parse.c (parse_omp_structured_block): Handle ST_OMP_TARGET_PARALLEL.
@@ -10,7 +21,7 @@ 
 
 2020-01-17  Mark Eggleston  <mark.eggleston@codethink.com>
 
-        Backport from mainline
+	Backport from mainline
 	Mark Eggleston  <mark.eggleston@codethink.com>
 
 	PR fortran/93236
diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index bee98129bc1..b5701b1a59a 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -3671,7 +3671,12 @@  gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where)
      explicitly declared at all if requested.  */
   if (sym->attr.if_source == IFSRC_UNKNOWN && !sym->attr.is_iso_c)
     {
-      if (sym->ns->has_implicit_none_export && sym->attr.proc == PROC_UNKNOWN)
+      bool has_implicit_none_export = false;
+      if (sym->attr.proc == PROC_UNKNOWN)
+	for (gfc_namespace *ns = sym->ns; ns; ns = ns->parent)
+	   if (ns->has_implicit_none_export)
+	     has_implicit_none_export = true;
+      if (has_implicit_none_export)
 	{
 	  const char *guessed
 	    = gfc_lookup_function_fuzzy (sym->name, sym->ns->sym_root);
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 2b8f86e0881..faaeebf2c09 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -2899,9 +2899,6 @@  gfc_get_namespace (gfc_namespace *parent, int parent_types)
 	}
     }
 
-  if (parent_types && ns->parent != NULL)
-    ns->has_implicit_none_export = ns->parent->has_implicit_none_export;
-
   ns->refs = 1;
 
   return ns;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9e117a6854a..0f8e7592665 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@ 
+2020-02-03  Tobias Burnus  <tobias@codesourcery.com>
+
+	Backported from mainline
+	2020-01-21  Tobias Burnus  <tobias@codesourcery.com>
+
+	PR fortran/93309
+	* gfortran.dg/external_implicit_none_2.f90: New.
+
 2020-01-30  Kito Cheng  <kito.cheng@sifive.com>
 
 	Backport from mainline
diff --git a/gcc/testsuite/gfortran.dg/external_implicit_none_2.f90 b/gcc/testsuite/gfortran.dg/external_implicit_none_2.f90
new file mode 100644
index 00000000000..b2b1dd1e6d7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/external_implicit_none_2.f90
@@ -0,0 +1,28 @@ 
+! { dg-do compile }
+!
+! PR fortran/93309
+!
+module m
+  implicit none(external)
+contains
+  subroutine s
+    implicit none(external) ! OK
+  end subroutine
+end module
+
+module m2
+  implicit none(external)
+contains
+  subroutine s
+    call foo(1)  ! { dg-error "not explicitly declared" }
+  end subroutine
+end module
+
+module m3
+  implicit none(external)
+contains
+  subroutine s
+    implicit none(external) ! OK
+    implicit none(external) ! { dg-error "Duplicate IMPLICIT NONE statement" }
+  end subroutine
+end module