public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fortran: Missing error with IMPLICIT none (external) [PR100972]
@ 2021-10-31 17:25 Bernhard Reutner-Fischer
  2021-11-05 20:00 ` Mikael Morin
  0 siblings, 1 reply; 2+ messages in thread
From: Bernhard Reutner-Fischer @ 2021-10-31 17:25 UTC (permalink / raw)
  To: gcc-patches, fortran; +Cc: Bernhard Reutner-Fischer, Bernhard Reutner-Fischer

From: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>

gcc/fortran/ChangeLog:

	PR fortran/100972
	* decl.c (gfc_match_implicit_none): Fix typo in warning.
	* resolve.c (resolve_unknown_f): Reject external procedures
	without explicit EXTERNAL attribute whe IMPLICIT none (external)
	is in effect.

gcc/testsuite/ChangeLog:

	PR fortran/100972
	* gfortran.dg/implicit_14.f90: Adjust error.
	* gfortran.dg/external_implicit_none_3.f08: New test.

---

As Gerhard Steinmetz noticed, gfc_match_implicit_none() had a notify_std
that mentioned IMPORT instead of IMPLICIT. Fix that typo.

IMPLICIT NONE (external) is supposed to require external procedures to
be explicitly declared with EXTERNAL.
We cannot do this when parsing in e.g.
gfc_match_rvalue->gfc_match_varspec because the procedure might live
way down in a CONTAINS like in bind-c-contiguous-3.f90.
Hence diagnose missing EXTERNAL declaraions when resolving.

Bootstrapped and regtested on x86_64-unknown-linux without regressions.
Ok for trunk?
---
 gcc/fortran/decl.c                              |  2 +-
 gcc/fortran/resolve.c                           | 13 +++++++++++++
 .../gfortran.dg/external_implicit_none_3.f08    | 17 +++++++++++++++++
 gcc/testsuite/gfortran.dg/implicit_14.f90       |  2 +-
 4 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/external_implicit_none_3.f08

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index e9e23fe1acb..ab88ab5e9c1 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -4715,7 +4715,7 @@ gfc_match_implicit_none (void)
   if (c == '(')
     {
       (void) gfc_next_ascii_char ();
-      if (!gfc_notify_std (GFC_STD_F2018, "IMPORT NONE with spec list at %C"))
+      if (!gfc_notify_std (GFC_STD_F2018, "IMPLICIT NONE with spec list at %C"))
 	return MATCH_ERROR;
 
       gfc_gobble_whitespace ();
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 21126cba262..1f4abd08720 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -2974,6 +2974,19 @@ resolve_unknown_f (gfc_expr *expr)
       return false;
     }
 
+  /* IMPLICIT NONE (external) procedures require an explicit EXTERNAL attr.  */
+  /* Intrinsics were handled above, only non-intrinsics left here.  */
+  if (sym->attr.flavor == FL_PROCEDURE
+      && sym->attr.implicit_type
+      && sym->ns
+      && sym->ns->has_implicit_none_export)
+    {
+	  gfc_error ("Missing explicit declaration with EXTERNAL attribute "
+	      "for symbol %qs at %L", sym->name, &sym->declared_at);
+	  sym->error = 1;
+	  return false;
+    }
+
   /* The reference is to an external name.  */
 
   sym->attr.proc = PROC_EXTERNAL;
diff --git a/gcc/testsuite/gfortran.dg/external_implicit_none_3.f08 b/gcc/testsuite/gfortran.dg/external_implicit_none_3.f08
new file mode 100644
index 00000000000..329deedc413
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/external_implicit_none_3.f08
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! { dg-options "-std=f2018" }
+! Tests fix for PR100972 - Fails to warn about missing EXTERNAL attribute
+! Contributed by Gerhard Steinmetz
+
+program p
+   implicit none (external)
+   real, external :: f
+   real :: a
+   real :: b
+   integer :: i
+   character :: c
+   a = f() ! OK
+   b = g() ! { dg-error "Missing explicit declaration with EXTERNAL attribute" }
+   i = h() ! { dg-error "Missing explicit declaration with EXTERNAL attribute" }
+   c = j() ! { dg-error "Missing explicit declaration with EXTERNAL attribute" }
+end
diff --git a/gcc/testsuite/gfortran.dg/implicit_14.f90 b/gcc/testsuite/gfortran.dg/implicit_14.f90
index 8282c1f1f86..422d913fd4f 100644
--- a/gcc/testsuite/gfortran.dg/implicit_14.f90
+++ b/gcc/testsuite/gfortran.dg/implicit_14.f90
@@ -4,5 +4,5 @@
 ! Support Fortran 2018's IMPLICIT NONE with spec list
 ! (currently implemented as vendor extension)
 
-implicit none (type) ! { dg-error "Fortran 2018: IMPORT NONE with spec list at \\(1\\)" }
+implicit none (type) ! { dg-error "Fortran 2018: IMPLICIT NONE with spec list at \\(1\\)" }
 end
-- 
2.33.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fortran: Missing error with IMPLICIT none (external) [PR100972]
  2021-10-31 17:25 [PATCH] Fortran: Missing error with IMPLICIT none (external) [PR100972] Bernhard Reutner-Fischer
@ 2021-11-05 20:00 ` Mikael Morin
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2021-11-05 20:00 UTC (permalink / raw)
  To: Bernhard Reutner-Fischer, gcc-patches, fortran; +Cc: Bernhard Reutner-Fischer

Le 31/10/2021 à 18:25, Bernhard Reutner-Fischer via Fortran a écrit :
> As Gerhard Steinmetz noticed, gfc_match_implicit_none() had a notify_std
> that mentioned IMPORT instead of IMPLICIT. Fix that typo.
> 
> IMPLICIT NONE (external) is supposed to require external procedures to
> be explicitly declared with EXTERNAL.
> We cannot do this when parsing in e.g.
> gfc_match_rvalue->gfc_match_varspec because the procedure might live
> way down in a CONTAINS like in bind-c-contiguous-3.f90.
> Hence diagnose missing EXTERNAL declaraions when resolving.
> 
> Bootstrapped and regtested on x86_64-unknown-linux without regressions.
> Ok for trunk?

OK, thanks.

Mikael

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-05 20:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-31 17:25 [PATCH] Fortran: Missing error with IMPLICIT none (external) [PR100972] Bernhard Reutner-Fischer
2021-11-05 20:00 ` Mikael Morin

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).