1! { dg-do run }
2! { dg-options "-fcheck=recursion" }
3! { dg-shouldfail "Recursion check" }
4!
5! { dg-output "Fortran runtime error: Recursive call to nonrecursive procedure 'f'" }
6!
7! PR fortran/39577
8!
9! Invalid - recursion
10program test
11 call f(.false.)
12 call f(.true.)
13contains
14  subroutine f(rec)
15    logical :: rec
16    if(rec) then
17      call g()
18    end if
19    return
20  end subroutine f
21  subroutine g()
22    call f(.false.)
23    return
24  end subroutine g
25end program test
26