This one-line fix removes a check for recursion for procedures
which are compiler-generated, such as finalizers or deallocation.
These need to be recursive, even if the user code should not be.
gcc/fortran/ChangeLog:
PR fortran/95743
* trans-decl.c (gfc_generate_function_code): Do not generate
recursion check for compiler-generated procedures.
|| (sym->attr.entry_master
&& sym->ns->entries->sym->attr.recursive);
if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION)
- && !is_recursive && !flag_recursive)
+ && !is_recursive && !flag_recursive && !sym->attr.artificial)
{
char * msg;
--- /dev/null
+! { dg-do run }
+! ! { dg-options "-fcheck=recursion" }
+! PR 95743 - this used cause a runtime error.
+! Test case by Antoine Lemoine
+
+program test_recursive_call
+ implicit none
+
+ type t_tree_node
+ type(t_tree_node), dimension(:), allocatable :: child
+ end type
+
+ type t_tree
+ type(t_tree_node), allocatable :: root
+ end type
+
+ type(t_tree), allocatable :: tree
+
+ allocate(tree)
+ allocate(tree%root)
+ allocate(tree%root%child(1))
+ ! If the line below is removed, the code works fine.
+ allocate(tree%root%child(1)%child(1))
+ deallocate(tree)
+end program