From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5539 invoked by alias); 24 Nov 2006 10:28:40 -0000 Received: (qmail 5522 invoked by uid 48); 24 Nov 2006 10:28:31 -0000 Date: Fri, 24 Nov 2006 10:28:00 -0000 Subject: [Bug c/29968] New: integer division by zero with optimization X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "tiamat at komi dot mts dot ru" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-11/txt/msg02101.txt.bz2 On ultrasparc hardware Linux/Solaris gcc 4.0.2, 4.0.3, 4.1.1 and 4.1.2-prerelease have a bug: #include 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