Fortran: a RECURSIVE procedure cannot be an INTRINSIC
authorHarald Anlauf <anlauf@gmx.de>
Mon, 4 Apr 2022 18:42:51 +0000 (20:42 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 5 Apr 2022 17:06:09 +0000 (19:06 +0200)
gcc/fortran/ChangeLog:

PR fortran/105138
* intrinsic.cc (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>
gcc/fortran/intrinsic.cc
gcc/testsuite/gfortran.dg/recursive_reference_3.f90 [new file with mode: 0644]

index 2339d90..e89131f 100644 (file)
@@ -1164,6 +1164,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 (file)
index 0000000..f4e2963
--- /dev/null
@@ -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