summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2022-04-04 20:42:51 +0200
committerHarald Anlauf <anlauf@gmx.de>2022-05-16 21:50:59 +0200
commitf43db17894744827d93ddcea7952d4ecf1f83f30 (patch)
tree4e4749f2d6fb65037b2b9572a89aee1fdfcacde2
parent882739c259fa2a0dcce58b501c140e3ef0bf1e5d (diff)
Fortran: a RECURSIVE procedure cannot be an INTRINSIC
gcc/fortran/ChangeLog: PR fortran/105138 * intrinsic.c (gfc_is_intrinsic): When a symbol refers to a RECURSIVE procedure, it cannot be an INTRINSIC. gcc/testsuite/ChangeLog: PR fortran/105138 * gfortran.dg/recursive_reference_3.f90: New test. Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org> (cherry picked from commit d46685b04071a485b56de353d997a866bfc8caba)
-rw-r--r--gcc/fortran/intrinsic.c1
-rw-r--r--gcc/testsuite/gfortran.dg/recursive_reference_3.f9014
2 files changed, 15 insertions, 0 deletions
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index 3fbc8cad914..7d8504166d6 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -1105,6 +1105,7 @@ gfc_is_intrinsic (gfc_symbol* sym, int subroutine_flag, locus loc)
/* Check for attributes which prevent the symbol from being INTRINSIC. */
if (sym->attr.external || sym->attr.contained
+ || sym->attr.recursive
|| sym->attr.if_source == IFSRC_IFBODY)
return false;
diff --git a/gcc/testsuite/gfortran.dg/recursive_reference_3.f90 b/gcc/testsuite/gfortran.dg/recursive_reference_3.f90
new file mode 100644
index 00000000000..f4e2963aec2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/recursive_reference_3.f90
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! { dg-options "-std=f2018" }
+! PR fortran/105138 - recursive procedures and shadowing of intrinsics
+
+RECURSIVE FUNCTION LOG_GAMMA(Z) RESULT(RES)
+ COMPLEX, INTENT(IN) :: Z
+ COMPLEX :: RES
+ RES = LOG_GAMMA(Z)
+END FUNCTION LOG_GAMMA
+
+recursive subroutine date_and_time (z)
+ real :: z
+ if (z > 0) call date_and_time (z-1)
+end subroutine date_and_time