]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/37103 (possible integer codegen bug)
authorJakub Jelinek <jakub@redhat.com>
Thu, 14 Aug 2008 09:02:46 +0000 (11:02 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 14 Aug 2008 09:02:46 +0000 (11:02 +0200)
PR middle-end/37103
* fold-const.c (fold_widened_comparison): Do not allow
sign changes that change the result even if shorter type
is wider than arg1_unw's type.

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

From-SVN: r139093

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

index 2b4062aeae371c8724d01bab1b5442339a49980a..ed3129dc38becd8f495d7a0aac17a4bcd9f5855f 100644 (file)
@@ -1,3 +1,10 @@
+2008-08-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/37103
+       * fold-const.c (fold_widened_comparison): Do not allow
+       sign changes that change the result even if shorter type
+       is wider than arg1_unw's type.
+
 2008-08-13  Kazu Hirata  <kazu@codesourcery.com>
 
        * gcc.dg/arm-g2.c, gcc.dg/arm-mmx-1.c, gcc.dg/arm-scd42-2.c:
index cae45b5a6585e11cabf1254080c8c4278d5518fa..eac31ef1a7944a7f4a4bc67ac3d6ddd0bdad7db0 100644 (file)
@@ -6733,10 +6733,8 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1)
   if ((code == EQ_EXPR || code == NE_EXPR
        || TYPE_UNSIGNED (TREE_TYPE (arg0)) == TYPE_UNSIGNED (shorter_type))
       && (TREE_TYPE (arg1_unw) == shorter_type
-         || (TYPE_PRECISION (shorter_type)
-             > TYPE_PRECISION (TREE_TYPE (arg1_unw)))
          || ((TYPE_PRECISION (shorter_type)
-              == TYPE_PRECISION (TREE_TYPE (arg1_unw)))
+              >= TYPE_PRECISION (TREE_TYPE (arg1_unw)))
              && (TYPE_UNSIGNED (shorter_type)
                  == TYPE_UNSIGNED (TREE_TYPE (arg1_unw))))
          || (TREE_CODE (arg1_unw) == INTEGER_CST
index f4d6909f93d5ab158851cd2e95d33c81ba1d6d0d..ca3aa25161e613331bd6a724b7dee1365a8d4354 100644 (file)
@@ -1,3 +1,8 @@
+2008-08-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/37103
+       * gcc.c-torture/execute/20080813-1.c: New test.
+
 2008-08-13  H.J. Lu  <hongjiu.lu@intel.com>
 
        * gcc.target/i386/incoming-1.c: Skip *-*-darwin*.
diff --git a/gcc/testsuite/gcc.c-torture/execute/20080813-1.c b/gcc/testsuite/gcc.c-torture/execute/20080813-1.c
new file mode 100644 (file)
index 0000000..9ef6bc2
--- /dev/null
@@ -0,0 +1,30 @@
+/* PR middle-end/37103 */
+
+extern void abort (void);
+
+void
+foo (unsigned short x)
+{
+  signed char y = -1;
+  if (x == y)
+    abort ();
+}
+
+void
+bar (unsigned short x)
+{
+  unsigned char y = -1;
+  if (x == y)
+    abort ();
+}
+
+int
+main (void)
+{
+  if (sizeof (int) == sizeof (short))
+    return 0;
+  foo (-1);
+  if (sizeof (short) > 1)
+    bar (-1);
+  return 0;
+}