This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix other/15526: libgcc2 __mulvsi3 overflow test


Hi,

this fixes PR other/15526. Roger Sayle said he tested it on
i686-pc-linux-gnu.

        Falk



2004-05-20  Falk Hueffner  <falk@debian.org>

	PR other/15526
	* libgcc2.c (__mulvsi3): Fix overflow test.

2004-05-20  Falk Hueffner  <falk@debian.org>

	PR other/15526
	* gcc.dg/ftrapv-1.c: New test case.


Index: gcc/libgcc2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/libgcc2.c,v
retrieving revision 1.170
diff -u -p -r1.170 libgcc2.c
--- gcc/libgcc2.c	14 Nov 2003 02:23:13 -0000	1.170
+++ gcc/libgcc2.c	19 May 2004 23:06:27 -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;
Index: gcc/testsuite/gcc.dg/ftrapv-1.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/ftrapv-1.c
diff -N gcc/testsuite/gcc.dg/ftrapv-1.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/ftrapv-1.c	19 May 2004 23:06:27 -0000
@@ -0,0 +1,25 @@
+/* Copyright (C) 2004 Free Software Foundation.
+
+   PR other/15526
+   Verify correct overflow checking with -ftrapv.
+
+   Written by Falk Hueffner, 20th May 2004.  */
+
+/* { dg-do run } */
+/* { dg-options "-ftrapv" } */
+
+__attribute__((noinline)) int
+mulv(int a, int b)
+{
+  return a * b;
+}
+
+int
+main()
+{
+  mulv( 0,  0);
+  mulv( 0, -1);
+  mulv(-1,  0);
+  mulv(-1, -1);
+  return 0;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]