This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/32153] New: runtime integer overflow checking fails
- From: "kloedej at knmi dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 May 2007 10:10:38 -0000
- Subject: [Bug fortran/32153] New: runtime integer overflow checking fails
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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
--
Summary: runtime integer overflow checking fails
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kloedej at knmi dot nl
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32153