When compiling my code with the -ftrapv option, I would have expected the program to detect integer overflows. However, this only seems to happen for the 8-byte integer type, and not for the other integer types. Maybe I have a wrong expectation here, and it should only check 8-byte integers? If this is the case, I would like to request implementation of an additional option to do this runtime check for the other types as well (which may be very usefull for debugging purposes). Here are the code fragments that I used for testing and the results: >gfortran -v Using built-in specs. Target: i386-pc-linux-gnu Configured with: /home/fxcoudert/gfortran_nightbuild/trunk/configure --prefix=/home/fxcoudert/gfortran_nightbuild/irun-20070529 --enable-languages=c,fortran --build=i386-pc-linux-gnu --enable-checking=release --with-gmp=/home/fxcoudert/gfortran_nightbuild/software Thread model: posix gcc version 4.3.0 20070529 (experimental) >cat TestInt1.F90 program Test1 integer(1) :: i,j i=126 ! max for this type is 127 do j=1,10 print *,"i=",i i = i + 1 enddo end program Test1 >gfortran -ftrapv -o TestInt1 TestInt1.F90 >TestInt1 i= 126 i= 127 i= -128 i= -127 i= -126 i= -125 i= -124 i= -123 i= -122 i= -121 >cat TestInt2.F90 program Test2 integer(2) :: i,j i=32767-1 ! max for this type is 32767 do j=1,10 print *,"i=",i i = i + 1 enddo end program Test2 >gfortran -ftrapv -o TestInt2 TestInt2.F90 >TestInt2 i= 32766 i= 32767 i= -32768 i= -32767 i= -32766 i= -32765 i= -32764 i= -32763 i= -32762 i= -32761 >cat TestInt4.F90 program Test4 integer(4) :: i,j i=2147483647-1 ! max for this type is 2147483647 do j=1,10 print *,"i=",i i = i + 1 enddo end program Test4 >gfortran -ftrapv -o TestInt4 TestInt4.F90 >TestInt4 i= 2147483646 i= 2147483647 i= -2147483648 i= -2147483647 i= -2147483646 i= -2147483645 i= -2147483644 i= -2147483643 i= -2147483642 i= -2147483641 >cat TestInt8.F90 program Test8 integer(8) :: i,j i=9223372036854775807_8-1 ! max for this type is 9223372036854775807 do j=1,10 print *,"i=",i i = i + 1 enddo end program Test8 >gfortran -ftrapv -o TestInt8 TestInt8.F90 >TestInt8 i= 9223372036854775806 i= 9223372036854775807 Abort best regards, Jos de Kloe
-ftrapv only traps floating-point overflow - no integer overflows. (This is not completely correct, as some systems seem to offer to send FPE also for integer overflows, see e.g. https://www.cisl.ucar.edu/docs/ibm/ref/fpe.html For x86 (32/64) platforms, this does not seem to be directly supported by hardware; in this case one would need to add manual checks, which are slow, cf. e.g. http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30227217.aspx .) -> WONTFIX, unless you find a good method to trap integer overflows.
> -ftrapv only traps floating-point overflow - no integer overflows. It's the other way around, -ftrapv is meant to trap on integer operations only. But it's well-known for being broken...
Reopen...
...to mark as dup of PR19020. *** This bug has been marked as a duplicate of 19020 ***
(In reply to comment #1) > for integer overflows, see e.g. > https://www.cisl.ucar.edu/docs/ibm/ref/fpe.html > For x86 (32/64) platforms, this does not seem to be directly supported by > hardware; in this case one would need to add manual checks, which are slow, cf. ... > -> WONTFIX, unless you find a good method to trap integer overflows. thanks for your replies. I understand adding extra checks makes the compiled code slower, if this cannot be done by the hardware (but the same is probably true for many other runtime checks, like bounds checking, etc.) However, I think it would be very usefull to have such an option for debugging purposes. If anyone finds the time to implement it, it would be highly appreciated. best regards, Jos de Kloe