Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26736 Discussions

Trace/BPT trap: 5 on mac os when moving function to inner function and compiling with -check all

Rivoldini__Attilio
174 Views

Hi,

In the code given below the compiled program stops with a Trace/BPT trap: 5 when calling function calculate for a second time and compiling with  -check all with ifort version 19.0.5.281 on mac os 10.14.6 . The function calculate from module mod1 is identical to calculate2 from module mod3 except that the function f1 is an inner function of function calculate and a module function in module mod3. Without the -check all compiler flag there is no Trace/BPT trap: 5 and the code works fine with gfortran 8.1. 

Cheers,

AR

 

module mod

type:: myType
real(8)::val
real(8),allocatable::bigTable(:)
logical,private::flag=.false.
procedure(realFunction1),private,pointer,nopass::f =>null()
contains 
    procedure::calc
end type myType

interface myType
module procedure init_myType
end interface myType

abstract interface

function realFunction1(x)
real(8)::realFunction1
real(8),intent(in)::x
end function realFunction1

end interface

contains
    
type(myType) function init_myType(val,f) result(this)
real(8),intent(in)::val
procedure(realFunction1),optional::f
integer::i

this%val=val
allocate(this%bigTable(1000))
do i=1,1000
    this%bigTable(i)=i
enddo
    
if (present(f)) then
    this%f=>f
    this%flag=.true.
end if

end function init_myType

real(8) function calc(this,x)
class(myType)::this
real(8),intent(in)::x
if (this%flag) then
    calc=this%f(x)
else 
    calc=x
endif
calc=calc+sum(this%bigTable)
end function calc

end module mod

module mod2
use mod

contains
real(8) function calculate(x)
real(8),intent(in)::x
logical,save:: flag=.false.
type(myType),save::m1,m2
    
if (.not. flag) then
    flag=.true.
    m1=myType(10.d0,f1)
    m2=myType(20.d0)
endif

calculate=m1%calc(x)+m2%calc(x)

contains

real(8) function f1(x)
real(8), intent(in)::x
f1=x
end function f1
    
end function calculate

end module mod2


module mod3
use mod

contains
real(8) function calculate2(x)
real(8),intent(in)::x
logical,save::flag=.false.
type(myType),save::m1,m2
    
if (.not. flag) then
    flag=.true.
    m1=myType(10.d0,f1)
    m2=myType(20.d0)
endif

calculate2=m1%calc(x)+m2%calc(x)
    
end function calculate2

real(8) function f1(x)
real(8), intent(in)::x
f1=x
end function f1

end module mod3

program break
use mod2
use mod3,only:calculate2

write(*,*) 'calculate2'
write(*,*) calculate2(1.d0)
write(*,*) calculate2(2.d0)
write(*,*) calculate2(3.d0)
write(*,*) 'calculate'
write(*,*) calculate(1.d0)
write(*,*) calculate(2.d0)
write(*,*) calculate(3.d0)


end program break
 

0 Kudos
0 Replies
Reply