Dear all,

the attached simple and obvious patch fixes a bogus recursion error
with inquiry refs used statement functions.  The commit message
says all there is to say...

Regtested on x86_64-pc-linux-gnu.

I intend to commit to mainline within the next 24 hours unless someone
screams...  Will also backport to 14-branch after a decent delay.

Thanks,
Harald

From 8bb31eb3d7f8ea6d21066380c36abf53f7b64156 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anl...@gmx.de>
Date: Fri, 10 May 2024 21:18:03 +0200
Subject: [PATCH] Fortran: fix dependency checks for inquiry refs [PR115039]

gcc/fortran/ChangeLog:

	PR fortran/115039
	* expr.cc (gfc_traverse_expr): An inquiry ref does not constitute
	a dependency and cannot collide with a symbol.

gcc/testsuite/ChangeLog:

	PR fortran/115039
	* gfortran.dg/statement_function_5.f90: New test.
---
 gcc/fortran/expr.cc                           |  3 ++-
 .../gfortran.dg/statement_function_5.f90      | 20 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/statement_function_5.f90

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 66edad58278..8e29535b0f7 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -5500,7 +5500,8 @@ gfc_traverse_expr (gfc_expr *expr, gfc_symbol *sym,
 	  break;

 	case REF_INQUIRY:
-	  return true;
+	  /* An inquiry_ref does not collide with a symbol.  */
+	  return false;

 	default:
 	  gcc_unreachable ();
diff --git a/gcc/testsuite/gfortran.dg/statement_function_5.f90 b/gcc/testsuite/gfortran.dg/statement_function_5.f90
new file mode 100644
index 00000000000..bc5a5dba7a0
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/statement_function_5.f90
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! PR fortran/115039
+!
+! Check that inquiry refs work with statement functions
+!
+! { dg-additional-options "-std=legacy -fdump-tree-optimized" }
+! { dg-prune-output " Obsolescent feature" }
+! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "optimized" } }
+
+program testit
+  implicit none
+  complex :: x
+  real    :: im
+  integer :: slen
+  character(5) :: s
+  im(x)   = x%im + x%re + x%kind
+  slen(s) = s%len
+  if (im((1.0,3.0) + (2.0,4.0)) /= 14.) stop 1
+  if (slen('abcdef') /= 5)              stop 2
+end program testit
--
2.35.3

Reply via email to