Bug 15526 - [3.4 Regression] -ftrapv aborts on 0 * (-1)
Summary: [3.4 Regression] -ftrapv aborts on 0 * (-1)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 3.4.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-18 20:43 UTC by Erik Schnetter
Modified: 2004-09-26 20:49 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.0.0 3.3.3
Known to fail:
Last reconfirmed: 2004-05-18 21:33:14


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Schnetter 2004-05-18 20:43:37 UTC
My version of gcc 
 
$ ~/gcc/bin/gcc --version 
gcc (GCC) 3.5.0 20040517 (experimental) 
 
produces code that aborts when it encounters the expression "0 * (-1)" when 
compiled with -ftrapv.  The failing programme is 
 
int test (int a) 
{ 
  return a * (a-1); 
} 
 
int main (int argc, char ** argv) 
{ 
  test (0); 
  return 0; 
} 
 
which I compile with 
 
$ ~/gcc/bin/gcc -o mul-trapv mul-trapv.c -ftrapv
Comment 1 Falk Hueffner 2004-05-18 21:13:22 UTC
Can't reproduce on alphaev68-linux 3.5.0 20040513. Probably platform specific.
Comment 2 Andrew Pinski 2004-05-18 21:33:12 UTC
Confirmed this caused by the following patch:
2003-06-30  Bruno Haible  <bruno@clisp.org>

        PR middle-end/6578
        * libgcc2.c (__subvsi3): Remove simplification that would not work
        when subtracting -0x80000000.
        (__subvdi3): Remove simplification that would return a wrong result.
        (__mulvsi3): Fix overflow check.
        (__absvdi2): Fix simplification that would return a wrong result.
        (__mulvdi3): Fix overflow check.
Comment 3 Falk Hueffner 2004-05-18 22:24:36 UTC
This should fix it (but I don't have the proper platform to test it):

diff -u -p -r1.170 libgcc2.c
--- libgcc2.c   14 Nov 2003 02:23:13 -0000      1.170
+++ libgcc2.c   18 May 2004 22:21:45 -0000
@@ -130,9 +130,7 @@ __mulvsi3 (Wtype a, Wtype b)
 {
   const DWtype w = (DWtype) a * (DWtype) b;
 
-  if (((a >= 0) == (b >= 0))
-      ? (UDWtype) w > (UDWtype) (((DWtype) 1 << (WORD_SIZE - 1)) - 1)
-      : (UDWtype) w < (UDWtype) ((DWtype) -1 << (WORD_SIZE - 1)))
+  if ((Wtype) (w >> WORD_SIZE) != (Wtype) w >> (WORD_SIZE - 1))
     abort ();
 
   return w;
Comment 4 bruno 2004-05-19 12:24:58 UTC
Yes, Falk Hueffner's patch will fix it. 
Sorry for the bug: during my testing of the patch I tried various arguments but not multiplying 
with 0 :-( 
 
Comment 5 CVS Commits 2004-05-19 23:43:22 UTC
Subject: Bug 15526

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	falk@gcc.gnu.org	2004-05-19 23:43:20

Modified files:
	gcc            : ChangeLog libgcc2.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: ftrapv-1.c 

Log message:
	PR other/15526
	* libgcc2.c (__mulvsi3): Fix overflow test.
	* gcc.dg/ftrapv-1.c: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3701&r2=2.3702
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/libgcc2.c.diff?cvsroot=gcc&r1=1.170&r2=1.171
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3763&r2=1.3764
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/ftrapv-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Falk Hueffner 2004-05-19 23:45:53 UTC
Fixed.
Comment 7 Andrew Pinski 2004-09-25 16:31:50 UTC
Reopening because this is not fixed for 3.4.x, only in 4.0.0.
Comment 8 CVS Commits 2004-09-26 20:47:32 UTC
Subject: Bug 15526

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	sayle@gcc.gnu.org	2004-09-26 20:47:23

Modified files:
	gcc            : ChangeLog libgcc2.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: ftrapv-1.c 

Log message:
	PR other/15526
	Backport from mainline
	2004-05-20  Falk Hueffner  <falk@debian.org>
	* libgcc2.c (__mulvsi3): Fix overflow test.
	
	* gcc.dg/ftrapv-1.c: New test case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.635&r2=2.2326.2.636
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/libgcc2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.170.6.1&r2=1.170.6.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.273&r2=1.3389.2.274
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/ftrapv-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.22.1

Comment 9 Andrew Pinski 2004-09-26 20:49:27 UTC
Fixed.