[gcc(refs/users/acsawdey/heads/memcpy-unaligned-vsx)] tree: Fix up get_narrower [PR96549]

Aaron Sawdey acsawdey@gcc.gnu.org
Thu Aug 13 19:55:25 GMT 2020


https://gcc.gnu.org/g:6b815e113c9aec397a86d7194f66455eb189cc7a

commit 6b815e113c9aec397a86d7194f66455eb189cc7a
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Aug 11 13:46:14 2020 +0200

    tree: Fix up get_narrower [PR96549]
    
    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.
    
    2020-08-11  Jakub Jelinek  <jakub@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.

Diff:
---
 gcc/testsuite/gcc.c-torture/execute/pr96549.c | 12 ++++++++++++
 gcc/tree.c                                    |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.c-torture/execute/pr96549.c b/gcc/testsuite/gcc.c-torture/execute/pr96549.c
new file mode 100644
index 00000000000..9d992a82c19
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr96549.c
@@ -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 ();
+}
diff --git a/gcc/tree.c b/gcc/tree.c
index 6dea32aeb45..d0202c3f785 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -8877,7 +8877,7 @@ get_narrower (tree op, int *unsignedp_ptr)
 	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;
     }


More information about the Gcc-cvs mailing list