Fortran: fix ICE on bad use of statement function [PR107995]

Message ID trinity-24b92e9f-fa6e-4c3c-bad9-e66b6e0de14f-1670707406360@3c-app-gmx-bap38
State Accepted
Headers
Series Fortran: fix ICE on bad use of statement function [PR107995] |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Harald Anlauf Dec. 10, 2022, 9:23 p.m. UTC
  Dear all,

I'm submitting the attached patch on behalf of Steve.
It fixes an ICE that occurs on an obscure use of a
statement function as argument to that function.

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

Thanks,
Harald
  

Comments

Jerry D Dec. 11, 2022, 4:30 p.m. UTC | #1
On 12/10/22 1:23 PM, Harald Anlauf via Fortran wrote:
> Dear all,
> 
> I'm submitting the attached patch on behalf of Steve.
> It fixes an ICE that occurs on an obscure use of a
> statement function as argument to that function.
> 
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
> 
> Thanks,
> Harald
> 

OK, looks good. See my unrelated question on mattermost.

Jerry
  

Patch

From f717054e7d656588650f6d4fd5a03840c6dc9a9c Mon Sep 17 00:00:00 2001
From: Steve Kargl <kargl@gcc.gnu.org>
Date: Sat, 10 Dec 2022 22:17:15 +0100
Subject: [PATCH] Fortran: fix ICE on bad use of statement function [PR107995]

gcc/fortran/ChangeLog:

	PR fortran/107995
	* interface.cc (gfc_check_dummy_characteristics): Reject statement
	function dummy arguments.

gcc/testsuite/ChangeLog:

	PR fortran/107995
	* gfortran.dg/pr107995.f90: New test.
---
 gcc/fortran/interface.cc               |  6 ++++++
 gcc/testsuite/gfortran.dg/pr107995.f90 | 10 ++++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr107995.f90

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index 73799c175b7..7d8eeda5a99 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -1334,6 +1334,12 @@  gfc_check_dummy_characteristics (gfc_symbol *s1, gfc_symbol *s2,
   if (s1 == NULL || s2 == NULL)
     return s1 == s2 ? true : false;

+  if (s1->attr.proc == PROC_ST_FUNCTION || s2->attr.proc == PROC_ST_FUNCTION)
+    {
+      strncpy (errmsg, "Statement function", err_len);
+      return false;
+    }
+
   /* Check type and rank.  */
   if (type_must_agree)
     {
diff --git a/gcc/testsuite/gfortran.dg/pr107995.f90 b/gcc/testsuite/gfortran.dg/pr107995.f90
new file mode 100644
index 00000000000..22e878630b8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107995.f90
@@ -0,0 +1,10 @@ 
+! { dg-do compile }
+! PR fortran/107995
+! Contributed by G.Steinmetz
+
+program p
+  implicit none
+  integer :: n  ! { dg-error "Self-referential argument" }
+  n(n) = 1      ! { dg-warning "Statement function" }
+  print *, n(n) ! { dg-error "Statement function" }
+end
--
2.35.3