Hi!

My changes to get_narrower to support COMPOUND_EXPRs apparently
used a wrong type for the COMPOUND_EXPRs, while e.g. the rhs
type was unsigned short, the COMPOUND_EXPR got int type as that was the
original type of op.  The type of COMPOUND_EXPR should be always the type
of the rhs.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk/10.3?

2020-08-10  Jakub Jelinek  <ja...@redhat.com>

        PR c/96549
        * tree.c (get_narrower): Use TREE_TYPE (ret) instead of
        TREE_TYPE (win) for COMPOUND_EXPRs.

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

--- gcc/tree.c.jj       2020-08-03 22:54:51.456531124 +0200
+++ gcc/tree.c  2020-08-10 11:05:49.129685858 +0200
@@ -8877,7 +8877,7 @@ get_narrower (tree op, int *unsignedp_pt
        v.safe_push (op);
       FOR_EACH_VEC_ELT_REVERSE (v, i, op)
        ret = build2_loc (EXPR_LOCATION (op), COMPOUND_EXPR,
-                         TREE_TYPE (win), TREE_OPERAND (op, 0),
+                         TREE_TYPE (ret), TREE_OPERAND (op, 0),
                          ret);
       return ret;
     }
--- gcc/testsuite/gcc.c-torture/execute/pr96549.c.jj    2020-08-10 
11:09:30.307623013 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr96549.c       2020-08-10 
11:09:15.772824289 +0200
@@ -0,0 +1,12 @@
+/* PR c/96549 */
+
+long c = -1L;
+long b = 0L;
+
+int
+main ()
+{
+  if (3L > (short) ((c ^= (b = 1L)) * 3L))
+    return 0;
+  __builtin_abort ();
+}

        Jakub

Reply via email to