[Bug c/29968] New: integer division by zero with optimization
tiamat at komi dot mts dot ru
gcc-bugzilla@gcc.gnu.org
Fri Nov 24 10:28:00 GMT 2006
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
More information about the Gcc-bugs
mailing list