Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29341 Discussions

Problem with recursive subroutine with class(*) argument

MR
Beginner
652 Views

Hi all,

I notice that the attached code produces a segmentation fault - I think that the code is fine. Seems to me like a problem related to the RECURSIVE subroutine with a CLASS(*) argument.

$ ./rec_call
   2.000000    
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
rec_call           00000000004725B9  Unknown               Unknown  Unknown
rec_call           0000000000470E8E  Unknown               Unknown  Unknown
rec_call           00000000004265C2  Unknown               Unknown  Unknown
rec_call           00000000004051D3  Unknown               Unknown  Unknown
rec_call           0000000000408BDB  Unknown               Unknown  Unknown
libpthread.so.0    00007FE1B31EDB10  Unknown               Unknown  Unknown
rec_call           0000000000402FAA  m_mp_s_                     7  rcs.f90
rec_call           0000000000403B0F  m_mp_retry_                21  rcs.f90
rec_call           0000000000403412  m_mp_s_                    11  rcs.f90
rec_call           0000000000403D4A  MAIN__                     34  rcs.f90
rec_call           0000000000402E46  Unknown               Unknown  Unknown

$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0 Build 20140120

 

module m
 implicit none
contains
 
 recursive subroutine s(x)
  class(*), intent(in) :: x
   select type(x)
    type is(real)
     write(*,*) x
    class default
     call retry(x)
   end select
 end subroutine s

 recursive subroutine retry(x)
  class(*), intent(in) :: x
   select type(x)
    type is(real)
     call s(x)
    type is(integer)
     call s(real(x))
    class default
     error stop "Not implemented"
   end select
 end subroutine retry

end module m

program p
 use m
 implicit none

 call s(2.0) ! OK
 call s(2)   ! segmentation fault
end program p

 

0 Kudos
2 Replies
Steven_L_Intel1
Employee
652 Views

Thanks, I can reproduce this. The "recursive" aspect isn't important. If you change the second call to "call retry(2)" you get the same behavior. The compiler is not properly passing real(x) to the class(*) argument of s. I will let the developers know. Issue ID is DPD200256830.

A workaround is to use this for "retry":

 recursive subroutine retry(x)
  class(*), intent(in) :: x
  integer xx
   select type(x)
    type is(real)
     call s(x)
    type is(integer)
     xx = x
     call s(real(xx))
    class default
     error stop "Not implemented"
   end select
 end subroutine retry

 

0 Kudos
Steven_L_Intel1
Employee
652 Views

This has been fixed for the 15.0 release later this year.

0 Kudos
Reply