re PR middle-end/40692 (Endless recursion between fold_ternary and fold_cond_expr_wit...
authorJakub Jelinek <jakub@redhat.com>
Thu, 9 Jul 2009 11:19:22 +0000 (13:19 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 9 Jul 2009 11:19:22 +0000 (13:19 +0200)
PR middle-end/40692
* fold-const.c (fold_cond_expr_with_comparison): Don't replace
arg1 with arg01 if arg1 is already INTEGER_CST.

* gcc.c-torture/compile/pr40692.c: New test.

From-SVN: r149418

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

index 0347c24ae88860ef8304a5529a84e049ac0880f8..cc7e18644edf97b3cfaed58e1786b290edb2975b 100644 (file)
@@ -1,3 +1,9 @@
+2009-07-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/40692
+       * fold-const.c (fold_cond_expr_with_comparison): Don't replace
+       arg1 with arg01 if arg1 is already INTEGER_CST.
+
 2009-07-08  Adam Nemet  <anemet@caviumnetworks.com>
 
        * simplify-rtx.c (simplify_binary_operation_1) <AND>: Transform (and
index 670fa45e4975056d89d09832d1b9378663d9ae42..f3e0614a4a67a0af80cfe4f11c763968804b87fb 100644 (file)
@@ -5303,6 +5303,8 @@ fold_cond_expr_with_comparison (tree type, tree arg0, tree arg1, tree arg2)
     switch (comp_code)
       {
       case EQ_EXPR:
+       if (TREE_CODE (arg1) == INTEGER_CST)
+         break;
        /* We can replace A with C1 in this case.  */
        arg1 = fold_convert (type, arg01);
        return fold_build3 (COND_EXPR, type, arg0, arg1, arg2);
index 63b2df4d0ce1950eb95de57944e4951bb0710aa7..736c22f5e8a9074fd4caefe9a1977731a3d21143 100644 (file)
@@ -1,3 +1,8 @@
+2009-07-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/40692
+       * gcc.c-torture/compile/pr40692.c: New test.
+
 2009-07-09  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/40604
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr40692.c b/gcc/testsuite/gcc.c-torture/compile/pr40692.c
new file mode 100644 (file)
index 0000000..567516e
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR middle-end/40692 */
+
+#define M1(x) (((x) & 0x00000002) ? 0x2 : ((x) & 0x1))
+#define M2(x) (((x) & 0x0000000c) ? M1 ((x) >> 2) << 2 : M1 (x))
+#define M3(x) (((x) & 0x000000f0) ? M2 ((x) >> 4) << 4 : M2 (x))
+#define M4(x) (((x) & 0x0000ff00) ? M3 ((x) >> 8) << 8 : M3 (x))
+#define M5(x) (((x) & 0xffff0000) ? M4 ((x) >> 16) << 16 : M4 (x))
+
+struct A { char e; char f; };
+
+long
+foo (void)
+{
+  return M5 (4096UL - (long) &((struct A *) 0)->f);
+}