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; 6+ 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] 6+ messages in thread

end of thread, other threads:[~2023-04-20 21:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-29968-4@http.gcc.gnu.org/bugzilla/>
2023-04-20 21:32 ` [Bug c/29968] integer division by zero with optimization vincent-gcc at vinc17 dot net
2023-04-20 21:38 ` pinskia at gcc dot gnu.org
2023-04-20 21:46 ` pinskia at gcc dot gnu.org
2006-11-24 10:28 [Bug c/29968] New: " 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).