public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/32153] New: runtime integer overflow checking fails
@ 2007-05-30 10:10 kloedej at knmi dot nl
2007-05-30 17:54 ` [Bug fortran/32153] " burnus at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: kloedej at knmi dot nl @ 2007-05-30 10:10 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/32153] runtime integer overflow checking fails
2007-05-30 10:10 [Bug fortran/32153] New: runtime integer overflow checking fails kloedej at knmi dot nl
@ 2007-05-30 17:54 ` burnus at gcc dot gnu dot org
2007-05-30 18:03 ` ebotcazou at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-05-30 17:54 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from burnus at gcc dot gnu dot org 2007-05-30 17:54 -------
-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.
--
burnus at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |WONTFIX
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32153
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/32153] runtime integer overflow checking fails
2007-05-30 10:10 [Bug fortran/32153] New: runtime integer overflow checking fails kloedej at knmi dot nl
2007-05-30 17:54 ` [Bug fortran/32153] " burnus at gcc dot gnu dot org
@ 2007-05-30 18:03 ` ebotcazou at gcc dot gnu dot org
2007-05-30 19:59 ` rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2007-05-30 18:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from ebotcazou at gcc dot gnu dot org 2007-05-30 18:02 -------
> -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...
--
ebotcazou at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ebotcazou at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32153
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/32153] runtime integer overflow checking fails
2007-05-30 10:10 [Bug fortran/32153] New: runtime integer overflow checking fails kloedej at knmi dot nl
2007-05-30 17:54 ` [Bug fortran/32153] " burnus at gcc dot gnu dot org
2007-05-30 18:03 ` ebotcazou at gcc dot gnu dot org
@ 2007-05-30 19:59 ` rguenth at gcc dot gnu dot org
2007-05-30 19:59 ` rguenth at gcc dot gnu dot org
2007-06-01 8:41 ` kloedej at knmi dot nl
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-05-30 19:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from rguenth at gcc dot gnu dot org 2007-05-30 19:59 -------
...to mark as dup of PR19020.
*** This bug has been marked as a duplicate of 19020 ***
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32153
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/32153] runtime integer overflow checking fails
2007-05-30 10:10 [Bug fortran/32153] New: runtime integer overflow checking fails kloedej at knmi dot nl
` (2 preceding siblings ...)
2007-05-30 19:59 ` rguenth at gcc dot gnu dot org
@ 2007-05-30 19:59 ` rguenth at gcc dot gnu dot org
2007-06-01 8:41 ` kloedej at knmi dot nl
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-05-30 19:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2007-05-30 19:59 -------
Reopen...
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|WONTFIX |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32153
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/32153] runtime integer overflow checking fails
2007-05-30 10:10 [Bug fortran/32153] New: runtime integer overflow checking fails kloedej at knmi dot nl
` (3 preceding siblings ...)
2007-05-30 19:59 ` rguenth at gcc dot gnu dot org
@ 2007-06-01 8:41 ` kloedej at knmi dot nl
4 siblings, 0 replies; 6+ messages in thread
From: kloedej at knmi dot nl @ 2007-06-01 8:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from kloedej at knmi dot nl 2007-06-01 08:41 -------
(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
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32153
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-06-01 8:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-30 10:10 [Bug fortran/32153] New: runtime integer overflow checking fails kloedej at knmi dot nl
2007-05-30 17:54 ` [Bug fortran/32153] " burnus at gcc dot gnu dot org
2007-05-30 18:03 ` ebotcazou at gcc dot gnu dot org
2007-05-30 19:59 ` rguenth at gcc dot gnu dot org
2007-05-30 19:59 ` rguenth at gcc dot gnu dot org
2007-06-01 8:41 ` kloedej at knmi dot nl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).