Silverfrost Forums

Welcome to our forums

Missing trap on integer overflow

26 May 2020 12:49 #25514

In the process of stress testing some code, I came across the following. If the result of a double precision operation to be stored in an integer exceeds the possible range of that integer, there is no exception generated, and the program terminates (and it takes a long time to do so). The following code illustrates the issue. I perform the calculation with the result being a 64-bit integer (stored into a 32-bit), the result calculated as a 32-bit integer (fails), and an implicit conversion across the equals sign (never gets here, actually). Only the first result gets output, and no overflow is detected with the conversion across the equals sign. /CHECKMATE and /RELEASE operate the same way.

    program main
    integer:: i_xx,i_yy,i_zz
    real*8:: ddx
    ddx = 9999999.d0
    i_xx = int(ddx*1000.d0,4)
    print *,i_xx
    i_zz = int(ddx*1000.d0,3)
    print *,i_zz
    i_yy = ddx*1000.d0
    print *,i_yy
    end

Is there a compiler option to enforce the checking? Or, is there no run-time exception handler?

Bill

26 May 2020 6:04 #25515

The quick answer is that integer overflow is detected for integer calculations when /debug is applied. This is true for both 32 bits and 64 bits.

integer k
k = 10
do i = 1,100
  k = 10*k
end do
end  
26 May 2020 8:28 #25516

Floating point overflow is detected (both 32 bits and 64 bits) without any options applied...

real k
k = 10.0
do i = 1,100
  k = k*k
end do
end  
26 May 2020 12:18 #25517

Paul, this is good news. For my /CHECKMATE version, I'll apply /DEBUG as well.

Thanks! Bill

Please login to reply.