This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, Fortran] PR 39577 - fix -fcheck=recursion


Tobias,

With your new patch, most of the "Recursive call to nonrecursive procedure"
I saw are now gone. I think the error is right on the first two tests at the
end of this mail where the recursivity is obfuscated. For the third test
(a monster coming form comp.lang.fortran, likely authored by James Van Buskirk!-)
I am not sure that the error is valid (I don't really understand the code).

Note that the ICE with -fwhole-file on the test given in:

http://gcc.gnu.org/ml/fortran/2009-03/msg00310.html

is back despite the Paul's patch in

http://gcc.gnu.org/ml/fortran/2009-03/msg00312.html

> I think there are still a couple of bugs in gfortran with
> ENTRY as it is only rarely used.

I see pr34500 (ICE) and pr34663 and pr23280 and pr37134 (for missing
debug info). For these issues you may need to interact with Paul.

Thanks for the work.

Dominique

-----------------------------------------------------------------------------

(1) obfuscated recursivity

program skrofa
   implicit none
   integer, external :: fact
   integer           :: i

   do i=1, 10
      write(*,*) i, fact(i)
   end do

   stop
end program skrofa

function fact(n)
   implicit none
   integer n, fact
   integer, external :: gact

   if(n <= 1) then
      fact = 1
   else
      fact = gact(n)
   end if

   return
end function fact

function gact(n)
   implicit none
   integer n, gact
   integer, external :: fact

   gact = n*fact(n-1)

   return
end function gact 

-----------------------------------------------------------------------------

(2) obfuscated recursivity

module mod1 
 contains 
 function factorial(n) 
   implicit none 
   integer :: n, factorial 
   factorial = n * temp(n-1) 
 end function factorial 
 function temp( n ) 
  implicit none 
  integer n, temp 
  if(n == 2) then 
    temp = 2 
  else 
    temp = factorial( n ) 
  end if 
  return 
 end function temp 
 recursive function factorial2( n ) result( nn ) 
  integer, intent(in) :: n 
  integer :: nn 
  if(n == 2) then 
    nn = 2 
  else 
    nn = factorial2(n-1) * n 
  end if 
  return 
 end function factorial2 
end module mod1 
program main 
 use mod1 
 implicit none 
 print*, factorial(3), factorial(4), factorial(5) 
 print*, factorial2(3), factorial2(4), factorial2(5) 
! pause 
end 

-----------------------------------------------------------------------------

(3) monster code I don't understand

MODULE pthread 
  USE, INTRINSIC :: iso_c_binding 
  IMPLICIT NONE 
  PRIVATE 
  PUBLIC :: pthread_t 
  PUBLIC :: pthread_create 
  PUBLIC :: pthread_exit 
  INTEGER, PARAMETER :: pthread_t_size = 1 
  TYPE, BIND(c) :: pthread_t 
    PRIVATE 
    INTEGER(c_int) :: hidden(pthread_t_size) 
  END TYPE pthread_t 
  INTERFACE 
    INTEGER(c_int) FUNCTION pthread_create(thread, attr, start_routine, arg) BIND(C) 
      IMPORT :: c_int, c_ptr, c_funptr 
      TYPE(c_ptr),    VALUE :: thread 
      TYPE(c_ptr),    VALUE :: attr 
      TYPE(c_funptr), VALUE :: start_routine 
      TYPE(c_ptr),    VALUE :: arg 
    END FUNCTION pthread_create 
    SUBROUTINE pthread_exit(value_ptr) BIND(c) 
      IMPORT :: c_ptr 
      TYPE(c_ptr),    VALUE :: value_ptr 
    END SUBROUTINE pthread_exit 
  END INTERFACE 
END MODULE pthread 
MODULE start_routine 
  USE, INTRINSIC :: iso_c_binding 
  USE :: pthread 
  IMPLICIT NONE 
  PRIVATE 
  PUBLIC :: PrintHello 
CONTAINS 
  SUBROUTINE PrintHello (ThreadId) BIND(c) 
    TYPE(c_ptr), VALUE :: ThreadId 
    INTEGER, POINTER :: tid 
    CALL c_f_pointer(ThreadId, tid) 
    PRINT *, "Hello World! It's me, thread #", tid, "!" 
    CALL pthread_exit(c_null_ptr); 
  END SUBROUTINE PrintHello 
END MODULE start_routine 
PROGRAM PthreadTest 
  USE, INTRINSIC :: iso_c_binding 
  USE :: pthread 
  USE :: start_routine 
  IMPLICIT NONE 
  INTEGER, PARAMETER :: NumThreads = 5 
  TYPE(c_funptr) :: start 
  TYPE(pthread_t), TARGET :: threads(0:4) 
  TYPE(c_ptr) :: thread_ptr 
  INTEGER :: rc 
  INTEGER, TARGET :: t 
  TYPE(c_ptr) :: t_ptr 
  start = c_funloc(PrintHello) 
  DO t = 0, NumThreads-1 
    PRINT *, "In main: creating thread ", t 
    t_ptr = c_loc(t) 
    thread_ptr = c_loc(threads(t)) 
    rc = pthread_create(thread_ptr, c_null_ptr, start, t_ptr); 
    IF (rc /= 0) THEN 
      PRINT *, "ERROR; return code from pthread_create() is ", rc 
      STOP 
    ENDIF 
  ENDDO 
  CALL pthread_exit(c_null_ptr); 
END PROGRAM PthreadTest 

-----------------------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]