Here is an example test case that works with GFortran:
SUBROUTINE dinvr(x)
IMPLICIT NONE
DOUBLE PRECISION x
DOUBLE PRECISION big,small,zx,zy,zz, zsmall, zbig
LOGICAL qcond
INTRINSIC abs,max,min
LOGICAL qxmon
SAVE
qxmon(zx,zy,zz) = zx .LE. zy .AND. zy .LE. zz
qcond = .NOT. qxmon(small,x,big)
print *, "small = ", small
print *, "x = ", x
print *, "big = ", big
print *, 'qcond = ', qcond
IF (qcond) error stop
return
entry distinv(zsmall, zbig)
small = zsmall
big = zbig
end subroutine
program entry_10
implicit none
double precision :: x
x = 0.5d0
call distinv(0.0d0, 1.0d0)
call dinvr(x)
end program
This prints:
$ gfortran a.f90 && ./a.out
small = 0.0000000000000000
x = 0.50000000000000000
big = 1.0000000000000000
qcond = F
Now if we remove the “return” statement from before “entry distinv(zsmall, zbig)”:
SUBROUTINE dinvr(x)
IMPLICIT NONE
DOUBLE PRECISION x
DOUBLE PRECISION big,small,zx,zy,zz, zsmall, zbig
LOGICAL qcond
INTRINSIC abs,max,min
LOGICAL qxmon
SAVE
qxmon(zx,zy,zz) = zx .LE. zy .AND. zy .LE. zz
qcond = .NOT. qxmon(small,x,big)
print *, "small = ", small
print *, "x = ", x
print *, "big = ", big
print *, 'qcond = ', qcond
IF (qcond) error stop
entry distinv(zsmall, zbig)
small = zsmall
big = zbig
end subroutine
program entry_10
implicit none
double precision :: x
x = 0.5d0
call distinv(0.0d0, 1.0d0)
call dinvr(x)
end program
We obtain:
$ gfortran -g a.f90 && ./a.out
small = 0.0000000000000000
x = 0.50000000000000000
big = 1.0000000000000000
qcond = F
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x100497bd3 in ???
#1 0x100496cc3 in ???
#2 0x1869d04e3 in ???
#3 0x100023d67 in master.0.dinvr
at /Users/ondrej/repos/scipy/a.f90:18
zsh: segmentation fault ./a.out
Is this a bug in GFortran, or is the above code incorrect?