OSDN Git Service

PR c/39855
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 22 Apr 2009 21:57:52 +0000 (21:57 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 22 Apr 2009 21:57:52 +0000 (21:57 +0000)
* fold-const.c (fold_binary) <case LSHIFT_EXPR>: When optimizing
into 0, use omit_one_operand.

* gcc.dg/torture/pr39855.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146617 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr39855.c [new file with mode: 0644]

index 9073054..7bc4f33 100644 (file)
@@ -3,6 +3,10 @@
        * alias.c (find_base_term): Move around LO_SUM case, so that
        CONST falls through into PLUS/MINUS handling.
 
+       PR c/39855
+       * fold-const.c (fold_binary) <case LSHIFT_EXPR>: When optimizing
+       into 0, use omit_one_operand.
+
 2009-04-23  Ben Elliston  <bje@au.ibm.com>
 
        * config/rs6000/linux-unwind.h (get_regs): Remove type
index ca07cf1..f0ff5b6 100644 (file)
@@ -11880,7 +11880,8 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
              if (code == LROTATE_EXPR || code == RROTATE_EXPR)
                low = low % TYPE_PRECISION (type);
              else if (TYPE_UNSIGNED (type) || code == LSHIFT_EXPR)
-               return build_int_cst (type, 0);
+               return omit_one_operand (type, build_int_cst (type, 0),
+                                        TREE_OPERAND (arg0, 0));
              else
                low = TYPE_PRECISION (type) - 1;
            }
index e5c7010..7af7fcc 100644 (file)
@@ -1,3 +1,8 @@
+2009-04-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/39855
+       * gcc.dg/torture/pr39855.c: New test.
+
 2009-04-22  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/39639
diff --git a/gcc/testsuite/gcc.dg/torture/pr39855.c b/gcc/testsuite/gcc.dg/torture/pr39855.c
new file mode 100644 (file)
index 0000000..6d75c38
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR c/39855 */
+/* { dg-do run { target { int32plus } } } */
+
+extern void abort (void);
+
+int i, j, k;
+
+int
+foo (void)
+{
+  return ++i;
+}
+
+int
+main ()
+{
+  if (__CHAR_BIT__ != 8 || sizeof (int) != 4)
+    return 0;
+  j = foo () << 30 << 2;
+  k = (unsigned) foo () >> 16 >> 16;
+  if (i != 2 || j != 0 || k != 0)
+    abort ();
+  return 0;
+}