public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fortran: diagnostics of MODULE PROCEDURE declaration conflicts [PR104649]
@ 2023-10-26 20:43 Harald Anlauf
  2023-10-27  8:22 ` Paul Richard Thomas
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2023-10-26 20:43 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear all,

the attached patch improves the diagnostics of MODULE PROCEDURE declaration
conflicts, when one of the declarations is an alternate return.  We used to
ICE before.

Steve identified the cause of the issue and provided a partial fix.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr104649.diff --]
[-- Type: text/x-patch, Size: 3117 bytes --]

From 9d591a73f070e6090b7c59dca928b84b1c261d92 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Thu, 26 Oct 2023 22:32:35 +0200
Subject: [PATCH] Fortran: diagnostics of MODULE PROCEDURE declaration
 conflicts [PR104649]

gcc/fortran/ChangeLog:

	PR fortran/104649
	* decl.cc (gfc_match_formal_arglist): Handle conflicting declarations
	of a MODULE PROCEDURE when one of the declarations is an alternate
	return.

gcc/testsuite/ChangeLog:

	PR fortran/104649
	* gfortran.dg/pr104649.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
---
 gcc/fortran/decl.cc                    | 21 +++++++++---
 gcc/testsuite/gfortran.dg/pr104649.f90 | 44 ++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr104649.f90

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index bdd3be32a46..4893c582065 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -6796,12 +6796,25 @@ ok:
 	      || (p->next == NULL && q->next != NULL))
 	    arg_count_mismatch = true;
 	  else if ((p->sym == NULL && q->sym == NULL)
-		    || strcmp (p->sym->name, q->sym->name) == 0)
+		    || (p->sym && q->sym
+			&& strcmp (p->sym->name, q->sym->name) == 0))
 	    continue;
 	  else
-	    gfc_error_now ("Mismatch in MODULE PROCEDURE formal "
-			   "argument names (%s/%s) at %C",
-			   p->sym->name, q->sym->name);
+	    {
+	      if (q->sym == NULL)
+		gfc_error_now ("MODULE PROCEDURE formal argument %qs "
+			       "conflicts with alternate return at %C",
+			       p->sym->name);
+	      else if (p->sym == NULL)
+		gfc_error_now ("MODULE PROCEDURE formal argument is "
+			       "alternate return and conflicts with "
+			       "%qs in the separate declaration at %C",
+			       q->sym->name);
+	      else
+		gfc_error_now ("Mismatch in MODULE PROCEDURE formal "
+			       "argument names (%s/%s) at %C",
+			       p->sym->name, q->sym->name);
+	    }
 	}

       if (arg_count_mismatch)
diff --git a/gcc/testsuite/gfortran.dg/pr104649.f90 b/gcc/testsuite/gfortran.dg/pr104649.f90
new file mode 100644
index 00000000000..f301ffcde1f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104649.f90
@@ -0,0 +1,44 @@
+! { dg-do compile }
+! { dg-options "-w" }
+! PR fortran/104649
+! Contributed by G.Steinmetz
+
+module m
+  interface
+    module subroutine s(x)
+      real :: x
+    end
+  end interface
+end
+submodule(m) m2
+contains
+  module subroutine s(*) ! { dg-error "conflicts with alternate return" }
+  end
+end
+
+module n
+  interface
+     module subroutine s(*)
+     end
+  end interface
+end
+submodule(n) n2
+contains
+  module subroutine s(x) ! { dg-error "formal argument is alternate return" }
+    real :: x
+  end
+end
+
+module p
+  interface
+     module subroutine s(x)
+       real :: x
+     end
+  end interface
+end
+submodule(p) p2
+contains
+  module subroutine s(y) ! { dg-error "Mismatch in MODULE PROCEDURE formal argument names" }
+    real :: y
+  end
+end
--
2.35.3


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

* Re: [PATCH] Fortran: diagnostics of MODULE PROCEDURE declaration conflicts [PR104649]
  2023-10-26 20:43 [PATCH] Fortran: diagnostics of MODULE PROCEDURE declaration conflicts [PR104649] Harald Anlauf
@ 2023-10-27  8:22 ` Paul Richard Thomas
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2023-10-27  8:22 UTC (permalink / raw)
  To: Harald Anlauf; +Cc: fortran, gcc-patches

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

Hi Harald,

That's good for mainline.

Thanks for the patch

Paul


On Thu, 26 Oct 2023 at 21:43, Harald Anlauf <anlauf@gmx.de> wrote:

> Dear all,
>
> the attached patch improves the diagnostics of MODULE PROCEDURE declaration
> conflicts, when one of the declarations is an alternate return.  We used to
> ICE before.
>
> Steve identified the cause of the issue and provided a partial fix.
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
>
> Thanks,
> Harald
>
>

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

end of thread, other threads:[~2023-10-27  8:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-26 20:43 [PATCH] Fortran: diagnostics of MODULE PROCEDURE declaration conflicts [PR104649] Harald Anlauf
2023-10-27  8:22 ` Paul Richard Thomas

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