fold-const.c (operand_equal_p): Require equal sign also for FIX_{CEIL,TRUNC,FLOOR...
authorJakub Jelinek <jakub@redhat.com>
Wed, 1 Sep 2004 16:33:06 +0000 (18:33 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 1 Sep 2004 16:33:06 +0000 (18:33 +0200)
* fold-const.c (operand_equal_p): Require equal sign also for
FIX_{CEIL,TRUNC,FLOOR,ROUND}_EXPR.

* gcc.c-torture/execute/20040831-1.c: New test.

From-SVN: r86906

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20040831-1.c [new file with mode: 0644]

index 12183328e21b0086b21cf2dd44fb6ca1edd682d9..dccd34a932bdeae64e0a67dc36fc0cf9db50397c 100644 (file)
@@ -1,3 +1,8 @@
+2004-09-01  Jakub Jelinek  <jakub@redhat.com>
+
+       * fold-const.c (operand_equal_p): Require equal sign also for
+       FIX_{CEIL,TRUNC,FLOOR,ROUND}_EXPR.
+
 2004-09-01  Richard Earnshaw  <rearnsha@arm.com>
 
        * config.gcc (--with-cpu on ARM): Preserve the canonical cpu name
index 3ee2bc746e3db1daf69916ea9d21ff4653cf8c57..1ccea7e69b35cb77fcaeef1488a4a626a7d8cd76 100644 (file)
@@ -2391,10 +2391,21 @@ operand_equal_p (tree arg0, tree arg1, unsigned int flags)
     {
     case '1':
       /* Two conversions are equal only if signedness and modes match.  */
-      if ((TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == CONVERT_EXPR)
-         && (TYPE_UNSIGNED (TREE_TYPE (arg0))
-             != TYPE_UNSIGNED (TREE_TYPE (arg1))))
-       return 0;
+      switch (TREE_CODE (arg0))
+        {
+        case NOP_EXPR:
+        case CONVERT_EXPR:
+        case FIX_CEIL_EXPR:
+        case FIX_TRUNC_EXPR:
+        case FIX_FLOOR_EXPR:
+        case FIX_ROUND_EXPR:
+         if (TYPE_UNSIGNED (TREE_TYPE (arg0))
+             != TYPE_UNSIGNED (TREE_TYPE (arg1)))
+           return 0;
+         break;
+       default:
+         break;
+       }
 
       return operand_equal_p (TREE_OPERAND (arg0, 0),
                              TREE_OPERAND (arg1, 0), flags);
index d2fdc6a4a0bfb726044d1a7d2de1aaaa4e2f7e13..53ee056ae5398e96f2fab2516f5692fa47d84176 100644 (file)
@@ -1,3 +1,7 @@
+2004-09-01  Jakub Jelinek  <jakub@redhat.com>
+
+       * gcc.c-torture/execute/20040831-1.c: New test.
+
 2004-09-01  David Billinghurst <David.Billinghurst@riotinto.com>
 
        PR fortran/16579
diff --git a/gcc/testsuite/gcc.c-torture/execute/20040831-1.c b/gcc/testsuite/gcc.c-torture/execute/20040831-1.c
new file mode 100644 (file)
index 0000000..39773b3
--- /dev/null
@@ -0,0 +1,14 @@
+/* This testcase was being miscompiled, because operand_equal_p
+   returned that (unsigned long) d and (long) d are equal.  */
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+  double d = -12.0;
+  long l = (d > 10000) ? (unsigned long) d : (long) d;
+  if (l != -12)
+    abort ();
+  exit (0);
+}