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] Broken code in m68k/fpgnulib.c


The __floatsidf routine in config/m68k/fpgnulib.c relies on signed integer 
overflow to detect the most negative integer value. gcc is now clever enough 
to notice this and the function compiles to an infinite loop.

The attached patch casts to "unsigned long" to ensure correct behaviour.

Tested with cross to m68k-elf/-m5200
Ok?

Paul

2005-09-18  Paul Brook  <paul@codesourcery.com>

	* config/m68k/fpgnuib.c (__floatsidf): Don't rely on signed overflow.
Index: gcc/config/m68k/fpgnulib.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/config/m68k/fpgnulib.c,v
retrieving revision 1.3
diff -u -p -r1.3 fpgnulib.c
--- gcc/config/m68k/fpgnulib.c	12 Jan 2004 03:55:42 -0000	1.3
+++ gcc/config/m68k/fpgnulib.c	17 Sep 2005 23:14:31 -0000
@@ -121,7 +121,7 @@ __floatsidf (long a1)
   if (a1 < 0)
     {
       sign = SIGNBIT;
-      a1 = -a1;
+      a1 = (long)-(unsigned long)a1;
       if (a1 < 0)
 	{
 	  dl.l.upper = SIGNBIT | ((32 + EXCESSD) << 20L);

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