re PR c/37924 (ice in smallest_mode_for_size, at stor-layout.c:219)
authorJakub Jelinek <jakub@redhat.com>
Tue, 28 Oct 2008 19:02:36 +0000 (20:02 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 28 Oct 2008 19:02:36 +0000 (20:02 +0100)
PR c/37924
* combine.c (make_compound_operation): Don't call make_extraction with
non-positive length.
(simplify_shift_const_1): Canonicalize count even if complement_p.

* gcc.c-torture/execute/pr37924.c: New test.

From-SVN: r141413

gcc/ChangeLog
gcc/combine.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr37924.c [new file with mode: 0644]

index 5b520af2b09e57000be20b03f204c0994db35f87..9ef2947de39016c0af2fd054b634a167ea3fbe9e 100644 (file)
@@ -1,3 +1,10 @@
+2008-10-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/37924
+       * combine.c (make_compound_operation): Don't call make_extraction with
+       non-positive length.
+       (simplify_shift_const_1): Canonicalize count even if complement_p.
+
 2008-10-28  Joseph Myers  <joseph@codesourcery.com>
 
        * convert.c (strip_float_extensions): Do not remove or introduce
index 55baf37149ad15b0710926d7fbecf739e3367ccc..e76049a49ef44015124edaf0991eb6ace549dfd7 100644 (file)
@@ -6996,7 +6996,8 @@ make_compound_operation (rtx x, enum rtx_code in_code)
       if (GET_CODE (rhs) == CONST_INT
          && GET_CODE (lhs) == ASHIFT
          && GET_CODE (XEXP (lhs, 1)) == CONST_INT
-         && INTVAL (rhs) >= INTVAL (XEXP (lhs, 1)))
+         && INTVAL (rhs) >= INTVAL (XEXP (lhs, 1))
+         && INTVAL (rhs) < mode_width)
        {
          new_rtx = make_compound_operation (XEXP (lhs, 0), next_code);
          new_rtx = make_extraction (mode, new_rtx,
@@ -7016,6 +7017,7 @@ make_compound_operation (rtx x, enum rtx_code in_code)
                && (OBJECT_P (SUBREG_REG (lhs))))
          && GET_CODE (rhs) == CONST_INT
          && INTVAL (rhs) < HOST_BITS_PER_WIDE_INT
+         && INTVAL (rhs) < mode_width
          && (new_rtx = extract_left_shift (lhs, INTVAL (rhs))) != 0)
        new_rtx = make_extraction (mode, make_compound_operation (new_rtx, next_code),
                               0, NULL_RTX, mode_width - INTVAL (rhs),
@@ -9003,11 +9005,6 @@ simplify_shift_const_1 (enum rtx_code code, enum machine_mode result_mode,
       if (GET_CODE (varop) == CLOBBER)
        return NULL_RTX;
 
-      /* If we discovered we had to complement VAROP, leave.  Making a NOT
-        here would cause an infinite loop.  */
-      if (complement_p)
-       break;
-
       /* Convert ROTATERT to ROTATE.  */
       if (code == ROTATERT)
        {
@@ -9053,6 +9050,11 @@ simplify_shift_const_1 (enum rtx_code code, enum machine_mode result_mode,
            }
        }
 
+      /* If we discovered we had to complement VAROP, leave.  Making a NOT
+        here would cause an infinite loop.  */
+      if (complement_p)
+       break;
+
       /* An arithmetic right shift of a quantity known to be -1 or 0
         is a no-op.  */
       if (code == ASHIFTRT
index 0281e865fe2f389f7ce68bad7fa59e0811563d94..0dd44be45f65a850dc39246475a06d6d246e3f48 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/37924
+       * gcc.c-torture/execute/pr37924.c: New test.
+
 2008-10-28  Joseph Myers  <joseph@codesourcery.com>
 
        * gcc.dg/dfp/convert-bfp-12.c: New test.
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr37924.c b/gcc/testsuite/gcc.c-torture/execute/pr37924.c
new file mode 100644 (file)
index 0000000..ec098ff
--- /dev/null
@@ -0,0 +1,50 @@
+/* PR c/37924 */
+
+extern void abort (void);
+
+signed char a;
+unsigned char b;
+
+int
+test1 (void)
+{
+  int c = -1;
+  return ((unsigned int) (a ^ c)) >> 9;
+}
+
+int
+test2 (void)
+{
+  int c = -1;
+  return ((unsigned int) (b ^ c)) >> 9;
+}
+
+int
+main (void)
+{
+  a = 0;
+  if (test1 () != (-1U >> 9))
+    abort ();
+  a = 0x40;
+  if (test1 () != (-1U >> 9))
+    abort ();
+  a = 0x80;
+  if (test1 () != (a < 0) ? 0 : (-1U >> 9))
+    abort ();
+  a = 0xff;
+  if (test1 () != (a < 0) ? 0 : (-1U >> 9))
+    abort ();
+  b = 0;
+  if (test2 () != (-1U >> 9))
+    abort ();
+  b = 0x40;
+  if (test2 () != (-1U >> 9))
+    abort ();
+  b = 0x80;
+  if (test2 () != (-1U >> 9))
+    abort ();
+  b = 0xff;
+  if (test2 () != (-1U >> 9))
+    abort ();
+  return 0;
+}