public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/29968] New: integer division by zero with optimization
@ 2006-11-24 10:28 tiamat at komi dot mts dot ru
2006-11-24 10:31 ` [Bug c/29968] " tiamat at komi dot mts dot ru
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: tiamat at komi dot mts dot ru @ 2006-11-24 10:28 UTC (permalink / raw)
To: gcc-bugs
On ultrasparc hardware Linux/Solaris gcc 4.0.2, 4.0.3, 4.1.1 and
4.1.2-prerelease have a bug:
#include <stdio.h>
int testdiv(int i, int k) {
if (k == 0) printf("found divide by zero\n");
return(i/k);
}
int main() {
int i = testdiv(1,0);
return(i);
}
When compile it without optimization the expected result is received:
$ gcc test.c && ./a.out
found divide by zero
Floating point exception
But optimization broke it:
$ gcc -O3 test.c && ./a.out
Floating point exception
This bug was found with PostgreSQL 8.1.5 on Solaris 9 sparc. Regression tests
give me result:
The differences that caused some tests to fail can be viewed in the
file `./regression.diffs'. A copy of the test summary that you see
above is saved in the file `./regression.out'.
*** expected/errors.out Sat Feb 12 01:15:11 2005
--- results/errors.out Thu Nov 23 18:14:08 2006
***************
*** 300,308 ****
select 1/0::int8;
ERROR: division by zero
select 1::int2/0;
! ERROR: division by zero
select 1/0::int2;
! ERROR: division by zero
select 1::numeric/0;
ERROR: division by zero
select 1/0::numeric;
--- 300,310 ----
select 1/0::int8;
ERROR: division by zero
select 1::int2/0;
! ERROR: floating-point exception
! DETAIL: An invalid floating-point operation was signaled. This probably
means
an out-of-range result or an invalid operation, such as division by zero.
select 1/0::int2;
! ERROR: floating-point exception
! DETAIL: An invalid floating-point operation was signaled. This probably
means
an out-of-range result or an invalid operation, such as division by zero.
select 1::numeric/0;
ERROR: division by zero
select 1/0::numeric;
Thanks a lot!
--
Summary: integer division by zero with optimization
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tiamat at komi dot mts dot ru
GCC build triplet: sparc-linux-gnu, sparc-sun-solaris2.9, sparc64-sun-
solaris2.9
GCC host triplet: sparc-linux-gnu, sparc-sun-solaris2.9, sparc64-sun-
solaris2.9
GCC target triplet: sparc-linux-gnu, sparc-sun-solaris2.9, sparc64-sun-
solaris2.9
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29968
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/29968] integer division by zero with optimization
2006-11-24 10:28 [Bug c/29968] New: integer division by zero with optimization tiamat at komi dot mts dot ru
@ 2006-11-24 10:31 ` tiamat at komi dot mts dot ru
2006-11-24 10:34 ` schwab at suse dot de
2006-11-29 5:59 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: tiamat at komi dot mts dot ru @ 2006-11-24 10:31 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from tiamat at komi dot mts dot ru 2006-11-24 10:31 -------
Created an attachment (id=12681)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12681&action=view)
preprocessed file test.i
$ gcc -v -save-temps -O3 test.c
Using built-in specs.
Target: sparc-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-cpu=v8 --with-long-double-128
--enable-checking=release sparc-linux-gnu
Thread model: posix
gcc version 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)
/usr/lib/gcc/sparc-linux-gnu/4.1.2/cc1 -E -quiet -v -D__sparc_v8__ test.c
-mcpu=v8 -O3 -fpch-preprocess -o test.i
ignoring nonexistent directory "/usr/local/include/sparc-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/sparc-linux-gnu/4.1.2/../../../../sparc-linux-gnu/include"
ignoring nonexistent directory "/usr/include/sparc-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/sparc-linux-gnu/4.1.2/include
/usr/include
End of search list.
/usr/lib/gcc/sparc-linux-gnu/4.1.2/cc1 -fpreprocessed test.i -quiet -dumpbase
test.c -mcpu=v8 -auxbase test -O3 -version -fstack-protector -fstack-protector
-o test.s
GNU C version 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)
(sparc-linux-gnu)
compiled by GNU C version 4.1.2 20060928 (prerelease) (Ubuntu
4.1.1-13ubuntu5).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 98658b34ad66a745f736bec357f1c193
as -V -Qy -s -32 -relax -o test.o test.s
GNU assembler version 2.17 (sparc-linux-gnu) using BFD version 2.17 Debian
GNU/Linux
/usr/lib/gcc/sparc-linux-gnu/4.1.2/collect2 --eh-frame-hdr -m elf32_sparc -Y
P,/usr/lib -dynamic-linker /lib/ld-linux.so.2 -relax
/usr/lib/gcc/sparc-linux-gnu/4.1.2/../../../../lib/crt1.o
/usr/lib/gcc/sparc-linux-gnu/4.1.2/../../../../lib/crti.o
/usr/lib/gcc/sparc-linux-gnu/4.1.2/crtbeginS.o
-L/usr/lib/gcc/sparc-linux-gnu/4.1.2 -L/usr/lib/gcc/sparc-linux-gnu/4.1.2
-L/usr/lib/gcc/sparc-linux-gnu/4.1.2/../../../../lib -L/lib/../lib
-L/usr/lib/../lib test.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc
--as-needed -lgcc_s --no-as-needed /usr/lib/gcc/sparc-linux-gnu/4.1.2/crtend.o
/usr/lib/gcc/sparc-linux-gnu/4.1.2/../../../../lib/crtn.o
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29968
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/29968] integer division by zero with optimization
2006-11-24 10:28 [Bug c/29968] New: integer division by zero with optimization tiamat at komi dot mts dot ru
2006-11-24 10:31 ` [Bug c/29968] " tiamat at komi dot mts dot ru
@ 2006-11-24 10:34 ` schwab at suse dot de
2006-11-29 5:59 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: schwab at suse dot de @ 2006-11-24 10:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from schwab at suse dot de 2006-11-24 10:34 -------
Your program is invoking undefined behaviour. You should not perform the
division if the divisor is zero.
--
schwab at suse dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29968
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/29968] integer division by zero with optimization
2006-11-24 10:28 [Bug c/29968] New: integer division by zero with optimization tiamat at komi dot mts dot ru
2006-11-24 10:31 ` [Bug c/29968] " tiamat at komi dot mts dot ru
2006-11-24 10:34 ` schwab at suse dot de
@ 2006-11-29 5:59 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-29 5:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2006-11-29 05:59 -------
Just a further note here, divide by 0 is undefined behavior as defined by the C
standard.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
GCC build triplet|sparc-linux-gnu, sparc-sun- |
|solaris2.9, sparc64-sun- |
|solaris2.9 |
GCC host triplet|sparc-linux-gnu, sparc-sun- |
|solaris2.9, sparc64-sun- |
|solaris2.9 |
GCC target triplet|sparc-linux-gnu, sparc-sun- |sparc*
|solaris2.9, sparc64-sun- |
|solaris2.9 |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29968
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-11-29 5:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-24 10:28 [Bug c/29968] New: integer division by zero with optimization tiamat at komi dot mts dot ru
2006-11-24 10:31 ` [Bug c/29968] " tiamat at komi dot mts dot ru
2006-11-24 10:34 ` schwab at suse dot de
2006-11-29 5:59 ` pinskia at gcc dot gnu dot org
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).