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 decimal float wrong-code bug, c/39035


A decimal float zero as a conditional expression is treated as true,
not false.  Flag rvc_zero is not set for decimal values because there
are many valid representations of decimal float zero.  This patch
special-cases comparisons of zero against a decimal float value so
that those different representations can be taken into account; just
setting rvc_zero for a decimal float contant zero breaks several
checks in test gcc.dg/dfp/constants-zero.c

Bootstrapped and regression tested on powerpc64-linux, all languages
except Ada.  As a wrong-code bug, is this OK for trunk?  Is it also
OK for the 4.3 branch, after I test it there?

2009-02-06  Janis Johnson  <janis187@us.ibm.com>

gcc/
	PR c/39035
	* real.c (do_compare): Special-case compare of zero against
	decimal float value.

testsuite/
	PR c/39035
	* gcc.dg/dfp/pr39035.c: New test.

Index: gcc/real.c
===================================================================
--- gcc/real.c	(revision 143946)
+++ gcc/real.c	(working copy)
@@ -905,15 +905,23 @@
       /* Sign of zero doesn't matter for compares.  */
       return 0;
 
+    case CLASS2 (rvc_normal, rvc_zero):
+      /* Decimal float zero is special and uses rvc_normal, not rvc_zero.  */
+      if (a->decimal)
+	return decimal_do_compare (a, b, nan_result);
+      /* Fall through.  */
     case CLASS2 (rvc_inf, rvc_zero):
     case CLASS2 (rvc_inf, rvc_normal):
-    case CLASS2 (rvc_normal, rvc_zero):
       return (a->sign ? -1 : 1);
 
     case CLASS2 (rvc_inf, rvc_inf):
       return -a->sign - -b->sign;
 
     case CLASS2 (rvc_zero, rvc_normal):
+      /* Decimal float zero is special and uses rvc_normal, not rvc_zero.  */
+      if (b->decimal)
+	return decimal_do_compare (a, b, nan_result);
+      /* Fall through.  */
     case CLASS2 (rvc_zero, rvc_inf):
     case CLASS2 (rvc_normal, rvc_inf):
       return (b->sign ? 1 : -1);
Index: gcc/testsuite/gcc.dg/dfp/pr39035.c
===================================================================
--- gcc/testsuite/gcc.dg/dfp/pr39035.c	(revision 0)
+++ gcc/testsuite/gcc.dg/dfp/pr39035.c	(revision 0)
@@ -0,0 +1,81 @@
+/* { dg-do run } */
+/* { dg-options "-std=gnu99 -O" } */
+
+/* DFP TR 24732 == WG14 / N1176, N1312 */
+/* Based on a test from Fred Tydeman.  */
+
+extern void abort (void);
+int failures = 0;
+
+#ifdef DBG
+#include <stdio.h>
+#define FAILURE(MSG) { printf ("line %d: %s\n", __LINE__, MSG); failures++; }
+#else
+#define FAILURE(MSG) failures++;
+#endif
+
+/* Test runtime computations.  */
+
+void
+runtime32 (void)
+{
+  volatile _Decimal32 d;
+  d = 0.0DF;
+  if (d)
+    FAILURE ("0.0DF should be zero")
+}
+
+void
+runtime64 (void)
+{
+  volatile _Decimal64 d;
+  d = 0.0DD;
+  if (d)
+    FAILURE ("0.0DD should be zero")
+}
+
+void
+runtime128 (void)
+{
+  volatile _Decimal128 d;
+  d = 0.0DL;
+  if (d)
+    FAILURE ("0.0DL should be zero")
+}
+
+void
+fold32 (void)
+{
+  if (0.0DF)
+    FAILURE ("0.0DF should be zero")
+}
+
+void
+fold64 (void)
+{
+  if (0.0DD)
+    FAILURE ("0.0DD should be zero")
+}
+
+void
+fold128 (void)
+{
+  if (0.0DL)
+    FAILURE ("0.0DL should be zero")
+}
+
+int
+main(void)
+{
+  runtime32 ();
+  runtime64 ();
+  runtime128 ();
+
+  fold32 ();
+  fold64 ();
+  fold128 ();
+
+  if (failures != 0)
+    abort ();
+  return 0;
+}



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